-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.js
70 lines (55 loc) · 2.31 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* eslint no-console: "off" */
const chalk = require('chalk');
const { spawnSync } = require('child_process');
const fs = require('fs');
const del = require('del');
const editJsonFile = require('edit-json-file');
module.exports = () => {
console.log(chalk.magenta('\ndeyarn...\n'));
const yarnLockPath = `${process.cwd()}/yarn.lock`;
if (fs.existsSync(yarnLockPath)) {
// Remove yarn.lock.
console.log(chalk.blue('\nRemoving `yarn.lock`.'));
del.sync(yarnLockPath);
if (fs.existsSync(yarnLockPath)) {
console.log(chalk.red('Failed to delete `yarn.lock`'));
process.exit(1);
}
console.log(chalk.blue('Removed `yarn.lock`.'));
}
// Remove node_modules if they exist in order to avoid any potential installation conflicts.
const nodeModsPath = `${process.cwd()}/node_modules`;
if (fs.existsSync(nodeModsPath)) {
console.log(chalk.blue('\nRemoving `node_modules`.'));
del.sync(nodeModsPath);
if (fs.existsSync(nodeModsPath)) {
console.log(chalk.red('Failed to delete `node_modules`'));
process.exit(1);
}
console.log(chalk.blue('Removed `node_modules`.'));
}
// Run `npm i`.
console.log(chalk.blue('\nInstalling dependencies with npm; generating `package-lock.json`.'));
spawnSync('npm', ['i'] /* empty args */, {
stdio: 'inherit',
shell: true
});
// Require that users of this package use npm rather than Yarn since it's easy to forget :).
const packageJsonPath = `${process.cwd()}/package.json`;
const packageJson = editJsonFile(packageJsonPath, {
autosave: true
});
packageJson.set('engines.yarn', 'YARN NO LONGER USED - use npm instead.');
packageJson.set('engines.npm', '>= 5.1');
// Output success.
console.log(chalk.green('\n\nSuccess!\n'));
console.log('NEXT STEPS:');
console.log(' 1. Perform any testing to ensure that package updates were not problematic.');
console.log(' 2. Update package.json scripts to use npm if necessary:');
console.log(' ', chalk.cyan(JSON.stringify(packageJson.get('scripts'))));
console.log(' 3. Update your CI configuration if necessary');
console.log(' 4. Update the README if necessary');
console.log(' - Add preferred npm-install instruction');
console.log(' - Update any other Yarn commands to use npm instead');
console.log(' 5. Commit the made changes');
};