Skip to content

Commit 0f11a7d

Browse files
authored
Oleg/feature/1536044437 (#76)
* ores/auto-commit => 'set' * ores/auto-commit => 'set' * ores/auto-commit => 'set' * ores/auto-commit => 'set' * ores/auto-commit => 'set' * ores/auto-commit => 'set' * ores/auto-commit => 'set' * ores/auto-commit => 'set' * ores/auto-commit => 'set' * ores/auto-commit => 'set' * ores/auto-commit => 'set' * ores/auto-commit => 'set' * ores/auto-commit => 'set' * ores/auto-commit => 'set'
1 parent be37951 commit 0f11a7d

File tree

5 files changed

+39
-16
lines changed

5 files changed

+39
-16
lines changed

cli/index.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fi
3232

3333
if ! type -f ores_get_project_root &> /dev/null; then
3434
npm i -s -g '@oresoftware/ores' || {
35-
echo "Could not install '@oresoftware/ores'";
35+
echo "Could not install '@oresoftware/ores', please check your permissions to install global npm packages.";
3636
exit 1;
3737
}
3838
fi
@@ -41,7 +41,7 @@ project_root="$(ores_get_project_root "$0")";
4141
npm_local_bin="${project_root}/node_modules/.bin";
4242

4343

44-
if [ "$use_local" == "yes" ]; then
44+
if [[ "$use_local" == "yes" ]]; then
4545
if false; then
4646
echo "$nlu_name NLU is addding local 'node_modules/.bin' executables to the PATH.";
4747
echo "To not add local command line tools to the PATH, use the --no-local option.";
@@ -53,18 +53,18 @@ if false; then
5353
echo "$nlu_name NLU is using NPM version => $(npm --version)";
5454
fi
5555

56-
if [ "$first_arg" == "init" ]; then
56+
if [[ "$first_arg" == "init" ]]; then
5757

5858
shift 1;
5959
node "${project_root}/dist/commands/init" "$@";
6060

61-
elif [ "$first_arg" == "ls" ]; then
61+
62+
elif [[ "$first_arg" == "ls" ]]; then
6263

6364
shift 1;
6465
node "${project_root}/dist/commands/ls" "$@";
6566

66-
elif [ "$first_arg" == "install" ] || [ "$first_arg" == "i" ] ; then
67-
67+
elif [[ "$first_arg" == "install" ]] || [[ "$first_arg" == "i" ]] ; then
6868

6969
npm i -s "$@" || {
7070
echo "npm install command failed.";
@@ -73,23 +73,23 @@ elif [ "$first_arg" == "install" ] || [ "$first_arg" == "i" ] ; then
7373

7474
nlu run --install-main
7575

76-
elif [ "$first_arg" == "config" ]; then
76+
elif [[ "$first_arg" == "config" ]]; then
7777

7878
shift 1;
7979
mkdir -p "$HOME/.nlu/global"
8080
node "${project_root}/dist/commands/config" "$@";
8181

82-
elif [ "$first_arg" == "add" ]; then
82+
elif [[ "$first_arg" == "add" ]]; then
8383

8484
shift 1;
8585
node "${project_root}/dist/commands/add" "$@";
8686

87-
elif [ "$first_arg" == "run" ]; then
87+
elif [[ "$first_arg" == "run" ]]; then
8888

8989
shift 1;
9090
node "${project_root}/dist/commands/run" "$@";
9191

92-
elif [ "$first_arg" == "update" ]; then
92+
elif [[ "$first_arg" == "update" ]]; then
9393

9494
shift 1;
9595
echo "$nlu_name 'nlu update' is not implemented.";

lib/commands/run/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import * as fs from 'fs';
1010

1111
//npm
1212
import chalk from 'chalk';
13+
1314
const dashdash = require('dashdash');
1415
import async = require('async');
1516
import residence = require('residence');
17+
1618
const cwd = process.cwd();
1719
let root = residence.findProjectRoot(cwd);
1820
const treeify = require('treeify');
@@ -108,12 +110,14 @@ if (opts.config) {
108110
}
109111
else {
110112
nluConfigRoot = residence.findRootDir(cwd, '.nlu.json');
113+
111114
}
112115

113116
if (!nluConfigRoot) {
114117
nluConfigRoot = cwd;
115118
}
116119

120+
117121
let pkg, conf: NluConf;
118122

119123
let hasNLUJSONFile = false;
@@ -285,6 +289,7 @@ if (opts.dry_run) {
285289
// when we search for projects, we ignore any projects where package.json name is "mainProjectName"
286290
const mainDep = map[mainProjectName] = {
287291
name: mainProjectName,
292+
288293
bin: null as any, // conf.bin ?
289294
hasNLUJSONFile,
290295
isMainProject: true,
@@ -301,9 +306,9 @@ async.autoInject({
301306

302307
const nm = path.resolve(root + '/node_modules');
303308
const keys = opts.production ? productionDepsKeys : allDepsKeys;
304-
309+
305310
determineIfReinstallIsNeeded(nm, mainDep, keys, opts, (err, val) => {
306-
311+
307312
if (err) {
308313
return cb(err);
309314
}

lib/find-projects.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ export const makeFindProject = function (mainProjectName: string, totalList: Map
157157
return path.resolve(dir, item);
158158
});
159159

160+
160161
let deps: Array<string>, npmlinkup: NLUDotJSON, hasNLUJSONFile = false;
161162

162163
try {
@@ -231,6 +232,7 @@ export const makeFindProject = function (mainProjectName: string, totalList: Map
231232
return cb(null);
232233
}
233234

235+
234236
let pkg: PkgJSON, linkable = null;
235237

236238
try {
@@ -259,6 +261,7 @@ export const makeFindProject = function (mainProjectName: string, totalList: Map
259261
}
260262

261263

264+
262265
if (npmlinkup.linkable === false) {
263266
log.warn(`Skipping project at dir "${dirname}" because 'linkable' was set to false.`);
264267
return cb(null);
@@ -290,15 +293,18 @@ export const makeFindProject = function (mainProjectName: string, totalList: Map
290293
linkToItself: Boolean(npmlinkup.linkToItself),
291294
runInstall: Boolean(npmlinkup.alwaysReinstall),
292295
path: dirname,
296+
293297
deps: deps,
294298
package: pkg
299+
295300
};
296301

297302
const nm = path.resolve(dirname + '/node_modules');
298303
const keys = opts.production ? getProdKeys(pkg) : getDevKeys(pkg);
299304

300305
async.autoInject({
301306

307+
302308
addToSearchRoots(cb: EVCb<any>) {
303309

304310
const searchRoots = getSearchRootsFromNluConf(npmlinkup);

lib/run-link.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,16 @@ export const runNPMLink = (map: NluMap, opts: any, cb: EVCb<null>) => {
101101
if (opts.umbrella && dep.isMainProject) {
102102
return [];
103103
}
104-
104+
105105
return deps.filter(d => {
106+
106107
if (!map[d]) {
107108
log.warning('Map for key => "' + d + '" is not defined.');
108109
return false;
109110
}
110111
return map[d] && map[d].isLinked;
111112
})
113+
112114
.map((d: string) => {
113115

114116
const path = map[d].path;
@@ -120,7 +122,7 @@ export const runNPMLink = (map: NluMap, opts: any, cb: EVCb<null>) => {
120122
});
121123

122124
};
123-
125+
124126
const getBinMap = (bin: string | BinFieldObject, path: string, name: string) => {
125127

126128
if (!bin) {
@@ -225,6 +227,7 @@ export const runNPMLink = (map: NluMap, opts: any, cb: EVCb<null>) => {
225227
log.info(`Processing dep with name => '${chalk.bold(dep.name)}'.`);
226228
}
227229

230+
228231
const nm = path.resolve(dep.path + '/node_modules');
229232

230233
determineIfReinstallIsNeeded(nm, dep, getDevKeys(dep.package), opts, (err, val) => {
@@ -301,6 +304,7 @@ export const runNPMLink = (map: NluMap, opts: any, cb: EVCb<null>) => {
301304
log.info(`Running this command for "${chalk.bold(dep.name)}" => '${chalk.blueBright(cmd)}'.`);
302305
}
303306

307+
304308
const k = cp.spawn('bash', [], {
305309
env: Object.assign({}, process.env, {
306310
NPM_LINK_UP: 'yes'
@@ -339,6 +343,7 @@ export const runNPMLink = (map: NluMap, opts: any, cb: EVCb<null>) => {
339343
dep: dep,
340344
error: stderr
341345
});
346+
342347
});
343348

344349
});

lib/utils.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const globalConfigFilePath = path.resolve(process.env.HOME + '/.nlu/globa
2020

2121
export const validateConfigFile = (data: NluConf) => {
2222

23+
2324
try {
2425
const ajv = new Ajv({allErrors: false}); // options can be passed, e.g. {allErrors: true}
2526
const validate = ajv.compile(schema);
@@ -106,6 +107,7 @@ export const getDevKeys = (pkg: PkgJSON) => {
106107
.concat(Object.keys(pkg.optionalDependencies || {}));
107108
};
108109

110+
109111
export const validateOptions = (opts: any) => {
110112

111113
try {
@@ -121,13 +123,15 @@ export const validateOptions = (opts: any) => {
121123

122124
};
123125

126+
124127
export const mapConfigObject = (obj: any) => {
125128
return Object.keys(obj).reduce((a, b) => {
126129
const key = String(b).replace(/[^a-zA-z]+/g, '_').toLowerCase();
127130
return (a[key] = obj[b], a);
128131
}, {} as any);
129132
};
130133

134+
131135
const checkPackages = (dep: NluMapItem, m: Map<string, string>, sym: Set<string>): boolean => {
132136

133137
const d = dep.package.dependencies || {};
@@ -192,6 +196,7 @@ export const determineIfReinstallIsNeeded = (nodeModulesPath: string, dep: NluMa
192196
return process.nextTick(cb);
193197
}
194198

199+
195200
fs.readdir(nodeModulesPath, (err, originalItemsInNodeModules) => {
196201

197202
if (err || !Array.isArray(originalItemsInNodeModules)) {
@@ -208,6 +213,7 @@ export const determineIfReinstallIsNeeded = (nodeModulesPath: string, dep: NluMa
208213
return !String(v).startsWith('@') && String(v) !== '.bin';
209214
});
210215

216+
211217
const totalValid = new Set(topLevel.slice(0));
212218

213219
const processFolder = (name: string, folder: string, cb: EVCb<null>) => {
@@ -309,7 +315,7 @@ export const determineIfReinstallIsNeeded = (nodeModulesPath: string, dep: NluMa
309315
if (err && result.install === true) {
310316
return cb(null, true);
311317
}
312-
318+
313319
if (err) {
314320
return cb(err, false);
315321
}
@@ -338,10 +344,11 @@ export const determineIfReinstallIsNeeded = (nodeModulesPath: string, dep: NluMa
338344
return cb(null, true);
339345
}
340346

347+
341348
if (checkPackages(dep, map, sym)) {
342349
return cb(null, true);
343350
}
344-
351+
345352
cb(null, false);
346353

347354
});

0 commit comments

Comments
 (0)