-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
45 lines (33 loc) · 1.25 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
'use strict';
const {parsePackageJson, generateInstallString, generateInstallDevString} = require('./lib/package-json-parser');
const {writeFile, appendFile} = require('./lib/utils');
const path = require('path');
const currentPath = process.cwd();
async function entry(input) {
const forceMode = input.f === true;
const outputFile = input.output || false;
const interactiveMode = input.i === true;
const reportMode = input.report === true;
const fullPath = path.join(currentPath, 'package.json');
const installs = await parsePackageJson(fullPath);
const dependencies = generateInstallString(installs.dependencies);
const devDependencies = generateInstallDevString(installs.devDependencies);
if (forceMode) {
return ':) Force mode not implemented yet';
}
if (outputFile) {
const trimmedFilePath = outputFile.trim();
// Await removeOldFile(trimmedFilePath);
await writeFile(trimmedFilePath, dependencies);
await appendFile(trimmedFilePath, devDependencies);
return `:) You can find your strings inside '${outputFile}'`;
}
if (interactiveMode) {
return ':) Interactive mode not implemented yet';
}
if (reportMode) {
return ':) Report mode not implemented yet';
}
return `${dependencies}\n${devDependencies}`;
}
module.exports = entry;