Skip to content

Commit

Permalink
Support more publish config via asini.json (#52)
Browse files Browse the repository at this point in the history
The following may now be durably configured in asini.json.

- skipGit
- skipNpm
  • Loading branch information
gigabo committed Nov 10, 2016
1 parent b762923 commit c48b1f4
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ When run with this flag, `publish` will publish to npm without running any of th

> Only publish to npm; skip committing, tagging, and pushing git changes (this only affects publish).
This may be configured in asini.json via `skipGit` or `command.publish.skipGit`.

#### --skip-npm

```sh
Expand All @@ -245,6 +247,8 @@ dependencies, without committing, tagging, pushing or publishing.

> Only update versions and dependencies; don't actually publish (this only affects publish).
This may be configured in asini.json via `skipNpm` or `command.publish.skipNpm`.

#### --force-publish [packages]

```sh
Expand Down
15 changes: 10 additions & 5 deletions src/commands/PublishCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import { EOL } from "os";

export default class PublishCommand extends Command {
initialize(callback) {
const opts = this.getOptions();

// These can come in from asini.json or from flags on the command-line.
["skipNpm", "skipGit"].forEach((opt) => this[opt] = opts[opt]);

if (this.flags.canary) {
this.logger.info("Publishing canary build");
}
Expand Down Expand Up @@ -80,15 +85,15 @@ export default class PublishCommand extends Command {
}

this.updateUpdatedPackages();
if (!this.flags.skipGit) {
if (!this.skipGit) {
this.commitAndTagUpdates();
}
} catch (err) {
callback(err);
return;
}

if (this.flags.skipNpm) {
if (this.skipNpm) {
callback(null, true);
} else {
this.publishPackagesToNpm(callback);
Expand Down Expand Up @@ -118,7 +123,7 @@ export default class PublishCommand extends Command {
return;
}

if (!(this.flags.canary || this.flags.skipGit)) {
if (!(this.flags.canary || this.skipGit)) {
this.logger.info("Pushing tags to git...");
this.logger.newLine();
GitUtilities.pushWithTags(this.tags);
Expand Down Expand Up @@ -243,7 +248,7 @@ export default class PublishCommand extends Command {
updateVersionInAsiniJson() {
this.repository.asiniJson.version = this.masterVersion;
FileSystemUtilities.writeFileSync(this.repository.asiniJsonLocation, JSON.stringify(this.repository.asiniJson, null, " "));
if (!this.flags.skipGit) {
if (!this.skipGit) {
GitUtilities.addFile(this.repository.asiniJsonLocation);
}
}
Expand Down Expand Up @@ -271,7 +276,7 @@ export default class PublishCommand extends Command {
changedFiles.push(packageJsonLocation);
});

if (!(this.flags.canary || this.flags.skipGit)) {
if (!(this.flags.canary || this.skipGit)) {
changedFiles.forEach(GitUtilities.addFile);
}
}
Expand Down
55 changes: 55 additions & 0 deletions test/PublishCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,61 @@ describe("PublishCommand", () => {
});
});

/** =========================================================================
* NORMAL - SKIP GIT AND SKIP NPM via asini.json
* ======================================================================= */

describe("normal mode with skipGit and skipNpm via asini.json", () => {
let testDir;

beforeEach((done) => {
testDir = initFixture("PublishCommand/skip", done);
});

it("should update versions but not push changes or publish", (done) => {
const publishCommand = new PublishCommand([], {});

publishCommand.runValidations();
publishCommand.runPreparations();

assertStubbedCalls([
[ChildProcessUtilities, "execSync", {}, [
{ args: ["git tag"] }
]],
[PromptUtilities, "select", { valueCallback: true }, [
{ args: ["Select a new version (currently 1.0.0)"], returns: "1.0.1" }
]],
[PromptUtilities, "confirm", { valueCallback: true }, [
{ args: ["Are you sure you want to publish the above changes?"], returns: true }
]],
]);

publishCommand.runCommand(exitWithCode(0, (err) => {
if (err) return done(err);

try {
assert.ok(!pathExists.sync(path.join(testDir, "asini-debug.log")));
assert.equal(require(path.join(testDir, "asini.json")).version, "1.0.1");

assert.equal(require(path.join(testDir, "packages/package-1/package.json")).version, "1.0.1");
assert.equal(require(path.join(testDir, "packages/package-2/package.json")).version, "1.0.1");
assert.equal(require(path.join(testDir, "packages/package-3/package.json")).version, "1.0.1");
assert.equal(require(path.join(testDir, "packages/package-4/package.json")).version, "1.0.1");

assert.equal(require(path.join(testDir, "packages/package-2/package.json")).dependencies["package-1"], "^1.0.1");
assert.equal(require(path.join(testDir, "packages/package-3/package.json")).devDependencies["package-2"], "^1.0.1");
assert.equal(require(path.join(testDir, "packages/package-4/package.json")).dependencies["package-1"], "^0.0.0");

done();
} catch (err) {
done(err);
}
}));
});
});



/** =========================================================================
* NORMAL - NPM TAG
* ======================================================================= */
Expand Down
11 changes: 11 additions & 0 deletions test/fixtures/PublishCommand/skip/asini.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"asini": "__TEST_VERSION__",
"version": "1.0.0",
"command": {
"publish": {
"//": "These options may appear at the top-level or within publish. Testing both.",
"skipNpm": true
}
},
"skipGit": true
}
3 changes: 3 additions & 0 deletions test/fixtures/PublishCommand/skip/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "independent"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "package-1",
"version": "1.0.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "package-2",
"version": "1.0.0",
"dependencies": {
"package-1": "^1.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "package-3",
"version": "1.0.0",
"devDependencies": {
"package-2": "^1.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "package-4",
"version": "1.0.0",
"dependencies": {
"package-1": "^0.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "package-5",
"dependencies": {
"package-1": "^1.0.0"
},
"private": true,
"version": "1.0.0"
}

0 comments on commit c48b1f4

Please sign in to comment.