Skip to content

Commit c8dddaa

Browse files
authored
Oleg/feature/root (#82)
* adding tarball stuff * ores/auto-commit => 'set' * 0.1.322 * ores/auto-commit => 'set' * 0.1.323 * ores/auto-commit => 'set' * foop * installed set * works * roots * changes
1 parent a8d2c32 commit c8dddaa

File tree

20 files changed

+558
-340
lines changed

20 files changed

+558
-340
lines changed

.nlu.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"/.git/"
1414
],
1515
"list": [
16+
"@oresoftware/envstr",
1617
"@oresoftware/shell",
1718
"prepend-transform",
1819
"residence",

.npmignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@ media
1111
.vscode
1212
scripts
1313
docs
14+
lib
1415

1516
### matching files
1617
*.md
1718
*.txt
1819
*.log
1920
tsconfig*.json
2021
*.yml
22+
Dockerfile*
23+
2124

2225
### files
26+
.nlu.json
2327
.gitignore
2428
.npmignore
2529
.npmrc

assets/postinstall.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set -e;
44

5-
if [ "$skip_postinstall" == "yes" ]; then
5+
if [[ "$skip_postinstall" == "yes" ]]; then
66
echo "skipping nlu postinstall routine.";
77
exit 0;
88
fi
@@ -44,10 +44,13 @@ mkdir -p "$HOME/.oresoftware/bash" && {
4444
}
4545

4646
(
47+
48+
if [[ -f "node_modules/@oresoftware/shell/assets/shell.sh" ]]; then
4749
cat "node_modules/@oresoftware/shell/assets/shell.sh" > "$HOME/.oresoftware/shell.sh" && {
4850
echo "Successfully copied @oresoftware/shell/assets/shell.sh to $HOME/.oresoftware/shell.sh";
4951
exit 0;
5052
}
53+
fi
5154

5255
curl -H 'Cache-Control: no-cache' \
5356
"https://raw.githubusercontent.com/oresoftware/shell/master/assets/shell.sh?$(date +%s)" \

cli/index.sh

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
echo;
55
my_args=( "$@" );
6-
first_arg="$1"
6+
first_arg="$1";
7+
shift 1;
78

89
export nlu_name="[nlu/npm-link-up]"
910

@@ -25,7 +26,6 @@ if nlu_match_arg "--no-use-local" "${my_args[@]}"; then
2526
use_local="nope"
2627
fi
2728

28-
2929
if nlu_match_arg "--no-local" "${my_args[@]}"; then
3030
use_local="nope"
3131
fi
@@ -39,12 +39,12 @@ fi
3939

4040
project_root="$(ores_get_project_root "$0")";
4141
npm_local_bin="${project_root}/node_modules/.bin";
42-
42+
commands="${project_root}/dist/commands"
4343

4444
if [[ "$use_local" == "yes" ]]; then
4545
if false; then
46-
echo "$nlu_name NLU is addding local 'node_modules/.bin' executables to the PATH.";
47-
echo "To not add local command line tools to the PATH, use the --no-local option.";
46+
echo "$nlu_name NLU is addding local 'node_modules/.bin' executables to the PATH.";
47+
echo "To not add local command line tools to the PATH, use the --no-local option.";
4848
fi
4949
export PATH="${npm_local_bin}:${PATH}";
5050
fi
@@ -55,50 +55,43 @@ fi
5555

5656
if [[ "$first_arg" == "init" ]]; then
5757

58-
shift 1;
59-
node "${project_root}/dist/commands/init" "$@";
60-
58+
node "$commands/init" "$@";
6159

6260
elif [[ "$first_arg" == "ls" ]]; then
6361

64-
shift 1;
65-
node "${project_root}/dist/commands/ls" "$@";
62+
node "$commands/ls" "$@";
6663

6764
elif [[ "$first_arg" == "install" ]] || [[ "$first_arg" == "i" ]] ; then
6865

69-
npm i -s "$@" || {
66+
npm i -s || {
7067
echo "npm install command failed.";
7168
exit 1;
7269
}
7370

74-
nlu run --install-main
71+
nlu run --install-main "$@"
7572

7673
elif [[ "$first_arg" == "config" ]]; then
7774

78-
shift 1;
7975
mkdir -p "$HOME/.nlu/global"
80-
node "${project_root}/dist/commands/config" "$@";
76+
node "$commands/config" "$@";
8177

8278
elif [[ "$first_arg" == "add" ]]; then
8379

84-
shift 1;
85-
node "${project_root}/dist/commands/add" "$@";
80+
node "$commands/add" "$@";
8681

8782
elif [[ "$first_arg" == "run" ]]; then
8883

89-
shift 1;
90-
node "${project_root}/dist/commands/run" "$@";
84+
node "$commands/run" "$@";
9185

9286
elif [[ "$first_arg" == "update" ]]; then
9387

94-
shift 1;
9588
echo "$nlu_name 'nlu update' is not implemented.";
9689
echo "$nlu_name You should manually update your .nlu.json files.";
9790
exit 1;
9891

9992
else
10093

101-
node "${project_root}/dist/commands/basic" "$@";
94+
node "$commands/basic" "${my_args[@]}";
10295

10396
fi
10497

lib/commands/add/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ async.autoInject({
224224
let cleanMap;
225225

226226
try {
227-
cleanMap = getCleanMap(mainProjectName, getMatchingProjects);
227+
cleanMap = getCleanMap(mainProjectName, getMatchingProjects, opts);
228228
}
229229
catch (err) {
230230
return process.nextTick(cb, err);

lib/commands/basic/cmd-line-opts.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ export default [
4444
default: false,
4545
hidden: true
4646
},
47+
48+
{
49+
names: ['json'],
50+
type: 'bool',
51+
help: 'Write stdout info as JSON (use json-stdio to parse it).',
52+
default: false,
53+
hidden: true,
54+
env: 'nlu_setting_json'
55+
},
4756

4857
{
4958
names: ['bash-completion', 'completion'],

lib/commands/basic/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import addOpts from '../add/cmd-line-opts';
1212
import initOpts from '../init/cmd-line-opts';
1313
import runOpts from '../run/cmd-line-opts';
1414
import * as nluUtils from '../../utils';
15+
import * as stdio from 'json-stdio';
1516

1617
process.once('exit', code => {
1718
log.info('Exiting with code:', code, '\n');
@@ -41,7 +42,13 @@ try {
4142
}
4243

4344
if (opts.version) {
44-
console.log(npmLinkUpPkg.version);
45+
if(opts.json){
46+
stdio.log(npmLinkUpPkg.version);
47+
}
48+
else{
49+
console.log(npmLinkUpPkg.version);
50+
}
51+
4552
process.exit(0);
4653
}
4754

lib/commands/run/index.ts

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ if (opts.help) {
7676
process.exit(0);
7777
}
7878

79-
8079
try {
8180
globalConf = require(globalConfigFilePath);
8281
}
@@ -93,11 +92,10 @@ if (Array.isArray(globalConf)) {
9392
globalConf = {};
9493
}
9594

96-
const {nluFilePath, nluConfigRoot} = handleConfigCLIOpt(cwd,opts);
95+
const {nluFilePath, nluConfigRoot} = handleConfigCLIOpt(cwd, opts);
9796

9897
let pkg, conf: NluConf, hasNLUJSONFile = false;
9998

100-
10199
try {
102100
conf = require(nluFilePath);
103101
opts.umbrella = opts.umbrella || Boolean(conf.umbrella);
@@ -237,7 +235,7 @@ const originalList = list.slice(0);
237235
if (!list.includes(mainProjectName)) {
238236
// always include the very project's name
239237
if (!opts.umbrella) {
240-
list.push(mainProjectName);
238+
list.push(mainProjectName); // TODO this might be causing the project to always link to itself?
241239
}
242240
}
243241

@@ -263,17 +261,19 @@ if (opts.dry_run) {
263261

264262
// add the main project to the map
265263
// when we search for projects, we ignore any projects where package.json name is "mainProjectName"
266-
const mainDep = map[mainProjectName] = {
264+
const mainDep = map[root] = {
267265
name: mainProjectName,
268-
269266
bin: null as any, // conf.bin ?
270267
hasNLUJSONFile,
271268
isMainProject: true,
272269
linkToItself: conf.linkToItself,
273270
runInstall: conf.alwaysReinstall,
274271
path: root,
275272
deps: list,
276-
package: pkg
273+
package: pkg,
274+
searchRoots: null as Array<string>,
275+
installedSet: new Set(),
276+
linkedSet: {}
277277
};
278278

279279
async.autoInject({
@@ -328,7 +328,15 @@ async.autoInject({
328328

329329
mapSearchRoots(npmCacheClean: any, cb: EVCb<any>) {
330330
opts.verbosity > 3 && log.info(`Mapping original search roots from your root project's "searchRoots" property.`);
331-
mapPaths(searchRoots, nluConfigRoot, cb);
331+
mapPaths(searchRoots, nluConfigRoot, (err, roots) => {
332+
333+
if (err) {
334+
return cb(err);
335+
}
336+
337+
mainDep.searchRoots = roots.slice(0);
338+
cb(err, roots);
339+
});
332340
},
333341

334342
findItems(mapSearchRoots: Array<string>, cb: EVCb<any>) {
@@ -353,9 +361,7 @@ async.autoInject({
353361
const findProject = makeFindProject(mainProjectName, totalList, map, ignore, opts, status, conf);
354362

355363
searchRoots.forEach(sr => {
356-
q.push(cb => {
357-
findProject(sr, cb);
358-
});
364+
q.push(cb => findProject(sr, cb));
359365
});
360366

361367
if (q.idle()) {
@@ -389,12 +395,12 @@ async.autoInject({
389395
return !map[v];
390396
});
391397

392-
if (unfound.length > 0) {
398+
if (false && unfound.length > 0) {
393399
log.warn(`The following packages could ${chalk.bold('not')} be located:`);
394-
for(let i of unfound.keys()){
395-
log.warn(chalk.bold(String(i+1), chalk.bold.green(unfound[i])));
400+
for (let i of unfound.keys()) {
401+
log.warn(chalk.bold(String(i + 1), chalk.bold.green(unfound[i])));
396402
}
397-
403+
398404
if (!opts.allow_missing) {
399405
console.error();
400406
log.warn('The following paths (and their subdirectories) were searched:');
@@ -415,7 +421,7 @@ async.autoInject({
415421
cleanMap = getCleanMapOfOnlyPackagesWithNluJSONFiles(mainProjectName, map);
416422
}
417423
else {
418-
cleanMap = getCleanMap(mainProjectName, map);
424+
cleanMap = getCleanMap(mainDep, map, opts);
419425
}
420426
}
421427
catch (err) {
@@ -451,18 +457,20 @@ async.autoInject({
451457
const cleanMap = results.runUtility;
452458

453459
if (cleanMap && typeof cleanMap === 'object') {
454-
455-
const treeObj = createTree(cleanMap, mainProjectName, originalList, opts);
460+
461+
const treeObj = createTree(cleanMap, mainDep.path, mainDep, opts);
462+
// const treeObj = createTree(cleanMap, mainProjectName, originalList, opts);
456463
const treeString = treeify.asTree(treeObj, true);
457-
const formattedStr = String(treeString).split('\n').map(function (line) {
458-
return '\t' + line;
459-
});
464+
const formattedStr = [''].concat(String(treeString).split('\n')).map(function (line) {
465+
return ' look here: \t' + line;
466+
}).concat('');
460467

461468
if (opts.verbosity > 1) {
469+
console.log();
462470
log.info(chalk.cyan.bold('NPM-Link-Up results as a visual:'), '\n');
463-
console.log('^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^');
471+
// console.log('^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^');
464472
console.log(chalk.white(formattedStr.join('\n')));
465-
console.log('^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^');
473+
// console.log('^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^');
466474
}
467475
}
468476
else {

0 commit comments

Comments
 (0)