imjuni / ctix

CLI to generate barrel file for webpack, rollup entrypoint
MIT License
82 stars 22 forks source link

How to skip the directory itself but handle all subdirectories? #82

Closed StringKe closed 1 year ago

StringKe commented 1 year ago

I'm using NextJS in src folder mode, src itself doesn't need to be exported externally (to generate index.ts) but other folders inside src such as components layout do need to generate index.ts.

imjuni commented 1 year ago

Hi @StringKe

use ignore: https://github.com/imjuni/ctix#ignore

StringKe commented 1 year ago

I don't know how to write ".ctiignore"

I've tried all these ways of writing but none of them work.

{
  "src":"",
  "src/*":"*"
}
imjuni commented 1 year ago

key is follow .gitignore spec 2.22.1. value is that specific class and interface, function name array or "*" ignore all.

{
  "src/**/*": "*"
}

If something in the README doesn't make understand, please issue a PR to improve it. Thank you.

StringKe commented 1 year ago

I tried, but it didn't generate any files

  1. find ./src -type f -name "index.ts" -exec rm -f {} + remove all index.ts files
  2. ctix create

.ctiignore

{
  "src/**/*": "*",
  "src/components/design-editor/utils/text-to-svg.ts": "*"
}

.ctix

{
  "project": "./tsconfig.json",
  "exportFilename": "index.ts",
  "useSemicolon": true,
  "useTimestamp": false,
  "useComment": false,
  "quote": "'",
  "overwrite": true,
  "keepFileExt": false,
  "skipEmptyDir": true,
  "output": "./",
  "useRootDir": false,
  "includeBackup": true,
  "noBackup": true,
  "startAt": "./src"
}

folder struct

.
├── README.md
├── next-env.d.ts
├── next.config.mjs
├── package.json
├── pnpm-lock.yaml
├── postcss.config.js
├── prettier.config.mjs
├── prisma
│   └── schema.prisma
├── public
│   ├── assets
│   │   └── wasm
│   │       └── svg.wasm
│   ├── cache
│   ├── favicon.ico
│   ├── zcool.ttf
│   └── zcool.woff
├── shims.d.ts
├── src
│   ├── components
│   │   └── design-editor
│   │       ├── App.module.scss
│   │       ├── App.tsx
│   │       ├── components
│   │       ├── state
│   │       └── utils
│   ├── env.mjs
│   ├── layouts
│   │   ├── DefaultLayout.tsx
│   │   └── WithApp.tsx
│   ├── pages
│   │   ├── _app.tsx
│   │   ├── _document.tsx
│   │   ├── api
│   │   │   └── trpc
│   │   ├── editor.tsx
│   │   └── index.tsx
│   ├── server
│   │   ├── api
│   │   │   ├── root.ts
│   │   │   ├── routers
│   │   │   └── trpc.ts
│   │   ├── db.ts
│   │   ├── redis.ts
│   │   └── session.ts
│   ├── styles
│   │   └── globals.scss
│   └── utils
│       ├── api.ts
│       └── dev-simple-error.ts
└── tsconfig.json

demo create tool : https://github.com/t3-oss/create-t3-app

imjuni commented 1 year ago

@StringKe Would you create reproducable repo?

StringKe commented 1 year ago

@StringKe Would you create reproducable repo?

check this repo https://github.com/StringKe/ctix-project-struct

imjuni commented 1 year ago

@StringKe Hi,

execute ctix create -g ./.ctiignore. ctix needs to be passed a .ctiignore file with the -g option to apply the ignore option.

StringKe commented 1 year ago

i try this

{
  "src/**/*": "*",
  "src/components/design-editor/utils/text-to-svg.ts": "*"
}

run ctix create -g ./.ctiignore did not generate any index.ts I had deleted all index.ts before that.

imjuni commented 1 year ago

The .ctiignore file you pass to the ctix follows the .gitignore file specification. "src/**/*": "*" sets all files in the src directory to be ignored, so no index file can be created.

{
  "src/env.mjs": "*",
  "src/pages/**": "*",
  "src/components/design-editor/utils/text-to-svg.ts": "*"
}

The above worked fine, what is the intended behavior?

StringKe commented 1 year ago

src/components/ not need generate index.ts src/pages/ not need generate index.ts src/utils/ not need generate index.ts src/components/auth/ generate index.ts src/components/user/profile/ generate index.ts

imjuni commented 1 year ago

When writing a .gitignore file, how do I exclude the file as you mentioned?

You could try something like this,

{
  "src/pages/**/*": "*",
  "src/utils/**/*": "*",
  "src/components/test1/**/*": "*",
  "src/components/test2/**/*": "*",
}
StringKe commented 1 year ago

When writing a .gitignore file, how do I exclude the file as you mentioned?

I haven't tried it, I think ctix should be different from git.

In my vision ctix should have the flexibility to control whether any hierarchical folder is involved in generating index.ts .

imjuni commented 1 year ago

Hard to disagree, ctix uses the ignore package to handle .ctiignore files. Please read the documentation for that package, and I'll close this issue.

StringKe commented 1 year ago

@imjuni I'm having a little problem with that. ctix not support ts.SyntaxKind.Identifier

[23-10-19 11:21:25] error: Cannot support type: (79) Checkbox
[23-10-19 11:21:25] error: Error: Cannot support type: (79) Checkbox
    at /Users/chen/Project/Companies/ybt/online-logo-editor/website/node_modules/ctix/dist/cli.js:923:15
    at Array.map (<anonymous>)
    at getIsIsolatedModules (/Users/chen/Project/Companies/ybt/online-logo-editor/website/node_modules/ctix/dist/cli.js:880:10)
    at /Users/chen/Project/Companies/ybt/online-logo-editor/website/node_modules/ctix/dist/cli.js:1041:32
    at Array.map (<anonymous>)
    at getExportInfo (/Users/chen/Project/Companies/ybt/online-logo-editor/website/node_modules/ctix/dist/cli.js:1015:10)
    at async Promise.all (index 27)
    at getExportInfos (/Users/chen/Project/Companies/ybt/online-logo-editor/website/node_modules/ctix/dist/cli.js:1099:26)
    at createWritor (/Users/chen/Project/Companies/ybt/online-logo-editor/website/node_modules/ctix/dist/cli.js:2075:34)
    at Object.handler (/Users/chen/Project/Companies/ybt/online-logo-editor/website/node_modules/ctix/dist/cli.js:2273:13)
StringKe commented 1 year ago

ctiignore doesn't exactly follow the gitignore specification?

Here's what I found in the gitignore specification

{
  "src/**": "*",
  "!src/component": "*",
  "!src/component/": "*",
  "!src/component/**": "*",
}

CleanShot 2023-10-20 at 18 10 41@2x

imjuni commented 1 year ago

@StringKe Hi,

Fist, thank you for your feedback in making ctix better!

I have recognized that there may be an issue with the handling of .ctiignore files. I was recently recognized that the way ctix generates index.ts files can be problematic for bundling declaration files with rollup-plugin-dts, so I have been working on version 2.0. I have also changed it to handle them as include and exclude options like tsconfig.json rather than ignore files, which should make the behavior clearer. Version 2.0.0-beta.4 is out now, and if there are no major issues, we'll release 2.0.0 this week.

imjuni commented 1 year ago

fixed in v2.0.0