1
1
#!/usr/bin/env node
2
2
const fs = require ( "fs" ) ;
3
3
const path = require ( "path" ) ;
4
- const chalk = require ( "chalk " ) ;
4
+ const colors = require ( "../cli/util/colors " ) ;
5
5
const version = require ( "../package.json" ) . version ;
6
6
7
7
if ( process . argv . length < 3 ) printHelp ( ) ;
8
8
9
9
function printHelp ( ) {
10
10
console . log ( [
11
11
"Version " + version ,
12
- "Syntax: " + chalk . cyan ( "asinit" ) + " [project directory]" ,
12
+ "Syntax: " + colors . cyan ( "asinit" ) + " [project directory]" ,
13
13
"" ,
14
- chalk . white . bold ( "Sets up a new AssemblyScript project or updates an existing one." ) ,
14
+ colors . white ( "Sets up a new AssemblyScript project or updates an existing one." ) ,
15
15
"" ,
16
16
"For example, to create a new project in the current directory:" ,
17
17
"" ,
18
- " " + chalk . cyan ( "asinit" ) + " ." ,
18
+ " " + colors . cyan ( "asinit" ) + " ." ,
19
19
] . join ( "\n" ) ) ;
20
20
process . exit ( 0 ) ;
21
21
}
@@ -40,38 +40,38 @@ const indexFile = path.join(projectDir, "index.js");
40
40
console . log ( [
41
41
"Version: " + version ,
42
42
"" ,
43
- chalk . white . bold ( [
43
+ colors . white ( [
44
44
"This command will make sure that the following files exist in the project" ,
45
45
"directory '" + projectDir + "':"
46
46
] . join ( "\n" ) ) ,
47
47
"" ,
48
- chalk . cyan ( " ./assembly" ) ,
48
+ colors . cyan ( " ./assembly" ) ,
49
49
" Directory holding the AssemblyScript sources being compiled to WebAssembly." ,
50
50
"" ,
51
- chalk . cyan ( " ./assembly/tsconfig.json" ) ,
51
+ colors . cyan ( " ./assembly/tsconfig.json" ) ,
52
52
" TypeScript configuration inheriting recommended AssemblyScript settings." ,
53
53
"" ,
54
- chalk . cyan ( " ./assembly/index.ts" ) ,
54
+ colors . cyan ( " ./assembly/index.ts" ) ,
55
55
" Exemplary entry file being compiled to WebAssembly to get you started." ,
56
56
"" ,
57
- chalk . cyan ( " ./build" ) ,
57
+ colors . cyan ( " ./build" ) ,
58
58
" Build artifact directory where compiled WebAssembly files are stored." ,
59
59
"" ,
60
- chalk . cyan ( " ./build/.gitignore" ) ,
60
+ colors . cyan ( " ./build/.gitignore" ) ,
61
61
" Git configuration that excludes compiled binaries from source control." ,
62
62
"" ,
63
- chalk . cyan ( " ./index.js" ) ,
63
+ colors . cyan ( " ./index.js" ) ,
64
64
" Main file loading the WebAssembly module and exporting its exports." ,
65
65
"" ,
66
- chalk . cyan ( " ./package.json" ) ,
66
+ colors . cyan ( " ./package.json" ) ,
67
67
" Package info containing the necessary commands to compile to WebAssembly." ,
68
68
"" ,
69
69
"The command will try to update existing files to match the correct settings" ,
70
70
"for this instance of the compiler in '" + compilerDir + "'." ,
71
71
""
72
72
] . join ( "\n" ) ) ;
73
73
74
- rl . question ( chalk . white . bold ( "Do you want to proceed?" ) + " [Y/n] " , answer => {
74
+ rl . question ( colors . white ( "Do you want to proceed?" ) + " [Y/n] " , answer => {
75
75
if ( ! / ^ y ? $ / i. test ( answer ) ) {
76
76
process . exit ( 1 ) ;
77
77
return ;
@@ -86,33 +86,33 @@ rl.question(chalk.white.bold("Do you want to proceed?") + " [Y/n] ", answer => {
86
86
ensurePackageJson ( ) ;
87
87
ensureIndexJs ( ) ;
88
88
console . log ( [
89
- chalk . green ( "Done!" ) ,
89
+ colors . green ( "Done!" ) ,
90
90
"" ,
91
- "To edit the entry file, open '" + chalk . cyan ( "assembly/index.ts" ) + "' in your editor of choice." ,
91
+ "To edit the entry file, open '" + colors . cyan ( "assembly/index.ts" ) + "' in your editor of choice." ,
92
92
"Create as many additional files as necessary and use them as imports." ,
93
93
"" ,
94
94
"To build the entry file to WebAssembly when you are ready, run:" ,
95
95
"" ,
96
- chalk . white . bold ( " npm run asbuild" ) ,
96
+ colors . white ( " npm run asbuild" ) ,
97
97
"" ,
98
98
"Running the command above creates the following binaries incl. their respective" ,
99
99
"text format representations and source maps:" ,
100
100
"" ,
101
- chalk . cyan ( " ./build/untouched.wasm" ) ,
102
- chalk . cyan ( " ./build/untouched.wasm.map" ) ,
103
- chalk . cyan ( " ./build/untouched.wat" ) ,
101
+ colors . cyan ( " ./build/untouched.wasm" ) ,
102
+ colors . cyan ( " ./build/untouched.wasm.map" ) ,
103
+ colors . cyan ( " ./build/untouched.wat" ) ,
104
104
"" ,
105
105
" ^ The untouched WebAssembly module as generated by the compiler." ,
106
106
" This one matches your sources exactly, without any optimizations." ,
107
107
"" ,
108
- chalk . cyan ( " ./build/optimized.wasm" ) ,
109
- chalk . cyan ( " ./build/optimized.wasm.map" ) ,
110
- chalk . cyan ( " ./build/optimized.wat" ) ,
108
+ colors . cyan ( " ./build/optimized.wasm" ) ,
109
+ colors . cyan ( " ./build/optimized.wasm.map" ) ,
110
+ colors . cyan ( " ./build/optimized.wat" ) ,
111
111
"" ,
112
112
" ^ The optimized WebAssembly module using default optimization settings (-O2s)." ,
113
- " You can change the optimization settings in '" + chalk . cyan ( "package.json" ) + "'." ,
113
+ " You can change the optimization settings in '" + colors . cyan ( "package.json" ) + "'." ,
114
114
"" ,
115
- chalk . white . bold ( "Additional documentation is available at the AssemblyScript wiki:" ) ,
115
+ colors . white ( "Additional documentation is available at the AssemblyScript wiki:" ) ,
116
116
"" ,
117
117
" https://github.com/AssemblyScript/assemblyscript/wiki" ,
118
118
"" ,
@@ -125,9 +125,9 @@ function ensureProjectDirectory() {
125
125
console . log ( "- Making sure that the project directory exists..." ) ;
126
126
if ( ! fs . existsSync ( projectDir ) ) {
127
127
fs . mkdirSync ( projectDir ) ;
128
- console . log ( chalk . green ( " Created: " ) + projectDir ) ;
128
+ console . log ( colors . green ( " Created: " ) + projectDir ) ;
129
129
} else {
130
- console . log ( chalk . yellow ( " Exists: " ) + projectDir ) ;
130
+ console . log ( colors . yellow ( " Exists: " ) + projectDir ) ;
131
131
}
132
132
console . log ( ) ;
133
133
}
@@ -136,9 +136,9 @@ function ensureAssemblyDirectory() {
136
136
console . log ( "- Making sure that the 'assembly' directory exists..." ) ;
137
137
if ( ! fs . existsSync ( assemblyDir ) ) {
138
138
fs . mkdirSync ( assemblyDir ) ;
139
- console . log ( chalk . green ( " Created: " ) + assemblyDir ) ;
139
+ console . log ( colors . green ( " Created: " ) + assemblyDir ) ;
140
140
} else {
141
- console . log ( chalk . yellow ( " Exists: " ) + assemblyDir ) ;
141
+ console . log ( colors . yellow ( " Exists: " ) + assemblyDir ) ;
142
142
}
143
143
console . log ( ) ;
144
144
}
@@ -153,13 +153,13 @@ function ensureTsconfigJson() {
153
153
"./**/*.ts"
154
154
]
155
155
} , null , 2 ) ) ;
156
- console . log ( chalk . green ( " Created: " ) + tsconfigFile ) ;
156
+ console . log ( colors . green ( " Created: " ) + tsconfigFile ) ;
157
157
158
158
} else {
159
159
let tsconfig = JSON . parse ( fs . readFileSync ( tsconfigFile , "utf8" ) ) ;
160
160
tsconfig [ "extends" ] = base ;
161
161
fs . writeFileSync ( tsconfigFile , JSON . stringify ( tsconfig , null , 2 ) ) ;
162
- console . log ( chalk . green ( " Updated: " ) + tsconfigFile ) ;
162
+ console . log ( colors . green ( " Updated: " ) + tsconfigFile ) ;
163
163
}
164
164
console . log ( ) ;
165
165
}
@@ -174,9 +174,9 @@ function ensureEntryFile() {
174
174
" return a + b;" ,
175
175
"}"
176
176
] . join ( "\n" ) + "\n" ) ;
177
- console . log ( chalk . green ( " Created: " ) + entryFile ) ;
177
+ console . log ( colors . green ( " Created: " ) + entryFile ) ;
178
178
} else {
179
- console . log ( chalk . yellow ( " Exists: " ) + entryFile ) ;
179
+ console . log ( colors . yellow ( " Exists: " ) + entryFile ) ;
180
180
}
181
181
console . log ( ) ;
182
182
}
@@ -185,9 +185,9 @@ function ensureBuildDirectory() {
185
185
console . log ( "- Making sure that the 'build' directory exists..." ) ;
186
186
if ( ! fs . existsSync ( buildDir ) ) {
187
187
fs . mkdirSync ( buildDir ) ;
188
- console . log ( chalk . green ( " Created: " ) + buildDir ) ;
188
+ console . log ( colors . green ( " Created: " ) + buildDir ) ;
189
189
} else {
190
- console . log ( chalk . yellow ( " Exists: " ) + buildDir ) ;
190
+ console . log ( colors . yellow ( " Exists: " ) + buildDir ) ;
191
191
}
192
192
console . log ( ) ;
193
193
}
@@ -200,9 +200,9 @@ function ensureGitignore() {
200
200
"*.wasm.map" ,
201
201
"*.asm.js"
202
202
] . join ( "\n" ) + "\n" ) ;
203
- console . log ( chalk . green ( " Created: " ) + gitignoreFile ) ;
203
+ console . log ( colors . green ( " Created: " ) + gitignoreFile ) ;
204
204
} else {
205
- console . log ( chalk . yellow ( " Exists: " ) + gitignoreFile ) ;
205
+ console . log ( colors . yellow ( " Exists: " ) + gitignoreFile ) ;
206
206
}
207
207
console . log ( ) ;
208
208
}
@@ -221,7 +221,7 @@ function ensurePackageJson() {
221
221
"asbuild" : buildAll
222
222
}
223
223
} , null , 2 ) ) ;
224
- console . log ( chalk . green ( " Created: " ) + packageFile ) ;
224
+ console . log ( colors . green ( " Created: " ) + packageFile ) ;
225
225
} else {
226
226
let pkg = JSON . parse ( fs . readFileSync ( packageFile ) ) ;
227
227
let scripts = pkg [ "scripts" ] ;
@@ -232,9 +232,9 @@ function ensurePackageJson() {
232
232
scripts [ "asbuild" ] = buildAll ;
233
233
pkg [ "scripts" ] = scripts ;
234
234
fs . writeFileSync ( packageFile , JSON . stringify ( pkg , null , 2 ) ) ;
235
- console . log ( chalk . green ( " Updated: " ) + packageFile ) ;
235
+ console . log ( colors . green ( " Updated: " ) + packageFile ) ;
236
236
} else {
237
- console . log ( chalk . yellow ( " Exists: " ) + packageFile ) ;
237
+ console . log ( colors . yellow ( " Exists: " ) + packageFile ) ;
238
238
}
239
239
}
240
240
console . log ( ) ;
@@ -251,9 +251,9 @@ function ensureIndexJs() {
251
251
" get: () => new WebAssembly.Instance(compiled, imports).exports" ,
252
252
"});" ,
253
253
] . join ( "\n" ) + "\n" ) ;
254
- console . log ( chalk . green ( " Created: " ) + indexFile ) ;
254
+ console . log ( colors . green ( " Created: " ) + indexFile ) ;
255
255
} else {
256
- console . log ( chalk . yellow ( " Exists: " ) + indexFile ) ;
256
+ console . log ( colors . yellow ( " Exists: " ) + indexFile ) ;
257
257
}
258
258
console . log ( ) ;
259
259
}
0 commit comments