This repository has been archived by the owner on Feb 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-test-dependencies.js
55 lines (45 loc) · 1.85 KB
/
update-test-dependencies.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* File: update-test-dependencies.js
*
* Reads main project dependencies,
* and copies them into the test elm-package.json
*
*/
var fs = require('fs');
var path = require('path');
// Generic function to load a JSON file (does this already exist?)
var loadUTF8Json = function(filename) {
var jsonString = fs.readFileSync(filename, 'utf8');
return JSON.parse(jsonString);
};
// Load the main-project package details from elm-package.json
var mainPackage = loadUTF8Json('elm-package.json');
var mainDeps = mainPackage.dependencies;
// Load the template elm-package file for tests,
// containing only test dependencies
// (so we can tell which dependencies are for the tests themselves).
var testPackage = loadUTF8Json('tests/elm-package-template.json');
// Update the test dependencies to be those of the main project.
for (dependency in mainPackage.dependencies) {
testPackage.dependencies[dependency] = mainDeps[dependency];
};
// Update source directories too (for unpublished packages included as submodules)
for (index in mainPackage["source-directories"]) {
// Prefix relative paths with ../ so they work in the tests/ folder.
var directory = mainPackage["source-directories"][index],
prefixedDirectory;
if (path.isAbsolute(directory)) {
prefixedDirectory = directory;
} else {
prefixedDirectory = path.join('..', directory);
}
testPackage["source-directories"].push(prefixedDirectory);
}
// Stringify with four-space indentation, to preserve the existing format
// as much as possible.
var newTestPackageJson = JSON.stringify(testPackage, null, ' ');
// The existing file ends with a newline; respect that.
newTestPackageJson = newTestPackageJson + '\n';
// Make combined package file available so tests can be run.
fs.writeFileSync('tests/elm-package.json',
newTestPackageJson,
{ encoding: 'utf8' });