Skip to content

Commit

Permalink
Implement exercise versioning (#688)
Browse files Browse the repository at this point in the history
* Skip package.json version when comparing checksums

* Sync `hello-world` exercise with canonical data v1.1.0
  • Loading branch information
tejasbubane authored and SleeplessByte committed Jun 13, 2019
1 parent bd6e04a commit ee06c60
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion exercises/hello-world/hello-world.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { hello } from './hello-world';

describe('Hello World', () => {
test('says hello', () => {
test('Say Hi!', () => {
expect(hello()).toEqual('Hello, World!');
});
});
2 changes: 1 addition & 1 deletion exercises/hello-world/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "exercism-javascript",
"version": "0.0.0",
"version": "1.1.0",
"description": "Exercism exercises in Javascript.",
"author": "Katrina Owen",
"private": true,
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "exercism-javascript",
"version": "0.0.0",
"description": "Exercism exercises in Javascript.",
"author": "Katrina Owen",
"private": true,
Expand Down
10 changes: 9 additions & 1 deletion scripts/checksum
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ const crypto = require('crypto');

const sha = str => crypto.createHash('md5').update(str).digest("hex");

// Helper function to check single assignment
function checksum(filename, assignment, rootChecksum) {
if(!assignment) { return; }

const assignmentConfig = shell.cat(['exercises', assignment, filename].join('/')).toString();
let assignmentConfig = shell.cat(['exercises', assignment, filename].join('/')).toString();
if(filename === 'package.json') {
const json = JSON.parse(assignmentConfig);
delete json['version'];
assignmentConfig = JSON.stringify(json, null, 2) + '\n';
}
const assignmentChecksum = sha(assignmentConfig);

if(assignmentChecksum !== rootChecksum) {
Expand All @@ -27,6 +33,8 @@ function checksum(filename, assignment, rootChecksum) {
}
}

// Check all assignments by default
// or single if ASSIGNMENT is given
function checkSumAll(filename, rootFileName = filename) {
shell.echo('\nChecking integrity of ' + filename + '...');

Expand Down
1 change: 1 addition & 0 deletions scripts/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function createExercisePackageJson() {
const packageFile = shell.cat('package.json').toString();
const packageJson = JSON.parse(packageFile);

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

const shellStr = new shell.ShellString(JSON.stringify(packageJson, null, 2) + '\n');
Expand Down

0 comments on commit ee06c60

Please sign in to comment.