@@ -8,6 +8,33 @@ const colors = require("../cli/util/colors");
88const version = require ( "../package.json" ) . version ;
99const options = require ( "../cli/util/options" ) ;
1010
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+
1138const asinitOptions = {
1239 "help" : {
1340 "category" : "General" ,
@@ -118,14 +145,14 @@ function createProject(answer) {
118145 "" ,
119146 "Don't forget to install dependencies before you start:" ,
120147 "" ,
121- colors . white ( " npm install" ) ,
148+ colors . white ( " " + commands [ pm ] . install ) ,
122149 "" ,
123150 "To edit the entry file, open '" + colors . cyan ( "assembly/index.ts" ) + "' in your editor of choice." ,
124151 "Create as many additional files as necessary and use them as imports." ,
125152 "" ,
126153 "To build the entry file to WebAssembly when you are ready, run:" ,
127154 "" ,
128- colors . white ( " npm run asbuild" ) ,
155+ colors . white ( " " + commands [ pm ] . run + " asbuild") ,
129156 "" ,
130157 "Running the command above creates the following binaries incl. their respective" ,
131158 "text format representations and source maps:" ,
@@ -146,7 +173,7 @@ function createProject(answer) {
146173 "" ,
147174 "To run the tests, do:" ,
148175 "" ,
149- colors . white ( " npm test" ) ,
176+ colors . white ( " " + commands [ pm ] . test ) ,
150177 "" ,
151178 "The AssemblyScript documentation covers all the details:" ,
152179 "" ,
@@ -289,7 +316,7 @@ function ensurePackageJson() {
289316 const entryPath = path . relative ( projectDir , entryFile ) . replace ( / \\ / g, "/" ) ;
290317 const buildUntouched = "asc " + entryPath + " --target debug" ;
291318 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";
293320 if ( ! fs . existsSync ( packageFile ) ) {
294321 fs . writeFileSync ( packageFile , JSON . stringify ( {
295322 "scripts" : {
0 commit comments