Skip to content

Commit

Permalink
Keep version when updating package json (#831)
Browse files Browse the repository at this point in the history
* Keep the assignment version when updating `package.json`.

* Fix inconsistently generated `package.json` files.
  • Loading branch information
paparomeo authored Mar 7, 2020
1 parent 8f9cd81 commit 1c1d1fa
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion exercises/scale-generator/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "exercism-javascript",
"description": "Exercism exercises in Javascript.",
"version": "2.0.0",
"description": "Exercism exercises in Javascript.",
"author": "Katrina Owen",
"private": true,
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion exercises/yacht/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "exercism-javascript",
"version":"1.2.0",
"version": "1.2.0",
"description": "Exercism exercises in Javascript.",
"author": "Katrina Owen",
"private": true,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "exercism-javascript",
"version": null,
"description": "Exercism exercises in Javascript.",
"author": "Katrina Owen",
"private": true,
Expand Down
4 changes: 2 additions & 2 deletions scripts/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ function cleanUp() {
const SKIP_PACKAGES_FOR_CHECKSUM = ['shelljs', '@babel/node'];

// Filter out some unwanted packages and create package.json for exercises
function createExercisePackageJson() {
function createExercisePackageJson(assignmentVersion) {
const packageFile = shell.cat('package.json').toString();
const packageJson = JSON.parse(packageFile);

delete packageJson['version'];
packageJson['version'] = assignmentVersion;
SKIP_PACKAGES_FOR_CHECKSUM.forEach(pkg => delete packageJson['devDependencies'][pkg]);

const shellStr = new shell.ShellString(JSON.stringify(packageJson, null, 2) + '\n');
Expand Down
18 changes: 14 additions & 4 deletions scripts/sync
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,30 @@ const shell = require('shelljs');
const assignment = shell.env['ASSIGNMENT'];
const helpers = require('./helpers');

function copyConfig(destination) {
helpers.createExercisePackageJson();
shell.cat('exercise-package.json').to(destination + '/package.json');
function copyConfigForAssignment(assignment) {
const destination = 'exercises/' + assignment;
const assignmentPackageFilename = 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);
}

function getAssignmentVersion(assignmentPackageFilename) {
const packageFile = shell.cat(assignmentPackageFilename).toString();
const packageJson = JSON.parse(packageFile);
console.debug(packageJson)
return packageJson['version'];
}

if(assignment) {
shell.echo('Syncing ' + assignment + '...');
copyConfig('exercises/' + assignment);
}
else {
shell.echo('Syncing all assignments...');
helpers.assignments.forEach(assignment => copyConfig('exercises/' + assignment));
helpers.assignments.forEach(copyConfigForAssignment);
}

0 comments on commit 1c1d1fa

Please sign in to comment.