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

bug/issue-1253 misleading init scaffolding instructions #1288

Merged
Merged
Changes from all 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
24 changes: 20 additions & 4 deletions packages/init/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,13 @@ const run = async () => {
try {
const firstArg = process.argv[process.argv.length - 1].split(' ')[0];
const taskRunner = program.yarn ? 'yarn' : 'npm run';
// bypassing commander here for my-app directory option, since I couldn't get it to work as an argument :/
// https://github.com/tj/commander.js?tab=readme-ov-file#command-arguments
const shouldChangeDirectory = !firstArg.startsWith('--') && firstArg !== '';
const shouldInstallDeps = program.install || program.yarn;
const instructions = [];

if (!firstArg.startsWith('--') && firstArg !== '') {
if (shouldChangeDirectory) {
TARGET_DIR = path.join(TARGET_DIR, `./${firstArg}`);

if (!fs.existsSync(TARGET_DIR)) {
Expand All @@ -283,20 +287,32 @@ const run = async () => {
console.log('Creating package.json...');
await npmInit();

if (program.install || program.yarn) {
if (shouldInstallDeps) {
console.log('Installing project dependencies...');
await install();
}

await cleanUp();

console.log(`${chalk.rgb(175, 207, 71)('Initializing new project complete!')}`);
console.log(`${chalk.rgb(175, 207, 71)('Complete the follow steps to get started:')}`);

if (shouldChangeDirectory) {
console.log(`Change directories by running => cd ${firstArg}`);
instructions.push(`Change directories by running => cd ${firstArg}`);
}

if (!shouldInstallDeps) {
instructions.push('Install dependencies with your package manager, e.g. => npm i');
}

console.log(`To start developing run => ${taskRunner} dev`);
instructions.push(`To start developing run => ${taskRunner} dev`);

// output all instructions in step-based order
instructions.forEach((instruction, idx) => {
const step = idx += 1;

console.log(`${step}) ${instruction}`);
});
} catch (err) {
console.error(err);
}
Expand Down
Loading