Moves locale and cmaps tasks to gulpfile.
This commit is contained in:
parent
f828f07ccd
commit
f1abd834d8
102
gulpfile.js
102
gulpfile.js
@ -27,6 +27,7 @@ var stream = require('stream');
|
|||||||
var exec = require('child_process').exec;
|
var exec = require('child_process').exec;
|
||||||
var spawn = require('child_process').spawn;
|
var spawn = require('child_process').spawn;
|
||||||
var streamqueue = require('streamqueue');
|
var streamqueue = require('streamqueue');
|
||||||
|
var merge = require('merge-stream');
|
||||||
var zip = require('gulp-zip');
|
var zip = require('gulp-zip');
|
||||||
|
|
||||||
var BUILD_DIR = 'build/';
|
var BUILD_DIR = 'build/';
|
||||||
@ -286,6 +287,15 @@ function checkFile(path) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkDir(path) {
|
||||||
|
try {
|
||||||
|
var stat = fs.lstatSync(path);
|
||||||
|
return stat.isDirectory();
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function createTestSource(testsName) {
|
function createTestSource(testsName) {
|
||||||
var source = stream.Readable({ objectMode: true });
|
var source = stream.Readable({ objectMode: true });
|
||||||
source._read = function () {
|
source._read = function () {
|
||||||
@ -382,6 +392,98 @@ gulp.task('buildnumber', function (done) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
gulp.task('locale', function () {
|
||||||
|
var VIEWER_LOCALE_OUTPUT = 'web/locale/';
|
||||||
|
var METADATA_OUTPUT = 'extensions/firefox/';
|
||||||
|
var EXTENSION_LOCALE_OUTPUT = 'extensions/firefox/locale/';
|
||||||
|
|
||||||
|
console.log();
|
||||||
|
console.log('### Building localization files');
|
||||||
|
|
||||||
|
rimraf.sync(EXTENSION_LOCALE_OUTPUT);
|
||||||
|
mkdirp.sync(EXTENSION_LOCALE_OUTPUT);
|
||||||
|
rimraf.sync(VIEWER_LOCALE_OUTPUT);
|
||||||
|
mkdirp.sync(VIEWER_LOCALE_OUTPUT);
|
||||||
|
|
||||||
|
var subfolders = fs.readdirSync(L10N_DIR);
|
||||||
|
subfolders.sort();
|
||||||
|
var metadataContent = '';
|
||||||
|
var chromeManifestContent = '';
|
||||||
|
var viewerOutput = '';
|
||||||
|
var locales = [];
|
||||||
|
for (var i = 0; i < subfolders.length; i++) {
|
||||||
|
var locale = subfolders[i];
|
||||||
|
var path = L10N_DIR + locale;
|
||||||
|
if (!checkDir(path)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!/^[a-z][a-z]([a-z])?(-[A-Z][A-Z])?$/.test(locale)) {
|
||||||
|
console.log('Skipping invalid locale: ' + locale);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
mkdirp.sync(EXTENSION_LOCALE_OUTPUT + '/' + locale);
|
||||||
|
mkdirp.sync(VIEWER_LOCALE_OUTPUT + '/' + locale);
|
||||||
|
|
||||||
|
locales.push(locale);
|
||||||
|
|
||||||
|
chromeManifestContent += 'locale pdf.js ' + locale + ' locale/' +
|
||||||
|
locale + '/\n';
|
||||||
|
|
||||||
|
if (checkFile(path + '/viewer.properties')) {
|
||||||
|
viewerOutput += '[' + locale + ']\n' +
|
||||||
|
'@import url(' + locale + '/viewer.properties)\n\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (checkFile(path + '/metadata.inc')) {
|
||||||
|
var metadata = fs.readFileSync(path + '/metadata.inc').toString();
|
||||||
|
metadataContent += metadata;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return merge([
|
||||||
|
createStringSource('metadata.inc', metadataContent)
|
||||||
|
.pipe(gulp.dest(METADATA_OUTPUT)),
|
||||||
|
createStringSource('chrome.manifest.inc', chromeManifestContent)
|
||||||
|
.pipe(gulp.dest(METADATA_OUTPUT)),
|
||||||
|
gulp.src(L10N_DIR + '/{' + locales.join(',') + '}' +
|
||||||
|
'/{viewer,chrome}.properties', {base: L10N_DIR})
|
||||||
|
.pipe(gulp.dest(EXTENSION_LOCALE_OUTPUT)),
|
||||||
|
|
||||||
|
createStringSource('locale.properties', viewerOutput)
|
||||||
|
.pipe(gulp.dest(VIEWER_LOCALE_OUTPUT)),
|
||||||
|
gulp.src(L10N_DIR + '/{' + locales.join(',') + '}' +
|
||||||
|
'/viewer.properties', {base: L10N_DIR})
|
||||||
|
.pipe(gulp.dest(VIEWER_LOCALE_OUTPUT))
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
gulp.task('cmaps', function () {
|
||||||
|
var CMAP_INPUT = 'external/cmaps';
|
||||||
|
var VIEWER_CMAP_OUTPUT = 'external/bcmaps';
|
||||||
|
|
||||||
|
console.log();
|
||||||
|
console.log('### Building cmaps');
|
||||||
|
|
||||||
|
// Testing a file that usually present.
|
||||||
|
if (!checkFile(CMAP_INPUT + '/UniJIS-UCS2-H')) {
|
||||||
|
console.log('./external/cmaps has no cmap files, download them from:');
|
||||||
|
console.log(' https://github.com/adobe-type-tools/cmap-resources');
|
||||||
|
throw new Error('cmap files were not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove old bcmap files.
|
||||||
|
fs.readdirSync(VIEWER_CMAP_OUTPUT).forEach(function (file) {
|
||||||
|
if (/\.bcmap$/i.test(file)) {
|
||||||
|
fs.unlinkSync(VIEWER_CMAP_OUTPUT + '/' + file);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var compressCmaps =
|
||||||
|
require('./external/cmapscompress/compress.js').compressCmaps;
|
||||||
|
compressCmaps(CMAP_INPUT, VIEWER_CMAP_OUTPUT, true);
|
||||||
|
});
|
||||||
|
|
||||||
gulp.task('bundle-firefox', ['buildnumber'], function () {
|
gulp.task('bundle-firefox', ['buildnumber'], function () {
|
||||||
var defines = builder.merge(DEFINES, {FIREFOX: true});
|
var defines = builder.merge(DEFINES, {FIREFOX: true});
|
||||||
return streamqueue({ objectMode: true },
|
return streamqueue({ objectMode: true },
|
||||||
|
75
make.js
75
make.js
@ -374,60 +374,7 @@ target.publish = function() {
|
|||||||
// Creates localized resources for the viewer and extension.
|
// Creates localized resources for the viewer and extension.
|
||||||
//
|
//
|
||||||
target.locale = function() {
|
target.locale = function() {
|
||||||
var METADATA_OUTPUT = 'extensions/firefox/metadata.inc';
|
execGulp('locale');
|
||||||
var CHROME_MANIFEST_OUTPUT = 'extensions/firefox/chrome.manifest.inc';
|
|
||||||
var EXTENSION_LOCALE_OUTPUT = 'extensions/firefox/locale';
|
|
||||||
var VIEWER_LOCALE_OUTPUT = 'web/locale/';
|
|
||||||
|
|
||||||
cd(ROOT_DIR);
|
|
||||||
echo();
|
|
||||||
echo('### Building localization files');
|
|
||||||
|
|
||||||
rm('-rf', EXTENSION_LOCALE_OUTPUT);
|
|
||||||
mkdir('-p', EXTENSION_LOCALE_OUTPUT);
|
|
||||||
rm('-rf', VIEWER_LOCALE_OUTPUT);
|
|
||||||
mkdir('-p', VIEWER_LOCALE_OUTPUT);
|
|
||||||
|
|
||||||
var subfolders = ls(LOCALE_SRC_DIR);
|
|
||||||
subfolders.sort();
|
|
||||||
var metadataContent = '';
|
|
||||||
var chromeManifestContent = '';
|
|
||||||
var viewerOutput = '';
|
|
||||||
for (var i = 0; i < subfolders.length; i++) {
|
|
||||||
var locale = subfolders[i];
|
|
||||||
var path = LOCALE_SRC_DIR + locale;
|
|
||||||
if (!test('-d', path)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!/^[a-z][a-z]([a-z])?(-[A-Z][A-Z])?$/.test(locale)) {
|
|
||||||
echo('Skipping invalid locale: ' + locale);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
mkdir('-p', EXTENSION_LOCALE_OUTPUT + '/' + locale);
|
|
||||||
mkdir('-p', VIEWER_LOCALE_OUTPUT + '/' + locale);
|
|
||||||
chromeManifestContent += 'locale pdf.js ' + locale + ' locale/' +
|
|
||||||
locale + '/\n';
|
|
||||||
|
|
||||||
if (test('-f', path + '/viewer.properties')) {
|
|
||||||
viewerOutput += '[' + locale + ']\n' +
|
|
||||||
'@import url(' + locale + '/viewer.properties)\n\n';
|
|
||||||
cp(path + '/viewer.properties', EXTENSION_LOCALE_OUTPUT + '/' + locale);
|
|
||||||
cp(path + '/viewer.properties', VIEWER_LOCALE_OUTPUT + '/' + locale);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (test('-f', path + '/chrome.properties')) {
|
|
||||||
cp(path + '/chrome.properties', EXTENSION_LOCALE_OUTPUT + '/' + locale);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (test('-f', path + '/metadata.inc')) {
|
|
||||||
var metadata = cat(path + '/metadata.inc');
|
|
||||||
metadataContent += metadata;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
viewerOutput.to(VIEWER_LOCALE_OUTPUT + 'locale.properties');
|
|
||||||
metadataContent.to(METADATA_OUTPUT);
|
|
||||||
chromeManifestContent.to(CHROME_MANIFEST_OUTPUT);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -436,25 +383,7 @@ target.locale = function() {
|
|||||||
// ./external/cmaps location.
|
// ./external/cmaps location.
|
||||||
//
|
//
|
||||||
target.cmaps = function () {
|
target.cmaps = function () {
|
||||||
var CMAP_INPUT = 'external/cmaps';
|
execGulp('cmaps');
|
||||||
var VIEWER_CMAP_OUTPUT = 'external/bcmaps';
|
|
||||||
|
|
||||||
cd(ROOT_DIR);
|
|
||||||
echo();
|
|
||||||
echo('### Building cmaps');
|
|
||||||
|
|
||||||
// testing a file that usually present
|
|
||||||
if (!test('-f', CMAP_INPUT + '/UniJIS-UCS2-H')) {
|
|
||||||
echo('./external/cmaps has no cmap files, please download them from:');
|
|
||||||
echo(' https://github.com/adobe-type-tools/cmap-resources');
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
rm(VIEWER_CMAP_OUTPUT + '*.bcmap');
|
|
||||||
|
|
||||||
var compressCmaps =
|
|
||||||
require('./external/cmapscompress/compress.js').compressCmaps;
|
|
||||||
compressCmaps(CMAP_INPUT, VIEWER_CMAP_OUTPUT, true);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
"jasmine": "^2.5.2",
|
"jasmine": "^2.5.2",
|
||||||
"jasmine-core": "^2.5.2",
|
"jasmine-core": "^2.5.2",
|
||||||
"jsdoc": "^3.3.0-alpha9",
|
"jsdoc": "^3.3.0-alpha9",
|
||||||
|
"merge-stream": "^1.0.1",
|
||||||
"mkdirp": "^0.5.1",
|
"mkdirp": "^0.5.1",
|
||||||
"node-ensure": "^0.0.0",
|
"node-ensure": "^0.0.0",
|
||||||
"requirejs": "^2.1.22",
|
"requirejs": "^2.1.22",
|
||||||
|
Loading…
Reference in New Issue
Block a user