Skip to content

Commit

Permalink
🤷‍♂️ skipping actual git branch check, added NETLIFY_LOCAL_BRANCH whi…
Browse files Browse the repository at this point in the history
…ch will be used for cli context override #1
  • Loading branch information
8eecf0d2 committed Oct 16, 2018
1 parent 11c851c commit 2907298
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/ts/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const parseNetlifyConfig = (filename: string): Netlify.Config => {
}

const netlifyConfig = toml.parse(fs.readFileSync(path.join(process.cwd(), netlifyFileOption), "utf8"));
const currentBranch = gitBranch.sync();
const currentBranch = process.env.NETLIFY_LOCAL_BRANCH || gitBranch.sync();

if(netlifyConfig.context && netlifyConfig.context[currentBranch]) {
netlifyConfig.build = {
Expand Down
10 changes: 5 additions & 5 deletions test/toml/netlify-example-1.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
functions = "default-functions"
command = "default-command"

[context.master]
base = "master-base"
publish = "master-publish"
functions = "master-functions"
command = "master-command"
[context.default]
base = "default-base"
publish = "default-publish"
functions = "default-functions"
command = "default-command"

[context.develop]
base = "develop-base"
Expand Down
13 changes: 6 additions & 7 deletions test/ts/config.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import { describe, it } from "mocha";
import * as assert from "assert";

import * as gitBranch from "git-branch";

import { parseNetlifyConfig, parseWebpackConfig } from "../../src/ts";

process.env.NETLIFY_LOCAL_BRANCH = "default"

describe('Config', function() {
describe('parseNetlifyConfig', function() {
it('should throw when not found', function() {
assert.throws(() => parseNetlifyConfig("test/toml/netlify.toml" + Math.random()));
});
it('should override build with context', function() {
const currentBranch = gitBranch.sync() || process.env.TRAVIS_BRANCH;
const netlifyConfig = parseNetlifyConfig("test/toml/netlify-example-1.toml");

assert.equal(netlifyConfig.build.base, `${currentBranch}-base`);
assert.equal(netlifyConfig.build.publish, `${currentBranch}-publish`);
assert.equal(netlifyConfig.build.functions, `${currentBranch}-functions`);
assert.equal(netlifyConfig.build.command, `${currentBranch}-command`);
assert.equal(netlifyConfig.build.base, `default-base`);
assert.equal(netlifyConfig.build.publish, `default-publish`);
assert.equal(netlifyConfig.build.functions, `default-functions`);
assert.equal(netlifyConfig.build.command, `default-command`);
});
});
});

0 comments on commit 2907298

Please sign in to comment.