@@ -7,38 +7,49 @@ import { exec as cpExec } from "child_process";
7
7
8
8
const exec = promisify ( cpExec ) ;
9
9
10
- const packageJson = `{
11
- "name": "@hkamran/utility-{{name}}",
12
- "version": "0.1.0",
13
- "description": "{{description}}",
14
- "main": "index.js",
15
- "types": "index.d.ts",
16
- "type": "module",
17
- "scripts": {
18
- "prepare": "tsc --declaration --emitDeclarationOnly --allowJs index.js",
19
- "test": "echo \\"Error: no test specified\\" && exit 1"
10
+ const packageJson = {
11
+ name : "@hkamran/utility-{{name}}" ,
12
+ version : "0.1.0" ,
13
+ description : "" ,
14
+ main : "index.js" ,
15
+ types : "index.d.ts" ,
16
+ type : "module" ,
17
+ scripts : {
18
+ lint : "eslint --ext .js,.ts --fix" ,
19
+ format : "prettier . --write" ,
20
+ prepare :
21
+ "tsc --declaration --emitDeclarationOnly --allowJs index.js && pnpm lint && pnpm format" ,
22
+ test : 'echo "Error: no test specified" && exit 1' ,
20
23
} ,
21
- " author" : {
22
- " name" : "H. Kamran",
23
-
24
- " url" : "https://hkamran.com"
24
+ author : {
25
+ name : "H. Kamran" ,
26
+
27
+ url : "https://hkamran.com" ,
25
28
} ,
26
- " repository" : {
27
- " type" : "git",
28
- " url" : "git+https://github.com/hkamran80/utilities-js.git",
29
- " directory" : "packages/{{name}}"
29
+ repository : {
30
+ type : "git" ,
31
+ url : "git+https://github.com/hkamran80/utilities-js.git" ,
32
+ directory : "packages/{{name}}" ,
30
33
} ,
31
- " keywords" : [{{keywords}} ],
32
- " license" : "AGPL-3.0-or-later",
33
- " bugs" : {
34
- " url" : "https://github.com/hkamran80/utilities-js/issues?q=is%3Aopen+label%3A%22utility%3A+{{name}}%22+sort%3Aupdated-desc"
34
+ keywords : [ ] ,
35
+ license : "AGPL-3.0-or-later" ,
36
+ bugs : {
37
+ url : "https://github.com/hkamran80/utilities-js/issues?q=is%3Aopen+label%3A%22utility%3A+{{name}}%22+sort%3Aupdated-desc" ,
35
38
} ,
36
- "homepage": "https://github.com/hkamran80/utilities-js/tree/main/packages/{{name}}#readme",
37
- "dependencies": {},
38
- "devDependencies": {
39
- "typescript": "^4.6.2"
40
- }
41
- }` ;
39
+ homepage :
40
+ "https://github.com/hkamran80/utilities-js/tree/main/packages/{{name}}#readme" ,
41
+ publishConfig : {
42
+ access : "public" ,
43
+ } ,
44
+ devDependencies : {
45
+ "@hkamran/prettier-config" : "^1.1.1" ,
46
+ eslint : "^8.36.0" ,
47
+ "eslint-config-prettier" : "^8.7.0" ,
48
+ prettier : "^2.8.4" ,
49
+ typescript : "^4.6.2" ,
50
+ } ,
51
+ prettier : "@hkamran/prettier-config" ,
52
+ } ;
42
53
43
54
const indexJs = `console.log("Hello world!");` ;
44
55
@@ -52,10 +63,40 @@ Create a utility
52
63
## Usage
53
64
54
65
\`\`\`bash
55
- npx @hkamran/utility-{{name}}
66
+ npm i @hkamran/utility-{{name}}
67
+ \`\`\`
68
+
69
+ \`\`\`bash
70
+ pnpm add @hkamran/utility-{{name}}
71
+ \`\`\`
72
+
73
+ \`\`\`bash
74
+ yarn add @hkamran/utility-{{name}}
56
75
\`\`\`
57
76
` ;
58
77
78
+ const ignore = `node_modules/*
79
+ .gitignore
80
+ .dccache
81
+ *.md
82
+
83
+ **/dist/*
84
+ **/node_modules/*
85
+ **/.gitignore
86
+ **/.dccache
87
+ **/*.md` ;
88
+
89
+ const eslintConfig = `module.exports = {
90
+ root: true,
91
+ env: { node: true },
92
+ parserOptions: {
93
+ ecmaVersion: "latest",
94
+ sourceType: "module",
95
+ },
96
+ extends: ["eslint:recommended", "prettier"],
97
+ };
98
+ ` ;
99
+
59
100
const questions = [
60
101
{
61
102
type : "list" ,
@@ -85,22 +126,27 @@ const questions = [
85
126
86
127
const answers = await inquirer . prompt ( questions ) ;
87
128
88
- await writeFile (
89
- "package.json" ,
90
- packageJson
91
- . replace ( / { { name} } / gm, answers . name . toLowerCase ( ) . replace ( / / gm, "-" ) )
92
- . replace ( / { { description} } / gm, answers . description )
93
- . replace (
94
- / { { keywords} } / gm,
95
- answers . keywords . length > 0
96
- ? answers . keywords
97
- . toLowerCase ( )
98
- . split ( "," )
99
- . map ( ( keyword ) => `"${ keyword } "` )
100
- . join ( "," )
101
- : "" ,
102
- ) ,
129
+ /** @type {string } */
130
+ const packageName = answers . name . toLowerCase ( ) . replace ( / / gm, "-" ) ;
131
+
132
+ packageJson . name = packageJson . name . replace ( / { { name} } / gm, packageName ) ;
133
+ packageJson . repository . directory = packageJson . repository . directory . replace (
134
+ / { { name} } / gm,
135
+ packageName ,
103
136
) ;
137
+ packageJson . bugs . url = packageJson . bugs . url . replace ( / { { name} } / gm, packageName ) ;
138
+ packageJson . homepage = packageJson . homepage . replace ( / { { name} } / gm, packageName ) ;
139
+
140
+ packageJson . description = answers . description ;
141
+ packageJson . keywords =
142
+ answers . keywords . length > 0
143
+ ? answers . keywords . toLowerCase ( ) . split ( "," )
144
+ : [ ] ;
145
+
146
+ await writeFile ( "package.json" , JSON . stringify ( packageJson ) ) ;
147
+ await writeFile ( ".eslintignore" , ignore ) ;
148
+ await writeFile ( ".prettierignore" , ignore ) ;
149
+ await writeFile ( ".eslintrc.js" , eslintConfig ) ;
104
150
105
151
await writeFile (
106
152
"README.md" ,
@@ -111,6 +157,7 @@ await writeFile(
111
157
112
158
await writeFile ( "index.js" , indexJs ) ;
113
159
114
- await exec ( `${ answers . npm_executable . toLowerCase ( ) } install` ) ;
160
+ await exec ( `${ answers . npm_executable } install` ) ;
161
+ await exec ( `${ answers . npm_executable } run prepare` ) ;
115
162
116
163
console . log ( "Utility created!" ) ;
0 commit comments