Skip to content

Commit

Permalink
bug/issue-1253 misleading init scaffolding instructions (#1288)
Browse files Browse the repository at this point in the history
* clearer post init user next steps instructions

* commenting and clean up
  • Loading branch information
thescientist13 authored Nov 1, 2024
1 parent 198f87a commit 39d0a3c
Showing 1 changed file with 20 additions and 4 deletions.
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

0 comments on commit 39d0a3c

Please sign in to comment.