Merge remote-tracking branch 'origin/update-examples'

This commit is contained in:
Frank Li 2017-07-18 12:09:55 -07:00
commit ef6c04d1cb
8 changed files with 30 additions and 5 deletions

View file

@ -11,11 +11,36 @@
const CWD = process.cwd(); const CWD = process.cwd();
const fs = require("fs-extra"); const fs = require("fs-extra");
const path = require("path");
const glob = require("glob");
let examplesFolder = "examples";
if (process.argv.indexOf("translations") !== -1) { if (process.argv.indexOf("translations") !== -1) {
fs.copySync(__dirname + "/../examples-translations/", CWD, { examplesFolder = "examples-translations";
overwrite: false
});
} else {
fs.copySync(__dirname + "/../examples/", CWD, { overwrite: false });
} }
const files = glob.sync(path.join(__dirname, "..", examplesFolder, "**"));
files.forEach(file => {
if (!fs.lstatSync(file).isDirectory()) {
let target = CWD;
if (file.includes("-examples")) {
target = path.join(CWD, "..");
}
let fileName = file.substring(
file.indexOf(examplesFolder) + examplesFolder.length
);
try {
fs.copySync(file, path.join(target, fileName), {
overwrite: false,
errorOnExist: true
});
console.log(fileName + " created in " + path.basename(target));
} catch (e) {
console.log(
fileName +
" already exists in " +
path.basename(target) +
". Remove or rename the file to regenerate this example file."
);
}
}
});