-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
66 lines (59 loc) · 2.15 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
const startModules = require('octopus-start-modules-tasks'),
_ = require('lodash'),
startTasks = require('octopus-start-tasks'),
start = require('start').default;
const {iter, modules} = startModules;
const {readJson, writeJson, mergeJson} = startModules.module;
function listModulesTask() {
return () => function listModules(log, reporter) {
return start(reporter)(modules.load(), iter.forEach()(_.noop));
}
}
function whereModuleTask(moduleName) {
return () => function whereModule(log, reporter) {
return start(reporter)(
modules.load(),
iter.async({silent: true})((module, input, asyncReporter) => {
return Promise.resolve().then(() => {
const dep = module.dependencies.find(dep => dep.name === moduleName);
if (dep) {
asyncReporter('whereModule', 'info', `${module.name} (${module.relativePath}) (${module.version})`);
}
})
})
)
}
}
function syncModulesTask(mutateVersion = version => `~${version}`) {
return () => function syncModules(log, reporter) {
return start(reporter)(
modules.load(),
startTasks.props({
modules: modules => modules,
modulesAndVersions: modules => modulesAndVersion(modules, mutateVersion)
}),
iter.async({mapInput: opts => opts.modules, silent: true})((module, input, asyncReporter) => {
const {modulesAndVersions} = input;
const readPackageJson = readJson(module)('package.json');
const writePackageJson = writeJson(module)('package.json');
const logMerged = input => log(`${module.name}: ${input.key} (${input.currentValue} -> ${input.newValue})`);
const mergePackageJson = mergeJson(logMerged)({
dependencies: modulesAndVersions,
devDependencies: modulesAndVersions
});
return start(asyncReporter)(readPackageJson, mergePackageJson, writePackageJson);
})
)
}
}
function modulesAndVersion(modules, mutateVersion) {
return modules.reduce((acc, val) => {
acc[val.name] = mutateVersion(val.version);
return acc;
}, {})
}
module.exports = {
list: listModulesTask,
sync: syncModulesTask,
where: whereModuleTask
};