Skip to content

Commit

Permalink
Display name of a correct package manager (npm, yarn or pnpm - the on…
Browse files Browse the repository at this point in the history
…e that has previously been choosen to install packages) in `Get Started` instruction.
  • Loading branch information
nenadvicentic committed Nov 25, 2022
1 parent 33d3a7e commit 6d719e9
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 10 deletions.
86 changes: 82 additions & 4 deletions __test__/after-task.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ansiColors.inverse = ansiColors;
ansiColors.underline = ansiColors;
ansiColors.bold = ansiColors;

const isAvailable = bin => bin === 'yarn';
const isAvailable = bin => bin === 'yarn' || bin === 'pnpm';

test('"after" task only prints summary in unattended mode', async t => {
const prompts = {
Expand Down Expand Up @@ -79,10 +79,49 @@ test('"after" task only prints summary in unattended mode and here mode', async
);
});

test('"after" task installs deps, and prints summary', async t => {
test('"after" task installs deps with npm, and prints summary', async t => {
const prompts = {
select(opts) {
t.deepEqual(opts.choices.map(c => c.value), [undefined, 'npm', 'yarn']);
t.deepEqual(opts.choices.map(c => c.value), [undefined, 'npm', 'yarn', 'pnpm']);
return 'npm';
}
};

function run(cmd, args) {
t.is(cmd, 'npm');
t.deepEqual(args, ['install']);
}

let printOut = '';
await after({
unattended: false,
here: false,
prompts,
run,
properties: {name: 'my-app'},
features: ['a', 'b'],
notDefaultFeatures: ['a', 'b-c'],
ansiColors
}, {
_isAvailable: isAvailable,
_log(m) {
printOut += m + '\n';
}
});

t.is(printOut,
'\nNext time, you can try to create similar project in silent mode:\n' +
' npx makes aurelia new-project-name -s a,b-c \n\n' +
'Get Started\n' +
'cd my-app\n' +
'npm start\n\n'
);
});

test('"after" task installs deps with yarn, and prints summary', async t => {
const prompts = {
select(opts) {
t.deepEqual(opts.choices.map(c => c.value), [undefined, 'npm', 'yarn', 'pnpm']);
return 'yarn';
}
};
Expand Down Expand Up @@ -114,7 +153,46 @@ test('"after" task installs deps, and prints summary', async t => {
' npx makes aurelia new-project-name -s a,b-c \n\n' +
'Get Started\n' +
'cd my-app\n' +
'npm start\n\n'
'yarn start\n\n'
);
});

test('"after" task installs deps with pnpm, and prints summary', async t => {
const prompts = {
select(opts) {
t.deepEqual(opts.choices.map(c => c.value), [undefined, 'npm', 'yarn', 'pnpm']);
return 'pnpm';
}
};

function run(cmd, args) {
t.is(cmd, 'pnpm');
t.deepEqual(args, ['install']);
}

let printOut = '';
await after({
unattended: false,
here: false,
prompts,
run,
properties: {name: 'my-app'},
features: ['a', 'b'],
notDefaultFeatures: ['a', 'b-c'],
ansiColors
}, {
_isAvailable: isAvailable,
_log(m) {
printOut += m + '\n';
}
});

t.is(printOut,
'\nNext time, you can try to create similar project in silent mode:\n' +
' npx makes aurelia new-project-name -s a,b-c \n\n' +
'Get Started\n' +
'cd my-app\n' +
'pnpm start\n\n'
);
});

Expand Down
19 changes: 13 additions & 6 deletions after.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = async function({
} = {}) {
const c = ansiColors;
let depsInstalled = false;
let packageManager = undefined;

if (!unattended) {
const choices = [
Expand All @@ -28,22 +29,27 @@ module.exports = async function({
];

if (_isAvailable('yarn')) {
choices.push({value: 'yarn', title: 'Yes, use yarn'});
choices.push({value: 'yarn', title: 'Yes, use yarn (node-modules)'});
}

if (_isAvailable('pnpm')) {
choices.push({value: 'pnpm', title: 'Yes, use pnpm'});
}

const result = await prompts.select({
packageManager = await prompts.select({
message: 'Do you want to install npm dependencies now?',
choices
});

if (result) {
await run(result, ['install']);
if (packageManager) {
await run(packageManager, ['install']);

if (features.includes('playwright')) {
await run('npx', ['playwright', 'install', '--with-deps']);
if (packageManager === 'npm') {
await run('npx', ['playwright', 'install', '--with-deps']);
} else {
await run(packageManager, ['dlx', 'playwright', 'install', '--with-deps']);
}
}
depsInstalled = true;
}
Expand All @@ -54,9 +60,10 @@ module.exports = async function({

_log(`\n${c.underline.bold('Get Started')}`);
if (!here) _log('cd ' + properties.name);

if (!depsInstalled) {
_log('npm install');
if (features.includes('playwright')) _log('npx playwright install --with-deps');
}
_log('npm start\n');
_log((packageManager ?? 'npm') + ' start\n');
};

0 comments on commit 6d719e9

Please sign in to comment.