Skip to content

Commit

Permalink
feat: reconfigure into two binaries
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
medikoo committed Nov 14, 2018
1 parent a07d144 commit 3abed15
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 75 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ You maintain many npm packages which depend on each other. When developing local

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.

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

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`)
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)
Expand All @@ -35,7 +35,7 @@ However when relying on [nvm](https://github.com/creationix/nvm), different npm

### CLI

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

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

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

#### `npm-cross-link install [...options]`
#### `npm-cross-link [...options]`

Installs and links all maintained dependencies of a project found at current working directory.
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)

Supports same options as `npm-cross-link install`
Supports same options as `npm-cross-link`

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

Updates all packages that are already installed at packages folder.

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

Supports same options as `npm-cross-link install`
Supports same options as `npm-cross-link`

### Configuration

Expand Down
42 changes: 42 additions & 0 deletions bin/npm-cross-link-update-all.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env node

"use strict";

Error.stackTraceLimit = Infinity;

process.on("unhandledRejection", reason => { throw reason; });

require("log4-nodejs")({ defaultNamespace: "npm-cross-link" });

const meta = require("../package");

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

const usage = `npm-cross-link-update-all v${ meta.version }
Usage: npm-cross-link-update-all [-h | --help] [--no-pull] [--push]
Ensures all packages in npm packages folder are properly installed and up to date
Options:
--pull Pull changes from remote
--push Push committed changes to remote
--help, -h Show this message
`;

if (argv.h || argv.help) {
process.stdout.write(usage);
return;
}

if (argv.v || argv.version) {
process.stdout.write(`${ meta.version }\n`);
return;
}

require("../lib/private/cli")("update-all", null, {
pull: argv.pull !== false,
push: argv.push !== false
});
39 changes: 23 additions & 16 deletions bin/npm-cross-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,30 @@ const meta = require("../package");

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

const [command, packageName] = argv._;
const [packageName] = argv._;

const usage = `npm-cross-link v${ meta.version }
Usage: npm-cross-link [-h | --help] [--no-pull] [--push] [<package-name>]
When <package-name> is provided, it is ensured it's installed and is up to date,
as located in npm packages folder
(there are no updates made to eventual project at current working directory)
When <package-name> is not provided then all dependencies of a project at
current working directory are ensured to be linked or installed
up to npm-cross-link installation rules
Options:
--pull Pull changes from remote
--push Push committed changes to remote
--help, -h Show this message
`;

const usage = require("../lib/private/cli/usage");
if (argv.h || argv.help) {
process.stdout.write(usage[command] || usage.main);
process.stdout.write(usage);
return;
}

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

if (!command) {
process.stderr.write(`Provide command name to install\n\n${ usage.main }`);
process.exit(1);
}

const supportedCommands = new Set(["install", "update-all"]);

if (!supportedCommands.has(command)) {
process.stderr.write(`${ command } is not a suppported command\n\n${ usage.main }`);
process.exit(1);
}

require("../lib/private/cli")(command, packageName, {
require("../lib/private/cli")("install", packageName, {
pull: argv.pull !== false,
push: argv.push !== false
});
52 changes: 0 additions & 52 deletions lib/private/cli/usage.js

This file was deleted.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"version": "2.0.0",
"author": "Mariusz Nowak <medyk@medikoo.com> (http://www.medikoo.com/)",
"bin": {
"npm-cross-link": "./bin/npm-cross-link.js"
"npm-cross-link": "./bin/npm-cross-link.js",
"npm-cross-link-update-all": "./bin/npm-cross-link-update-all.js"
},
"repository": "medikoo/npm-cross-link",
"dependencies": {
Expand Down

0 comments on commit 3abed15

Please sign in to comment.