Skip to content

Instantly share code, notes, and snippets.

@Zegnat
Created June 17, 2014 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zegnat/7a2963518ad14bdf6aa7 to your computer and use it in GitHub Desktop.
Save Zegnat/7a2963518ad14bdf6aa7 to your computer and use it in GitHub Desktop.
  1. Add to the root folder of your prism-break copy.
  2. Run by writing node copystubs.js in the terminal.
  3. Watch the output.

The output will tell you 2 things:

  1. If it has added projects from en-projects.json to any other localisation file.
  2. If any localisation file contained projects of which the slugs did not excist in en-projects.json.

The warnings given by step 2 are only warnings, you will have to resolve them yourself. This script does never remove content from a file, it only adds.

#!/usr/bin/env node
"use strict";
var db = './source/db',
fs = require('fs'),
en = JSON.parse(fs.readFileSync(db + '/en-projects.json', 'utf8')),
files = fs.readdirSync(db);
files.forEach(function (file) {
if (file.match(/^\w\w(-\w+)?-projects\.json$/)) {
var lang = JSON.parse(fs.readFileSync(db + '/' + file, 'utf8')),
list = lang.map(function (project) { return project.slug; }),
push = [];
en.forEach(function (project) {
var index = list.indexOf(project.slug);
if (index < 0) {
push.push(project.slug);
lang.push(project);
} else {
list.splice(index, 1);
}
});
if (push.length > 0) {
fs.writeFileSync(db + '/' + file, JSON.stringify(lang, null, ' '));
console.log('Added the following projects to ' + file + ' from en-projects.json:');
push.forEach(function (slug) { console.log(' ' + slug); });
}
if (list.length > 0) {
console.log('WARNING:' + "\n" + file + ' contains slugs that were not defined by en-projects.json:');
list.forEach(function (slug) { console.log(' ' + slug); });
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment