forked from ember-fastboot/ember-cli-fastboot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix-node-modules.mjs
More file actions
56 lines (52 loc) · 2.06 KB
/
fix-node-modules.mjs
File metadata and controls
56 lines (52 loc) · 2.06 KB
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
/**
* Fix nested packages not using workspace version
* ember-cli-addon-tests will link ember-cli-fastboot and run npm install in the test apps,
* the installation will install fastboot from npm registry rather than workspace version
*/
import path from 'path';
import fs from 'fs-extra';
import { fileURLToPath } from 'url';
import chalk from 'chalk';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const packagesDir = path.resolve(__dirname, '../../packages');
const nodeModulesDir = path.resolve(__dirname, 'node_modules');
const precookedDir = path.resolve(__dirname, 'tmp', 'precooked_node_modules');
// eslint-disable-next-line no-undef
const shouldRestore = process.argv[2];
if (shouldRestore === '--help' || shouldRestore === '-h') {
console.log(`Usage: node fix-node-modules.mjs [arguments]
Options:
-h, --help print this message
-r, --restore restore node_modules by removing symlinks`);
} else if (shouldRestore === '-r' || shouldRestore === '--restore') {
run(true);
} else {
run(false);
}
function run(shouldRestore) {
['fastboot', 'fastboot-express-middleware'].forEach((packageName) => {
const nodeModulesPackageDir = path.join(nodeModulesDir, packageName);
const precookedPackageDir = path.join(precookedDir, packageName);
const workspacesPackageDir = path.resolve(packagesDir, packageName);
if (fs.existsSync(nodeModulesPackageDir)) {
console.log(chalk.blue(`remove ${nodeModulesPackageDir}`));
fs.removeSync(nodeModulesPackageDir);
}
if (fs.existsSync(precookedPackageDir)) {
console.log(chalk.blue(`remove ${precookedPackageDir}`));
fs.removeSync(precookedPackageDir);
}
if (!shouldRestore) {
console.log(
chalk.green(
`symlink ${nodeModulesPackageDir} -> ${workspacesPackageDir}`
)
);
fs.symlinkSync(workspacesPackageDir, nodeModulesPackageDir, 'dir');
console.log(
chalk.green(`symlink ${precookedPackageDir} -> ${workspacesPackageDir}`)
);
fs.symlinkSync(workspacesPackageDir, precookedPackageDir, 'dir');
}
});
}