Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(create-waku): install dependencies automatically when creating a new waku #728

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/create-waku/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@
"build": "ncc build ./src/index.ts -o ./dist/ --minify --no-cache --no-source-map-register"
},
"devDependencies": {
"@types/cross-spawn": "^6.0.6",
"@types/fs-extra": "^11.0.4",
"@types/prompts": "^2.4.9",
"@types/tar": "^6.1.13",
"@vercel/ncc": "^0.38.1",
"cross-spawn": "^7.0.3",
Rec0iL99 marked this conversation as resolved.
Show resolved Hide resolved
"fs-extra": "^11.2.0",
"kolorist": "^1.8.0",
"prompts": "^2.4.2",
Expand Down
33 changes: 26 additions & 7 deletions packages/create-waku/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
parseExampleOption,
downloadAndExtract,
} from './helpers/example-option.js';
import process from 'node:process';
Rec0iL99 marked this conversation as resolved.
Show resolved Hide resolved
import { sync } from 'cross-spawn';

const userAgent = process.env.npm_config_user_agent || '';
const packageManager = /pnpm/.test(userAgent)
Expand All @@ -30,7 +32,7 @@ const commands = {
create: 'pnpm create waku',
},
yarn: {
install: 'yarn',
install: 'yarn install',
dev: 'yarn dev',
create: 'yarn create waku',
},
Expand Down Expand Up @@ -202,15 +204,32 @@ async function init() {
await installTemplate(root, packageName, templateRoot, templateName);
}

// TODO automatically installing dependencies
// 1. check packageManager
// 2. and then install dependencies

console.log(`\nDone. Now run:\n`);
console.log(`${bold(green(`cd ${targetDir}`))}`);
console.log(`${bold(green(commands.install))}`);
console.log(`${bold(green(commands.dev))}`);
console.log();
console.log(`Installing dependencies by running ${commands.install}...`);

process.chdir(targetDir);
const [, installFlag] = commands.install.split(' ');
Rec0iL99 marked this conversation as resolved.
Show resolved Hide resolved
Rec0iL99 marked this conversation as resolved.
Show resolved Hide resolved

// synchronously install all the deps
Rec0iL99 marked this conversation as resolved.
Show resolved Hide resolved
const installProcess = sync(packageManager, [installFlag!], {
Rec0iL99 marked this conversation as resolved.
Show resolved Hide resolved
stdio: 'inherit',
});
const error = installProcess.error;

if (error) {
console.error(`Could not execute ${commands.install}. Please run`);
console.log(`${bold(green(`cd ${targetDir}`))}`);
console.log(`${bold(green(commands.install))}`);
console.log(`${bold(green(commands.dev))}`);
console.log();
} else {
console.log(`\nDone. Now run:\n`);
console.log(`${bold(green(`cd ${targetDir}`))}`);
console.log(`${bold(green(commands.dev))}`);
console.log();
}
}

init()
Expand Down
12 changes: 12 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading