1 | create-ts-index
|
2 | ----
|
3 | [![Download Status](https://img.shields.io/npm/dw/create-ts-index.svg)](https://npmcharts.com/compare/create-ts-index?minimal=true) [![Github Star](https://img.shields.io/github/stars/imjuni/create-ts-index.svg?style=popout)](https://github.com/imjuni/create-ts-index) [![Github Issues](https://img.shields.io/github/issues-raw/imjuni/create-ts-index.svg)](https://github.com/imjuni/create-ts-index/issues) [![NPM version](https://img.shields.io/npm/v/create-ts-index.svg)](https://www.npmjs.com/package/create-ts-index) [![License](https://img.shields.io/npm/l/create-ts-index.svg)](https://github.com/imjuni/create-ts-index/blob/master/LICENSE) [![cti](https://circleci.com/gh/imjuni/create-ts-index.svg?style=shield)](https://app.circleci.com/pipelines/github/imjuni/create-ts-index?branch=master)
|
4 |
|
5 | # Install
|
6 | ```bash
|
7 | npm install create-ts-index --save-dev
|
8 | ```
|
9 |
|
10 | # Introduction
|
11 | index.ts file create for exportation. If don't have business logic in index.ts that use to only exportation, create-ts-index help easy importing. Or if you have library project need this export process(for example, blueprint.js etc ...). cti(create-ts-index) create export index.ts file.
|
12 |
|
13 | For example, sample directory below.
|
14 |
|
15 | ```
|
16 | src/
|
17 | app.ts
|
18 | component/
|
19 | Nav.ts
|
20 | Button.ts
|
21 | ```
|
22 |
|
23 | create-ts-index create sub-command create index.ts file below.
|
24 |
|
25 | ```
|
26 | src/
|
27 | app.ts
|
28 | > index.ts
|
29 | // created from 'create-ts-index'
|
30 | export * from './component';
|
31 | export * from './app';
|
32 | component/
|
33 | Nav.ts
|
34 | Button.ts
|
35 | > index.ts
|
36 | // created from 'create-ts-index'
|
37 | export * from './Nav';
|
38 | export * from './Button';
|
39 | ```
|
40 |
|
41 | create-ts-index entrypoint sub-command create index.ts file below.
|
42 |
|
43 | ```
|
44 | src/
|
45 | app.ts
|
46 | component/
|
47 | Nav.ts
|
48 | Button.ts
|
49 | > entrypoint.ts
|
50 | // created from 'create-ts-index'
|
51 | export * from './src/app.ts'
|
52 | export * from './src/component/Nav.ts'
|
53 | export * from './src/component/Button.ts'
|
54 | ```
|
55 |
|
56 | # Option
|
57 | ## library
|
58 | * `fileFirst: boolean` export list create filefirst. default false
|
59 | * `addNewline: boolean` deside add newline file ending. default true
|
60 | * `useSemicolon: boolean` deside use semicolon line ending. default true
|
61 | * `useTimestamp: boolean` deside use timestamp(YYYY-MM-DD HH:mm) top line comment. default false
|
62 | * `includeCWD: boolean` deside include cwd directory. default true
|
63 | * `excludes: string[]` pass exclude directory. default exclude directory is `['@types', 'typings', '__test__', '__tests__']`
|
64 | * `fileExcludePatterns: string[]` pass exclude filename pattern. default exclude patterns is `[]`
|
65 | * `targetExts: string[]` pass include extname. default extname is `['ts', 'tsx']`. extname pass without dot charactor.
|
66 | * `globOptions: glob.IOptions` pass include glob options. [node-glob](https://github.com/isaacs/node-glob) option use it.
|
67 | * `quote` deside quote charactor. Single quete charactor use to default.
|
68 | * `verbose` verbose log message disply
|
69 | * `withoutComment` remove create-ts-index comment that top of line in index.ts
|
70 | * `withoutBackupFile` Don't create backupfile if already exists target file
|
71 | * `output` index.ts or entrypoint.ts filename change
|
72 |
|
73 | ## cli (use it cti)
|
74 | * `-f --filefirst` export list create filefirst, no option false, option true
|
75 | * `-n --addnewline` deside add newline file ending. no option true, option false
|
76 | * `-s --usesemicolon` deside use semicolon line ending. no option true, option false
|
77 | * `-t --usetimestamp` deside use timestamp(YYYY-MM-DD HH:mm) top line comment. no option false, option true
|
78 | * `-c --includecwd` deside include cwd directory. no option true, option true
|
79 | * `-e --excludes [comma separated exclude directories]` pass exclude directory. default exclude directory is `['@types', 'typings', '__test__', '__tests__']`
|
80 | * `-i --fileexcludes [comma separated extname]` pass exclude filename pattern. default exclude patterns is `[]`
|
81 | * `-x --targetexts [comma separated extname]` pass include extname. default extname is `['ts', 'tsx']`. extname pass without dot charactor.
|
82 | * `-q --quote` deside quote charactor. default quote charactor single quote
|
83 | * `-v --verbose` disply verbose log message. no option false, option true
|
84 | * `-w --withoutcomment` remove create-ts-index comment that top of line in index.ts
|
85 | * `-b --withoutbackup` Don't create backupfile if already exists target file
|
86 | * `-o --output` index.ts or entrypoint.ts filename change
|
87 |
|
88 | # Usage
|
89 | ## library
|
90 | ### Use TypeScritIndexWriter
|
91 | ```typescript
|
92 | const tsiw = new TypeScritIndexWriter();
|
93 | const option = TypeScritIndexWriter.getDefaultOption('./src');
|
94 |
|
95 | (async () => {
|
96 | await tsiw.create(option);
|
97 |
|
98 | // or
|
99 |
|
100 | await tsiw.createEntrypoint(option);
|
101 | })();
|
102 | ```
|
103 |
|
104 | ### Use CommandModule
|
105 | ```typescript
|
106 | (async () => {
|
107 | const option = CreateTsIndexOption.getOption({});
|
108 | const createCommand = new CreateCommandModule();
|
109 | await createCommand.do(process.cwd(), option);
|
110 | });
|
111 | ```
|
112 |
|
113 | ## CLI
|
114 | cli use git-style sub-command
|
115 |
|
116 | * create
|
117 | * cti create index.ts file
|
118 | * entrypoint
|
119 | * cti create webpack entrypoint
|
120 | * init
|
121 | * create `.ctirc` file
|
122 | * clean
|
123 | * cti clean index.ts file recursively
|
124 |
|
125 | ```bash
|
126 | # basic usage
|
127 | cti create ./src # or cti create ./src
|
128 | ## or
|
129 | cti entrypoint ./src # or cti create ./src
|
130 |
|
131 | # without newline
|
132 |
|
133 | ## create sub-command, create sub-command is a default command
|
134 | cti -n ./src
|
135 | cti create -n ./src
|
136 |
|
137 | ## entrypoint sub-command
|
138 | cti entrypoint -n ./src
|
139 |
|
140 | # custom exclude directories
|
141 | cti create -n -e @types,typings,__test__,__tests__,pages ./src
|
142 | ## or
|
143 | cti entrypoint -n -e @types,typings,__test__,__tests__,pages ./src
|
144 |
|
145 | # clean index.ts
|
146 | cti clean ./src # or cti clean ./src
|
147 |
|
148 | # loop through every sub-directory in current path (thanks Mohsen)
|
149 | for f in *; do cti create ./$f; done
|
150 |
|
151 | # Pass variadic directories
|
152 | cti create ./src/server ./src/client ./src/module
|
153 | ```
|
154 |
|
155 | ## CLI with .ctirc
|
156 | create-ts-index cli support `.ctirc` configuration file. Available name is only `.ctirc`. `.ctirc` configuration file can applied by each target directories and script working directory. Every configuration overwrited same feature. Also cti cli arguments forced applied. And `.ctirc` file can write [json5](https://json5.org) format. json5 spec. can comment and more feature.
|
157 |
|
158 | See below search, apply order.
|
159 |
|
160 | ```bash
|
161 | # execute on /Users/cti/github/create-ts-index
|
162 | sh> cti create ./example/type01
|
163 |
|
164 | # search configuration file on "/Users/cti/github/create-ts-index"
|
165 | # search configuration file on "/Users/cti/github/create-ts-index/example/type01"
|
166 | # apply configuration by "/Users/cti/github/create-ts-index"
|
167 | # apply configuration by "/Users/cti/github/create-ts-index/example/type01"
|
168 | # every configuration is overwrited
|
169 | ```
|
170 |
|
171 | ### .ctirc creation
|
172 | You can use cli for `.ctirc` file creation.
|
173 |
|
174 | ```bash
|
175 | # create current directory
|
176 | > cti init
|
177 |
|
178 | # create multiple directory
|
179 | > cti init ./example/type03 ./example/type02
|
180 | ```
|
181 |
|
182 | # Language
|
183 | * [English](https://github.com/imjuni/create-ts-index/blob/master/README.md)
|
184 | * [Korean](https://github.com/imjuni/create-ts-index/blob/master/README.ko.md)
|