Skip to content

Commit 3207afb

Browse files
yokos2Rec0iL99dai-shi
committed
feat(create-waku): install dependencies automatically when creating a new waku project (#808)
follow up wakujs/waku#728 - [x] implement a new feature --------- Co-authored-by: Joel Mathew Koshy <[email protected]> Co-authored-by: Daishi Kato <[email protected]>
1 parent ab89806 commit 3207afb

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

Diff for: e2e/create-waku.spec.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { spawn } from 'node:child_process';
1+
import { exec, spawn } from 'node:child_process';
22
import { fileURLToPath } from 'node:url';
33
import crypto from 'node:crypto';
44
import { mkdir, readdir, cp, readFile, writeFile } from 'node:fs/promises';
5-
import { test, debugChildProcess, terminate } from './utils.js';
5+
import { test, debugChildProcess } from './utils.js';
66
import { expect } from '@playwright/test';
77

88
test('should create waku with default setup work', async () => {
@@ -43,7 +43,7 @@ test('should create waku with default setup work', async () => {
4343
expect(files).toContain('package.json');
4444
expect(files).toContain('src');
4545
expect(files).toContain('tsconfig.json');
46-
await terminate(childProcess.pid!);
46+
exec(`rm -rf ${cwd}`);
4747
});
4848

4949
test('should create waku with update notify work', async () => {
@@ -87,5 +87,6 @@ test('should create waku with update notify work', async () => {
8787
break;
8888
}
8989
}
90+
exec(`rm -rf ${cwd}`);
9091
// no need to kill the process, it will exit by itself
9192
});

Diff for: packages/create-waku/src/index.ts

+24-6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
parseExampleOption,
1717
downloadAndExtract,
1818
} from './helpers/example-option.js';
19+
import { spawn } from 'node:child_process';
1920

2021
const userAgent = process.env.npm_config_user_agent || '';
2122
const packageManager = /pnpm/.test(userAgent)
@@ -202,15 +203,32 @@ async function init() {
202203
await installTemplate(root, packageName, templateRoot, templateName);
203204
}
204205

205-
// TODO automatically installing dependencies
206206
// 1. check packageManager
207207
// 2. and then install dependencies
208-
209-
console.log(`\nDone. Now run:\n`);
210-
console.log(`${bold(green(`cd ${targetDir}`))}`);
211-
console.log(`${bold(green(commands.install))}`);
212-
console.log(`${bold(green(commands.dev))}`);
213208
console.log();
209+
console.log(`Installing dependencies by running ${commands.install}...`);
210+
211+
const installProcess = spawn(packageManager, ['install'], {
212+
stdio: 'inherit',
213+
shell: process.platform === 'win32',
214+
cwd: targetDir,
215+
});
216+
217+
installProcess.on('close', (code) => {
218+
// process exit code
219+
if (code !== 0) {
220+
console.error(`Could not execute ${commands.install}. Please run`);
221+
console.log(`${bold(green(`cd ${targetDir}`))}`);
222+
console.log(`${bold(green(commands.install))}`);
223+
console.log(`${bold(green(commands.dev))}`);
224+
console.log();
225+
} else {
226+
console.log(`\nDone. Now run:\n`);
227+
console.log(`${bold(green(`cd ${targetDir}`))}`);
228+
console.log(`${bold(green(commands.dev))}`);
229+
console.log();
230+
}
231+
});
214232
}
215233

216234
init()

0 commit comments

Comments
 (0)