Skip to content

Instantly share code, notes, and snippets.

@Zegnat Zegnat/README.md
Created Jun 17, 2014

Embed
What would you like to do?
  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
You can’t perform that action at this time.