@@ -8,6 +8,33 @@ const colors = require("../cli/util/colors");
8
8
const version = require ( "../package.json" ) . version ;
9
9
const options = require ( "../cli/util/options" ) ;
10
10
11
+ const commands = {
12
+ "npm" : {
13
+ install : "npm install" ,
14
+ run : "npm run" ,
15
+ test : "npm test"
16
+ } ,
17
+ "yarn" : {
18
+ install : "yarn install" ,
19
+ run : "yarn" ,
20
+ test : "yarn test"
21
+ } ,
22
+ "pnpm" : {
23
+ install : "pnpm install" ,
24
+ run : "pnpm run" ,
25
+ test : "pnpm test"
26
+ }
27
+ } ;
28
+
29
+ let pm = "npm" ;
30
+ if ( typeof process . env . npm_config_user_agent === "string" ) {
31
+ if ( / \b y a r n \/ / . test ( process . env . npm_config_user_agent ) ) {
32
+ pm = "yarn" ;
33
+ } else if ( / \b p n p m \/ / . test ( process . env . npm_config_user_agent ) ) {
34
+ pm = "pnpm" ;
35
+ }
36
+ }
37
+
11
38
const asinitOptions = {
12
39
"help" : {
13
40
"category" : "General" ,
@@ -118,14 +145,14 @@ function createProject(answer) {
118
145
"" ,
119
146
"Don't forget to install dependencies before you start:" ,
120
147
"" ,
121
- colors . white ( " npm install" ) ,
148
+ colors . white ( " " + commands [ pm ] . install ) ,
122
149
"" ,
123
150
"To edit the entry file, open '" + colors . cyan ( "assembly/index.ts" ) + "' in your editor of choice." ,
124
151
"Create as many additional files as necessary and use them as imports." ,
125
152
"" ,
126
153
"To build the entry file to WebAssembly when you are ready, run:" ,
127
154
"" ,
128
- colors . white ( " npm run asbuild" ) ,
155
+ colors . white ( " " + commands [ pm ] . run + " asbuild") ,
129
156
"" ,
130
157
"Running the command above creates the following binaries incl. their respective" ,
131
158
"text format representations and source maps:" ,
@@ -146,7 +173,7 @@ function createProject(answer) {
146
173
"" ,
147
174
"To run the tests, do:" ,
148
175
"" ,
149
- colors . white ( " npm test" ) ,
176
+ colors . white ( " " + commands [ pm ] . test ) ,
150
177
"" ,
151
178
"The AssemblyScript documentation covers all the details:" ,
152
179
"" ,
@@ -289,7 +316,7 @@ function ensurePackageJson() {
289
316
const entryPath = path . relative ( projectDir , entryFile ) . replace ( / \\ / g, "/" ) ;
290
317
const buildUntouched = "asc " + entryPath + " --target debug" ;
291
318
const buildOptimized = "asc " + entryPath + " --target release" ;
292
- const buildAll = "npm run asbuild:untouched && npm run asbuild:optimized";
319
+ const buildAll = commands [ pm ] . run + " asbuild:untouched && " + commands [ pm ] . run + " asbuild:optimized";
293
320
if ( ! fs . existsSync ( packageFile ) ) {
294
321
fs . writeFileSync ( packageFile , JSON . stringify ( {
295
322
"scripts" : {
0 commit comments