Skip to content

Commit

Permalink
Merge branch 'release/0.3.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
8eecf0d2 committed Oct 16, 2018
2 parents b7375f4 + 2c39161 commit 4a2035c
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 10 deletions.
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "netlify-local",
"version": "0.3.1",
"version": "0.3.2",
"description": "Local Netlify service emulation",
"main": ".dist/index.js",
"types": ".dist/index.d.ts",
Expand All @@ -14,15 +14,21 @@
"watch": "tsc --project ./tsconfig.json --watch",
"build": "tsc --project ./tsconfig.json",
"pretest": "yarn run build",
"test": "echo \"Success: no test specified\" && exit 0"
"test": "ts-mocha test/**/*.ts",
"test:now": "ts-mocha test/**/*.ts"
},
"devDependencies": {
"@types/assert": "^1.4.0",
"@types/body-parser": "^1.17.0",
"@types/express": "^4.16.0",
"@types/git-branch": "^2.0.0",
"@types/jsonwebtoken": "^7.2.8",
"@types/mocha": "^5.2.5",
"@types/node": "^10.11.7",
"@types/webpack": "^4.4.16",
"assert": "^1.4.1",
"mocha": "^5.2.0",
"ts-mocha": "^2.0.0",
"typescript": "^3.1.3"
},
"dependencies": {
Expand Down
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
6 changes: 3 additions & 3 deletions src/ts/netlify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ export namespace Netlify {
functions: string;
command: string;
}
context: any;
redirects: Netlify.Redirect[];
headers: Netlify.Headers[];
context?: any;
redirects?: Netlify.Redirect[];
headers?: Netlify.Headers[];
}
export interface Redirect {
from: string;
Expand Down
17 changes: 17 additions & 0 deletions test/toml/netlify-example-1.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[build]
base = "default-base"
publish = "default-publish"
functions = "default-functions"
command = "default-command"

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

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

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 netlifyConfig = parseNetlifyConfig("test/toml/netlify-example-1.toml");

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`);
});
});
});
Loading

0 comments on commit 4a2035c

Please sign in to comment.