Skip to content

Commit 3abed15

Browse files
committed
feat: reconfigure into two binaries
BREAKING CHANGE: `$ npm-cross-link install` now is represented by `$ npm-cross-link` `$ npm-cross-link update-all` now is represented by `$ npm-cross-link-update-all`
1 parent a07d144 commit 3abed15

File tree

5 files changed

+73
-75
lines changed

5 files changed

+73
-75
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ You maintain many npm packages which depend on each other. When developing local
1717

1818
Within [configuration](#configuration) you choose a folder (defaults to `~/npm-packages`) where maintained packages are placed, and predefine (at `packagesMeta`) a _package name_ to _repository url_ mappings of packages you maintain.
1919

20-
When running `npm-cross-link install <package-name>` following steps are pursued:
20+
When running `npm-cross-link <package-name>` following steps are pursued:
2121

2222
1. If repository is not setup, it is cloned into corresponding folder. Otherwise optionally changes from remote are pulled (`--pull`), and optionally committed changes can be pushed (`--push`)
2323
2. All maintained project dependencies (also `devDependencies`) are installed according to same flow. Those not maintained (not found in `packagesMeta`) are npm linked to global npm folder and ensured to be at latest version if one is supported, otherwise they're installed on spot but with its dependencies contained in dependency folder (not top level node_modules)
@@ -35,7 +35,7 @@ However when relying on [nvm](https://github.com/creationix/nvm), different npm
3535

3636
### CLI
3737

38-
#### `npm-cross-link install [...options] <package-name>`
38+
#### `npm-cross-link [...options] <package-name>`
3939

4040
Installs or updates indicated package (with its dependencies) at packages folder.
4141

@@ -46,20 +46,20 @@ _Note: This command doesn't interfere in any way with eventual project at curren
4646
- `--pull` - Pull eventual new updates from remote
4747
- `--push` - For all updated packages push eventually committed changes to remote
4848

49-
#### `npm-cross-link install [...options]`
49+
#### `npm-cross-link [...options]`
5050

5151
Installs and links all maintained dependencies of a project found at current working directory.
5252
Installation rules are same as for package install. Maintained packages are linked to its location, not maintained are linked to global npm folder (unless they do not refer to latest version, as then they're installed on spot)
5353

54-
Supports same options as `npm-cross-link install`
54+
Supports same options as `npm-cross-link`
5555

56-
#### `npm-cross-link update-all [...options]`
56+
#### `npm-cross-link-update-all [...options]`
5757

5858
Updates all packages that are already installed at packages folder.
5959

6060
_Note: This command doesn't interfere in any way with eventual project at current working directory._
6161

62-
Supports same options as `npm-cross-link install`
62+
Supports same options as `npm-cross-link`
6363

6464
### Configuration
6565

bin/npm-cross-link-update-all.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env node
2+
3+
"use strict";
4+
5+
Error.stackTraceLimit = Infinity;
6+
7+
process.on("unhandledRejection", reason => { throw reason; });
8+
9+
require("log4-nodejs")({ defaultNamespace: "npm-cross-link" });
10+
11+
const meta = require("../package");
12+
13+
const argv = require("minimist")(process.argv.slice(2), { boolean: ["pull", "push"] });
14+
15+
const usage = `npm-cross-link-update-all v${ meta.version }
16+
17+
Usage: npm-cross-link-update-all [-h | --help] [--no-pull] [--push]
18+
19+
Ensures all packages in npm packages folder are properly installed and up to date
20+
21+
Options:
22+
23+
--pull Pull changes from remote
24+
--push Push committed changes to remote
25+
--help, -h Show this message
26+
27+
`;
28+
29+
if (argv.h || argv.help) {
30+
process.stdout.write(usage);
31+
return;
32+
}
33+
34+
if (argv.v || argv.version) {
35+
process.stdout.write(`${ meta.version }\n`);
36+
return;
37+
}
38+
39+
require("../lib/private/cli")("update-all", null, {
40+
pull: argv.pull !== false,
41+
push: argv.push !== false
42+
});

bin/npm-cross-link.js

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,30 @@ const meta = require("../package");
1212

1313
const argv = require("minimist")(process.argv.slice(2), { boolean: ["pull", "push"] });
1414

15-
const [command, packageName] = argv._;
15+
const [packageName] = argv._;
16+
17+
const usage = `npm-cross-link v${ meta.version }
18+
19+
Usage: npm-cross-link [-h | --help] [--no-pull] [--push] [<package-name>]
20+
21+
When <package-name> is provided, it is ensured it's installed and is up to date,
22+
as located in npm packages folder
23+
(there are no updates made to eventual project at current working directory)
24+
25+
When <package-name> is not provided then all dependencies of a project at
26+
current working directory are ensured to be linked or installed
27+
up to npm-cross-link installation rules
28+
29+
Options:
30+
31+
--pull Pull changes from remote
32+
--push Push committed changes to remote
33+
--help, -h Show this message
34+
35+
`;
1636

17-
const usage = require("../lib/private/cli/usage");
1837
if (argv.h || argv.help) {
19-
process.stdout.write(usage[command] || usage.main);
38+
process.stdout.write(usage);
2039
return;
2140
}
2241

@@ -25,19 +44,7 @@ if (argv.v || argv.version) {
2544
return;
2645
}
2746

28-
if (!command) {
29-
process.stderr.write(`Provide command name to install\n\n${ usage.main }`);
30-
process.exit(1);
31-
}
32-
33-
const supportedCommands = new Set(["install", "update-all"]);
34-
35-
if (!supportedCommands.has(command)) {
36-
process.stderr.write(`${ command } is not a suppported command\n\n${ usage.main }`);
37-
process.exit(1);
38-
}
39-
40-
require("../lib/private/cli")(command, packageName, {
47+
require("../lib/private/cli")("install", packageName, {
4148
pull: argv.pull !== false,
4249
push: argv.push !== false
4350
});

lib/private/cli/usage.js

Lines changed: 0 additions & 52 deletions
This file was deleted.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"version": "2.0.0",
44
"author": "Mariusz Nowak <[email protected]> (http://www.medikoo.com/)",
55
"bin": {
6-
"npm-cross-link": "./bin/npm-cross-link.js"
6+
"npm-cross-link": "./bin/npm-cross-link.js",
7+
"npm-cross-link-update-all": "./bin/npm-cross-link-update-all.js"
78
},
89
"repository": "medikoo/npm-cross-link",
910
"dependencies": {

0 commit comments

Comments
 (0)