Skip to content

Commit

Permalink
Monorepo (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
hworld committed Aug 14, 2019
1 parent d172931 commit 4c3e43d
Show file tree
Hide file tree
Showing 1,553 changed files with 67,691 additions and 17,694 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -8,3 +8,4 @@
.DS_Store
.cache
yarn-error.log
/gulp/tasks/client/vendor/tmp-gamejolt.iss
3 changes: 0 additions & 3 deletions .gitmodules
@@ -1,6 +1,3 @@
[submodule "src/lib/gj-lib-client"]
path = src/lib/gj-lib-client
url = https://github.com/gamejolt/frontend-lib.git
[submodule "src/lib/site-translations"]
path = src/lib/site-translations
url = https://github.com/gamejolt/translations.git
Expand Down
40 changes: 40 additions & 0 deletions gulp/plugins/gulp-rename-langs.js
@@ -0,0 +1,40 @@
var through = require('through2');
var gutil = require('gulp-util');
var PluginError = gutil.PluginError;

const PLUGIN_NAME = 'gulp-rename-langs.js';

module.exports = function(options) {
// Creating a stream through which each file will pass
var stream = through.obj(function(file, enc, callback) {
if (file.isBuffer()) {
var content = file.contents.toString();
var parsed = JSON.parse(content);
var keys = Object.keys(parsed);
var lang = keys[0];

// Changes en-us to en_US.
var pieces = lang.split(/\-/);
if (pieces.length > 1) {
lang = pieces[0] + '_' + pieces[1].toUpperCase();
parsed[lang] = parsed[keys[0]];
delete parsed[keys[0]];
file.contents = new Buffer(JSON.stringify(parsed), 'utf-8');
}
} else if (file.isStream()) {
// Streams not supported.
this.emit(
'error',
new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported.')
);
return callback();
}

// Anything else just falls through.
this.push(file);
return callback();
});

// returning the file stream
return stream;
};
43 changes: 43 additions & 0 deletions gulp/plugins/gulp-sanitize-translations.js
@@ -0,0 +1,43 @@
var through = require('through2');
var gutil = require('gulp-util');
var PluginError = gutil.PluginError;
var sanitize = require('sanitize-html');

const PLUGIN_NAME = 'gulp-sanitize-translations.js';

module.exports = function(options) {
// Creating a stream through which each file will pass
var stream = through.obj(function(file, enc, callback) {
if (file.isBuffer()) {
var content = file.contents.toString();
var parsed = JSON.parse(content);
var lang = Object.keys(parsed)[0];

for (var i in parsed[lang]) {
if (Array.isArray(parsed[lang][i])) {
for (var n in parsed[lang][i]) {
parsed[lang][i][n] = sanitize(parsed[lang][i][n]);
}
} else {
parsed[lang][i] = sanitize(parsed[lang][i]);
}
}

file.contents = new Buffer(JSON.stringify(parsed), 'utf-8');
} else if (file.isStream()) {
// Streams not supported.
this.emit(
'error',
new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported.')
);
return callback();
}

// Anything else just falls through.
this.push(file);
return callback();
});

// returning the file stream
return stream;
};
93 changes: 93 additions & 0 deletions gulp/plugins/gulp-split-translations.js
@@ -0,0 +1,93 @@
var through = require('through2');
var gutil = require('gulp-util');
var PluginError = gutil.PluginError;
var path = require('path');
var fs = require('fs');
var pofile = require('pofile');
var _ = require('lodash');

const PLUGIN_NAME = 'gulp-split-translations.js';

module.exports = function(sections) {
// Creating a stream through which each file will pass
var stream = through.obj(function(file, enc, callback) {
if (file.isBuffer()) {
// If we aren't splitting out sections, just pass through.
if (!Object.keys(sections).length) {
this.push(file);
return callback();
}

var content = file.contents.toString();
var parsed = JSON.parse(content);
var lang = Object.keys(parsed)[0];

var poContent = fs.readFileSync(
path.resolve(
__dirname,
'../../../site-translations/' + lang + '/main.po'
),
'utf8'
);
var poParsed = pofile.parse(poContent);
var poItems = _.indexBy(poParsed.items, 'msgid');

_.forEach(
sections,
function(sectionPaths, sectionName) {
var sectionReferenceRegex = new RegExp(
'^(' + sectionPaths.join('|') + ')'
);
var sectionJson = {};
sectionJson[lang] = {};

// For each translation term in this language.
for (var i in parsed[lang]) {
var poItem = poItems[i];
if (poItem) {
var matchingReferences = 0;
for (var j in poItem.references) {
if (poItem.references[j].match(sectionReferenceRegex)) {
++matchingReferences;
}
}

// We only pull it into the section if ALL the references belong to the section.
// Otherwise we want to put it as part of the "common" translation file.
if (matchingReferences == poItem.references.length) {
sectionJson[lang][i] = parsed[lang][i];
delete parsed[lang][i];
}
}
}

this.push(
new gutil.File({
cwd: file.cwd,
base: file.base,
path: path.join(path.dirname(file.path), sectionName + '.json'),
contents: new Buffer(JSON.stringify(sectionJson), 'utf-8'),
})
);
},
this
);

file.contents = new Buffer(JSON.stringify(parsed), 'utf-8');
} else if (file.isStream()) {
// Streams not supported.
this.emit(
'error',
new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported.')
);
return callback();
}

// Anything else just falls through.
this.push(file);
return callback();
});

// returning the file stream
return stream;
};
22 changes: 22 additions & 0 deletions gulp/tasks/clean.js
@@ -0,0 +1,22 @@
const gulp = require('gulp');
const plugins = require('gulp-load-plugins')();

module.exports = config => {
gulp.task('clean:main', () => {
return gulp
.src(config.buildDir, { read: false, allowEmpty: true })
.pipe(plugins.clean({ force: true }));
});

gulp.task('clean:client', cb => {
if (config.clientBuildDir) {
return gulp
.src(config.clientBuildDir, { read: false, allowEmpty: true })
.pipe(plugins.clean({ force: true }));
} else {
cb();
}
});

gulp.task('clean', gulp.parallel('clean:main', 'clean:client'));
};

0 comments on commit 4c3e43d

Please sign in to comment.