-
Notifications
You must be signed in to change notification settings - Fork 0
/
hoist.js
executable file
·66 lines (48 loc) · 1.91 KB
/
hoist.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
#!/usr/bin/env node
"use strict";
const { getPackages } = require("@lerna/project");
const filterPackages = require("@lerna/filter-packages");
const batchPackages = require("@lerna/batch-packages");
const packageGraph = require("@lerna/package-graph");
const Project = require("@lerna/project");
const minimist = require('minimist')
async function getSortedPackages(rootPath, scope, ignore) {
const packages = await getPackages(rootPath);
const filtered = filterPackages(packages,
scope,
ignore,
true,);
return batchPackages(filtered)
.reduce((arr, batch) => arr.concat(batch), []);
}
function getProductionPackageDependancies(packages) {
return getPackageDependancies(packages, "dependencies");
}
function getAllPackageDependancies(packages) {
return getPackageDependancies(packages, "allDependencies");
}
function getPackageDependancies(packages, whichDependencies) {
let dependancies = {};
const pGraph = new packageGraph(packages, whichDependencies, 0);
pGraph.forEach(packageInfo => {
packageInfo.externalDependencies.forEach(
(packageInfo) => {
dependancies = Object.assign(dependancies, { [packageInfo.name] : packageInfo.rawSpec});
}
);
})
return dependancies;
}
var args = minimist(process.argv.slice(2), {
string: [ '--scope', '--ignore']
});
getSortedPackages(args['_'][0], args['--scope'], args['--ignore']).then((packages) => {
const project = new Project(args['_'][0]);
const dependancies = getProductionPackageDependancies(packages);
const allDependancies = getAllPackageDependancies(packages);
let devDependancies = Object.assign({}, allDependancies);
Object.keys(dependancies).forEach( (key) => delete devDependancies[key]);
Object.assign( project.manifest.dependencies || {}, dependancies);
Object.assign( project.manifest.devDependencies || {}, devDependancies);
return project.manifest.serialize();
})