create-ts-index
Install
npm install create-ts-index --save-dev
Please using ctix
ctix next generation export generation tool. ctix use TypeScript compiler API. So Many problem solve in create-ts-index. For example, separate project(using by tsconfig.json) and support default function, auto detect file that have export statement, etc. I need more help for improvement at ctix.
Introduction
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.
For example, sample directory below.
src/
app.ts
component/
Nav.ts
Button.ts
create-ts-index create sub-command create index.ts file below.
src/
app.ts
> index.ts
// created from 'create-ts-index'
export * from './component';
export * from './app';
component/
Nav.ts
Button.ts
> index.ts
// created from 'create-ts-index'
export * from './Nav';
export * from './Button';
create-ts-index entrypoint sub-command create index.ts file below.
src/
app.ts
component/
Nav.ts
Button.ts
> entrypoint.ts
// created from 'create-ts-index'
export * from './src/app.ts'
export * from './src/component/Nav.ts'
export * from './src/component/Button.ts'
Option
library
fileFirst: boolean
export list create filefirst. default falseaddNewline: boolean
deside add newline file ending. default trueuseSemicolon: boolean
deside use semicolon line ending. default trueuseTimestamp: boolean
deside use timestamp(YYYY-MM-DD HH:mm) top line comment. default falseincludeCWD: boolean
deside include cwd directory. default trueexcludes: string[]
pass exclude directory. default exclude directory is ['@types', 'typings', '__test__', '__tests__']
fileExcludePatterns: string[]
pass exclude filename pattern. default exclude patterns is []
targetExts: string[]
pass include extname. default extname is ['ts', 'tsx']
. extname pass without dot charactor.globOptions: glob.IOptions
pass include glob options. node-glob option use it.quote
deside quote charactor. Single quete charactor use to default.verbose
verbose log message displywithoutComment
remove create-ts-index comment that top of line in index.tswithoutBackupFile
Don't create backupfile if already exists target fileoutput
index.ts or entrypoint.ts filename change
cli (use it cti)
-f --filefirst
export list create filefirst, no option false, option true-n --addnewline
deside add newline file ending. no option true, option false-s --usesemicolon
deside use semicolon line ending. no option true, option false-t --usetimestamp
deside use timestamp(YYYY-MM-DD HH:mm) top line comment. no option false, option true-c --includecwd
deside include cwd directory. no option true, option true-e --excludes [comma separated exclude directories]
pass exclude directory. default exclude directory is ['@types', 'typings', '__test__', '__tests__']
-i --fileexcludes [comma separated extname]
pass exclude filename pattern. default exclude patterns is []
-x --targetexts [comma separated extname]
pass include extname. default extname is ['ts', 'tsx']
. extname pass without dot charactor.-q --quote
deside quote charactor. default quote charactor single quote-v --verbose
disply verbose log message. no option false, option true-w --withoutcomment
remove create-ts-index comment that top of line in index.ts-b --withoutbackup
Don't create backupfile if already exists target file-o --output
index.ts or entrypoint.ts filename change
Usage
library
Use TypeScritIndexWriter
const tsiw = new TypeScritIndexWriter();
const option = TypeScritIndexWriter.getDefaultOption('./src');
(async () => {
await tsiw.create(option);
await tsiw.createEntrypoint(option);
})();
Use CommandModule
(async () => {
const option = CreateTsIndexOption.getOption({});
const createCommand = new CreateCommandModule();
await createCommand.do(process.cwd(), option);
});
CLI
cli use git-style sub-command
- create
- entrypoint
- cti create webpack entrypoint
- init
- clean
- cti clean index.ts file recursively
cti create ./src
cti entrypoint ./src
cti -n ./src
cti create -n ./src
cti entrypoint -n ./src
cti create -n -e @types,typings,__test__,__tests__,pages ./src
cti entrypoint -n -e @types,typings,__test__,__tests__,pages ./src
cti clean ./src
for f in *; do cti create ./$f; done
cti create ./src/server ./src/client ./src/module
CLI with .ctirc
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 format. json5 spec. can comment and more feature.
See below search, apply order.
sh> cti create ./example/type01
.ctirc creation
You can use cli for .ctirc
file creation.
> cti init
> cti init ./example/type03 ./example/type02
Language