@@ -39,10 +39,10 @@ npm install @tsed/core @tsed/di @tsed/cli-core
3939
4040## Getting started
4141
42- Create CLI require some steps like create a package.json with the right information and create a structure directory
42+ Create CLI requires some steps like create a package.json with the right information and create a structure directory
4343aligned with TypeScript to be compiled correctly for a npm deployment.
4444
45- Here a structure directory example:
45+ Here is a structure directory example:
4646
4747```
4848.
@@ -57,93 +57,6 @@ Here a structure directory example:
5757└── tsconfig.compile.json
5858```
5959
60- ## Create package.json and tsconfig
61-
62- The first step is to create the package.json with the following lines:
63-
64- ``` jsonc
65- {
66- " name" : " {{name}}" ,
67- " version" : " 1.0.0" ,
68- " main" : " ./lib/index.js" ,
69- " typings" : " ./lib/index.d.ts" ,
70- " bin" : {
71- " tsed" : " lib/bin/{{name}}.js"
72- },
73- " files" : [" lib/bin/{{name}}.js" , " lib/bin" , " lib" , " templates" ],
74- " description" : " An awesome CLI build on top of @tsed/cli-core" ,
75- " dependencies" : {
76- " @tsed/cli-core" : " 1.3.1" ,
77- " tslib" : " 1.11.1"
78- },
79- " devDependencies" : {
80- " @tsed/cli-testing" : " 1.3.1" ,
81- " ts-node" : " latest" ,
82- " typescript" : " latest"
83- },
84- " scripts" : {
85- " build" : " tsc --build tsconfig.compile.json" ,
86- " start:cmd:add" : " cross-env NODE_ENV=development ts-node -r src/bin/{{name}}.ts add -r ./.tmp"
87- },
88- " engines" : {
89- " node" : " >=8.9"
90- },
91- " peerDependencies" : {}
92- }
93- ```
94-
95- Then create tsconfig files one for the IDE (` tsconfig.json ` ):
96-
97- ``` json
98- {
99- "compilerOptions" : {
100- "module" : " commonjs" ,
101- "target" : " es2016" ,
102- "sourceMap" : true ,
103- "declaration" : false ,
104- "experimentalDecorators" : true ,
105- "emitDecoratorMetadata" : true ,
106- "moduleResolution" : " node" ,
107- "isolatedModules" : false ,
108- "suppressImplicitAnyIndexErrors" : false ,
109- "noImplicitAny" : true ,
110- "strictNullChecks" : true ,
111- "noUnusedLocals" : false ,
112- "noUnusedParameters" : false ,
113- "allowSyntheticDefaultImports" : true ,
114- "importHelpers" : true ,
115- "newLine" : " LF" ,
116- "noEmit" : true ,
117- "lib" : [" es7" , " dom" , " esnext.asynciterable" ],
118- "typeRoots" : [" ./node_modules/@types" ]
119- },
120- "linterOptions" : {
121- "exclude" : []
122- },
123- "exclude" : []
124- }
125- ```
126-
127- And another one to compile source (` tsconfig.compile.json ` ):
128-
129- ``` json
130- {
131- "extends" : " ./tsconfig.compile.json" ,
132- "compilerOptions" : {
133- "rootDir" : " src" ,
134- "outDir" : " lib" ,
135- "moduleResolution" : " node" ,
136- "declaration" : true ,
137- "noResolve" : false ,
138- "preserveConstEnums" : true ,
139- "sourceMap" : true ,
140- "noEmit" : false ,
141- "inlineSources" : true
142- },
143- "exclude" : [" node_modules" , " test" , " lib" , " **/*.spec.ts" ]
144- }
145- ```
146-
14760## Create the bin file
14861
14962The bin file is used by npm to create your node.js executable program when you install the node_module globally.
@@ -155,19 +68,13 @@ Create a new file according to your project name (example: `name.ts`) and add th
15568import {AddCmd , CliCore } from " @tsed/cli-core" ;
15669import {resolve } from " node:path" ;
15770
158- const pkg = require (" ../../package.json" );
159- const TEMPLATE_DIR = resolve (__dirname , " .." , " .." , " templates" );
160-
16171CliCore .bootstrap ({
16272 commands: [
16373 AddCmd // CommandProvider to install a plugin
16474 // then add you commands
16575 ],
166-
16776 // optionals
168- name: " name" , // replace by the cli name. This property will be used by Plugins command
169- pkg ,
170- templateDir: TEMPLATE_DIR
77+ name: " name" // replace by the cli name. This property will be used by Plugins command
17178}).catch (console .error );
17279```
17380
@@ -265,12 +172,6 @@ export class GenerateCmd implements CommandProvider {
265172}
266173```
267174
268- Finally, create a handlebars template in templates directory:
269-
270- ``` hbs
271- import {Injectable} from "@tsed/di"; @Injectable() export class {{symbolName}} { }
272- ```
273-
274175## Run command in dev mode
275176
276177In your package.json add the following line in scripts property:
@@ -281,13 +182,13 @@ In your package.json add the following line in scripts property:
281182}
282183```
283184
284- > Note: replace {{name}} by the name of you bin file located in src/bin.
185+ > Note: replace {{name}} by the name of your bin file located in src/bin.
285186
286187> Note 2: The option ` -r ./.tmp ` create a temporary directory to generate files with your command.
287188
288189## More examples
289190
290- Here other commands examples:
191+ Here are other command examples:
291192
292193- Init a project command: https://github.com/tsedio/tsed-cli/tree/master/packages/cli/src/commands/init/InitCmd
293194- Generate command: https://github.com/tsedio/tsed-cli/tree/master/packages/cli/src/commands/generate/GenerateCmd
0 commit comments