forked from exercism/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync
More file actions
executable file
·45 lines (39 loc) · 1.46 KB
/
Copy pathsync
File metadata and controls
executable file
·45 lines (39 loc) · 1.46 KB
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
#!/usr/bin/env node
/**
* Run this script (from root directory): npx babel-node scripts/sync
*
* This script is used to copy following files to all exercises & keep them in sync:
* 1. package.json
* 2. babel.config.js
* 3. .eslintrc
* 4. .npmrc
* There is a CI step which checks that package.json in root & exercises match
* (see checksum script for more info).
*/
const shell = require("shelljs");
const assignment = shell.env["ASSIGNMENT"];
const helpers = require("./helpers");
const path = require("path");
function copyConfigForAssignment(assignment) {
const destination = path.join("exercises", assignment);
const assignmentPackageFilename = path.join(destination, "package.json");
const assignmentVersion = getAssignmentVersion(assignmentPackageFilename);
helpers.createExercisePackageJson(assignmentVersion);
shell.cat("exercise-package.json").to(assignmentPackageFilename);
shell.rm("exercise-package.json");
shell.cp("babel.config.js", destination);
shell.cp(".eslintrc", destination);
shell.cp(".npmrc", destination);
}
function getAssignmentVersion(assignmentPackageFilename) {
const packageFile = shell.cat(assignmentPackageFilename).toString();
const packageJson = JSON.parse(packageFile);
return packageJson["version"];
}
if (assignment) {
shell.echo("Syncing " + assignment + "...");
copyConfigForAssignment(assignment);
} else {
shell.echo("Syncing all assignments...");
helpers.assignments.forEach(copyConfigForAssignment);
}