Skip to content

Commit 4e55bf1

Browse files
authored
Merge pull request #90 from electricimp/develop
Release 3.3.0: Support Git Local as a file reader
2 parents 1962ed8 + 5dd4e19 commit 4e55bf1

15 files changed

+601
-38
lines changed

Diff for: README.md

+70-19
Large diffs are not rendered by default.

Diff for: package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Builder",
3-
"version": "3.2.0",
3+
"version": "3.3.0",
44
"description": "Builder Language Implementation",
55
"main": "src/index.js",
66
"bin": {
@@ -10,6 +10,7 @@
1010
"test": "jasmine",
1111
"test:bitbucket-server": "node ./spec/BitbucketServerExecutor.js",
1212
"test:azure-repos": "node ./spec/AzureReposExecutor.js",
13+
"test:git-local": "node ./spec/GitLocalExecutor.js",
1314
"build": "src/cli.js input"
1415
},
1516
"repository": {

Diff for: spec/GitLocal/GitLocalReader.spec.js

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// MIT License
2+
//
3+
// Copyright 2020 Electric Imp
4+
//
5+
// SPDX-License-Identifier: MIT
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files (the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions:
13+
//
14+
// The above copyright notice and this permission notice shall be
15+
// included in all copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
20+
// EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
21+
// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22+
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23+
// OTHER DEALINGS IN THE SOFTWARE.
24+
25+
'use strict';
26+
27+
const fs = require('fs');
28+
const Log = require('log');
29+
const eol = require('eol');
30+
const path = require('path');
31+
const GitLocalReader = require('../../src/Readers/GitLocalReader');
32+
33+
describe('GitLocalReader', () => {
34+
let reader;
35+
36+
beforeEach(function() {
37+
if (!process.env.SPEC_GIT_LOCAL_REPO_PATH) {
38+
fail('Some of the required environment variables are not set');
39+
return;
40+
}
41+
42+
reader = new GitLocalReader();
43+
44+
// @see https://www.npmjs.com/package/log#log-levels
45+
reader.logger = new Log(process.env.SPEC_LOGLEVEL || 'error');
46+
});
47+
48+
it('should read sample#1 from local git repo', () => {
49+
const expectedContent = eol.lf(fs.readFileSync(__dirname + '/../fixtures/sample-1/input.nut', 'utf-8'));
50+
let resultContent;
51+
52+
resultContent = reader.read(`git-local:${process.env.SPEC_GIT_LOCAL_REPO_PATH}/spec/fixtures/sample-1/input.nut`);
53+
expect(resultContent).toEqual(expectedContent);
54+
55+
resultContent = reader.read(`git-local:${process.env.SPEC_GIT_LOCAL_REPO_PATH}/./spec/../spec/fixtures/sample-1/input.nut`);
56+
expect(resultContent).toEqual(expectedContent);
57+
58+
resultContent = reader.read(`git-local:${process.env.SPEC_GIT_LOCAL_REPO_PATH}/./spec/../spec/fixtures/sample-1/input.nut@master`);
59+
expect(resultContent).toEqual(expectedContent);
60+
});
61+
62+
it('should read sample#1 from local git repo with refs', () => {
63+
const expectedContent = eol.lf(fs.readFileSync(__dirname + '/../fixtures/sample-1/input.nut', 'utf-8'));
64+
let resultContent;
65+
66+
resultContent = reader.read(`git-local:${process.env.SPEC_GIT_LOCAL_REPO_PATH}/spec/fixtures/sample-1/input.nut@master`);
67+
expect(resultContent).toEqual(expectedContent);
68+
69+
resultContent = reader.read(`git-local:${process.env.SPEC_GIT_LOCAL_REPO_PATH}/spec/fixtures/sample-1/input.nut@v0.1.0`);
70+
expect(resultContent).toEqual(expectedContent);
71+
72+
resultContent = reader.read(`git-local:${process.env.SPEC_GIT_LOCAL_REPO_PATH}/spec/fixtures/sample-1/input.nut@20454c4dcb9621252d248d8a833ceb1ca79c3730`);
73+
expect(resultContent).toEqual(expectedContent);
74+
});
75+
});

Diff for: spec/GitLocal/dependencies.spec.js

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// MIT License
2+
//
3+
// Copyright 2020 Electric Imp
4+
//
5+
// SPDX-License-Identifier: MIT
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files (the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions:
13+
//
14+
// The above copyright notice and this permission notice shall be
15+
// included in all copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
20+
// EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
21+
// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22+
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23+
// OTHER DEALINGS IN THE SOFTWARE.
24+
25+
'use strict';
26+
27+
require('jasmine-expect');
28+
29+
const fs = require('fs');
30+
const path = require('path');
31+
const eol = require('eol');
32+
const Log = require('log');
33+
const Builder = require('../../src/');
34+
35+
const dependenciesFile = path.join(process.cwd(), 'save_dependencies.json');
36+
37+
describe('Machine', () => {
38+
let machine;
39+
40+
beforeEach(function () {
41+
if (!process.env.SPEC_GIT_LOCAL_REPO_PATH) {
42+
fail('Some of the required environment variables are not set');
43+
return;
44+
}
45+
46+
const builder = new Builder();
47+
builder.logger = new Log(process.env.SPEC_LOGLEVEL || 'error');
48+
machine = builder.machine;
49+
});
50+
51+
it('Create and read dependencies JSON file', () => {
52+
const rev1Hash = "618bb5ecb831762ed085486f39496502f7b22700";
53+
const rev1Content = "// included file a\n// included file b\n\n\n // should be included\n\n // l2 else\n\n\n // should be included\n";
54+
const rev0Hash = "e2a5b434b34b5737b2ff52f51a92c5bbcc9f83bf";
55+
const rev0Content = "// included file a\n // included file b\n\n\n // should be included\n\n // l2 else\n\n\n // should be included\n";
56+
const url = `git-local:${process.env.SPEC_GIT_LOCAL_REPO_PATH}/spec/fixtures/sample-1/input.nut.out@v2.2.2`.replace(/\\/g, '/');
57+
58+
// ensure that test dependencies JSON file does not exist
59+
if (fs.existsSync(dependenciesFile)) {
60+
fs.unlinkSync(dependenciesFile);
61+
}
62+
63+
machine.dependenciesSaveFile = dependenciesFile;
64+
expect(eol.lf(machine.execute(`@include "${url}"`))).toBe(rev1Content);
65+
66+
// check dependencies JSON file content
67+
const rev1Map = new Map(JSON.parse(fs.readFileSync(dependenciesFile)));
68+
expect(rev1Map.size).toEqual(1);
69+
expect(rev1Map.get(url)).toEqual(rev1Hash);
70+
71+
// replace the actual (rev1) commit ID to rev0 commit ID
72+
rev1Map.set(url, rev0Hash);
73+
fs.writeFileSync(dependenciesFile, JSON.stringify([...rev1Map], null, 2), 'utf-8');
74+
75+
machine.dependenciesUseFile = dependenciesFile;
76+
expect(eol.lf(machine.execute(`@include "${url}"`))).toBe(rev0Content);
77+
78+
// check dependencies JSON file content again
79+
const rev0Map = new Map(JSON.parse(fs.readFileSync(dependenciesFile)));
80+
expect(rev0Map.size).toEqual(1);
81+
expect(rev0Map.get(url)).toEqual(rev0Hash);
82+
83+
// unlink dependencies file to avoid conflicts with unit-tests below
84+
fs.unlinkSync(dependenciesFile);
85+
});
86+
});

Diff for: spec/GitLocal/remote-relative-includes.spec.js

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// MIT License
2+
//
3+
// Copyright 2020 Electric Imp
4+
//
5+
// SPDX-License-Identifier: MIT
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files (the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions:
13+
//
14+
// The above copyright notice and this permission notice shall be
15+
// included in all copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
20+
// EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
21+
// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22+
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23+
// OTHER DEALINGS IN THE SOFTWARE.
24+
25+
'use strict';
26+
27+
// require('jasmine-expect');
28+
29+
const eol = require('eol');
30+
const Log = require('log');
31+
const backslashToSlash = require('../backslashToSlash');
32+
const Builder = require('../../src/');
33+
34+
// File inc-a.nut contains `@include "inc-b.nut"`
35+
const gitlocalPathA = `git-local:${process.env.SPEC_GIT_LOCAL_REPO_PATH}/spec/fixtures/sample-1/inc-a.nut`.replace(/\\/g, '/');
36+
37+
describe('remote-relative-includes', () => {
38+
let machine;
39+
40+
beforeEach(function () {
41+
if (!process.env.SPEC_GIT_LOCAL_REPO_PATH) {
42+
fail('Some of the required environment variables are not set');
43+
return;
44+
}
45+
46+
const builder = new Builder();
47+
builder.logger = new Log(process.env.SPEC_LOGLEVEL || 'error');
48+
machine = builder.machine;
49+
});
50+
51+
it('fetch local include from local git repo', () => {
52+
const fileNotFoundMessage = `Local file "inc-b.nut" not found (${gitlocalPathA}:2)`;
53+
try {
54+
eol.lf(machine.execute(`@include once "${gitlocalPathA}"`));
55+
fail();
56+
} catch (e) {
57+
expect(backslashToSlash(e.message)).toEqual(fileNotFoundMessage);
58+
}
59+
60+
// Enable remote-relative-includes feature
61+
machine.remoteRelativeIncludes = true;
62+
const res = eol.lf(machine.execute(`@include once "${gitlocalPathA}"`));
63+
expect(res).toEqual('// included file a\n// included file b\n');
64+
});
65+
});

Diff for: spec/GitLocalExecutor.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// MIT License
2+
//
3+
// Copyright 2020 Electric Imp
4+
//
5+
// SPDX-License-Identifier: MIT
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files (the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions:
13+
//
14+
// The above copyright notice and this permission notice shall be
15+
// included in all copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
20+
// EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
21+
// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22+
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23+
// OTHER DEALINGS IN THE SOFTWARE.
24+
25+
const Jasmine = require('jasmine');
26+
27+
const jasmine = new Jasmine();
28+
jasmine.loadConfig({
29+
'spec_dir': 'spec',
30+
'spec_files': [
31+
"GitLocal/**/*[sS]pec.js"
32+
],
33+
"random": false,
34+
"stopSpecOnExpectationFailure": true
35+
});
36+
jasmine.execute();

Diff for: spec/support/jasmine.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"spec_files": [
44
"**/*[sS]pec.js",
55
"!BitbucketServer/**/*[sS]pec.js",
6-
"!AzureRepos/**/*[sS]pec.js"
6+
"!AzureRepos/**/*[sS]pec.js",
7+
"!GitLocal/**/*[sS]pec.js"
78
],
89
"helpers": [
910
"helpers/**/*.js"

Diff for: src/FileCache.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class FileCache {
5151
}
5252

5353
/**
54-
* Transform url or github/bitbucket link to path and filename
54+
* Transform url or github/bitbucket/azure link to path and filename
5555
* It is important, that path and filename are unique,
5656
* because collision can break the build
5757
* @param {string} link link to the file

0 commit comments

Comments
 (0)