build(aio): copy examples boilerplate
This commit is contained in:
parent
4c21114087
commit
c05a8cf7bb
File diff suppressed because it is too large
Load Diff
|
@ -21,7 +21,9 @@
|
||||||
"docs-test": "node ../dist/tools/cjs-jasmine/index-tools ../../transforms/**/*.spec.js",
|
"docs-test": "node ../dist/tools/cjs-jasmine/index-tools ../../transforms/**/*.spec.js",
|
||||||
"~~update-webdriver": "webdriver-manager update --standalone false --gecko false",
|
"~~update-webdriver": "webdriver-manager update --standalone false --gecko false",
|
||||||
"pre~~deploy": "yarn build",
|
"pre~~deploy": "yarn build",
|
||||||
"~~deploy": "firebase deploy --message \"Commit: $TRAVIS_COMMIT\" --non-interactive --token \"$FIREBASE_TOKEN\""
|
"~~deploy": "firebase deploy --message \"Commit: $TRAVIS_COMMIT\" --non-interactive --token \"$FIREBASE_TOKEN\"",
|
||||||
|
"boilerplate:add": "node ./scripts/add-example-boilerplate add",
|
||||||
|
"boilerplate:remove": "node ./scripts/add-example-boilerplate remove"
|
||||||
},
|
},
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -53,6 +55,8 @@
|
||||||
"entities": "^1.1.1",
|
"entities": "^1.1.1",
|
||||||
"firebase-tools": "^3.2.1",
|
"firebase-tools": "^3.2.1",
|
||||||
"html": "^1.0.0",
|
"html": "^1.0.0",
|
||||||
|
"fs-extra": "^2.1.1",
|
||||||
|
"globby": "^6.1.0",
|
||||||
"jasmine-core": "~2.5.2",
|
"jasmine-core": "~2.5.2",
|
||||||
"jasmine-spec-reporter": "~3.2.0",
|
"jasmine-spec-reporter": "~3.2.0",
|
||||||
"karma": "~1.4.1",
|
"karma": "~1.4.1",
|
||||||
|
@ -65,6 +69,7 @@
|
||||||
"protractor": "~5.1.0",
|
"protractor": "~5.1.0",
|
||||||
"rho": "https://github.com/petebacondarwin/rho#master",
|
"rho": "https://github.com/petebacondarwin/rho#master",
|
||||||
"rimraf": "^2.6.1",
|
"rimraf": "^2.6.1",
|
||||||
|
"shelljs": "^0.7.7",
|
||||||
"ts-node": "~2.0.0",
|
"ts-node": "~2.0.0",
|
||||||
"tslint": "~4.5.0",
|
"tslint": "~4.5.0",
|
||||||
"typescript": "2.2.0"
|
"typescript": "2.2.0"
|
||||||
|
|
|
@ -0,0 +1,147 @@
|
||||||
|
const fs = fsExtra = require('fs-extra');
|
||||||
|
const globby = require('globby');
|
||||||
|
const path = require('path');
|
||||||
|
const Q = require("q");
|
||||||
|
const shelljs = require('shelljs');
|
||||||
|
|
||||||
|
const EXAMPLES_PATH = path.join(__dirname, '/../content/examples');
|
||||||
|
const BOILERPLATE_PATH = path.join(EXAMPLES_PATH, '_boilerplate');
|
||||||
|
const EXAMPLES_TESTING_PATH = path.join(EXAMPLES_PATH, 'testing');
|
||||||
|
|
||||||
|
const files = {
|
||||||
|
exampleBoilerplate: [
|
||||||
|
'src/styles.css',
|
||||||
|
'src/systemjs.config.js',
|
||||||
|
'src/tsconfig.json',
|
||||||
|
'bs-config.json',
|
||||||
|
'bs-config.e2e.json',
|
||||||
|
'package.json',
|
||||||
|
'tslint.json'
|
||||||
|
],
|
||||||
|
exampleUnitTestingBoilerplate: [
|
||||||
|
'src/browser-test-shim.js',
|
||||||
|
'karma-test-shim.js',
|
||||||
|
'karma.conf.js'
|
||||||
|
],
|
||||||
|
exampleConfigFilename: 'example-config.json'
|
||||||
|
};
|
||||||
|
|
||||||
|
// requires admin access because it adds symlinks
|
||||||
|
function add() {
|
||||||
|
const realPath = path.join(EXAMPLES_PATH, '/node_modules');
|
||||||
|
const nodeModulesPaths = getNodeModulesPaths(EXAMPLES_PATH);
|
||||||
|
|
||||||
|
// we install the examples modules first
|
||||||
|
installNodeModules();
|
||||||
|
|
||||||
|
nodeModulesPaths.map((linkPath) => {
|
||||||
|
console.log("symlinking " + linkPath + ' -> ' + realPath)
|
||||||
|
fs.ensureSymlinkSync(realPath, linkPath);
|
||||||
|
});
|
||||||
|
|
||||||
|
return copyExampleBoilerplate();
|
||||||
|
}
|
||||||
|
|
||||||
|
function copyExampleBoilerplate() {
|
||||||
|
console.log('Copying example boilerplate files');
|
||||||
|
const examplePaths = getExamplePaths(EXAMPLES_PATH);
|
||||||
|
// Make boilerplate files read-only to avoid that they be edited by mistake.
|
||||||
|
const destFileMode = '444';
|
||||||
|
let foo = copyFiles(files.exampleBoilerplate, BOILERPLATE_PATH, examplePaths, destFileMode)
|
||||||
|
// copy the unit test boilerplate
|
||||||
|
.then(() => {
|
||||||
|
const unittestPaths = getUnitTestingPaths(EXAMPLES_PATH);
|
||||||
|
return copyFiles(files.exampleUnitTestingBoilerplate, EXAMPLES_TESTING_PATH, unittestPaths, destFileMode);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error(err);
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copies fileNames into destPaths, setting the mode of the
|
||||||
|
// files at the destination as optional_destFileMode if given.
|
||||||
|
// returns a promise
|
||||||
|
function copyFiles(fileNames, originPath, destPaths, optional_destFileMode) {
|
||||||
|
const copy = Q.denodeify(fsExtra.copy);
|
||||||
|
const chmod = Q.denodeify(fsExtra.chmod);
|
||||||
|
let copyPromises = [];
|
||||||
|
destPaths.map((destPath) => {
|
||||||
|
fileNames.forEach((fileName) => {
|
||||||
|
const originName = path.join(originPath, fileName);
|
||||||
|
const destName = path.join(destPath, fileName);
|
||||||
|
let p = copy(originName, destName, { clobber: true});
|
||||||
|
if(optional_destFileMode !== undefined) {
|
||||||
|
p = p.then(() => {
|
||||||
|
return chmod(destName, optional_destFileMode);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
copyPromises.push(p);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return Q.all(copyPromises);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getExamplePaths(basePath, includeBase) {
|
||||||
|
// includeBase defaults to false
|
||||||
|
return getPaths(basePath, files.exampleConfigFilename, includeBase);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFilenames(basePath, filename, includeBase) {
|
||||||
|
let includePatterns = [path.join(basePath, "**/" + filename)];
|
||||||
|
if (!includeBase) {
|
||||||
|
// ignore (skip) the top level version.
|
||||||
|
includePatterns.push("!" + path.join(basePath, "/" + filename));
|
||||||
|
}
|
||||||
|
// ignore (skip) the files in BOILERPLATE_PATH.
|
||||||
|
includePatterns.push("!" + path.join(BOILERPLATE_PATH, "/" + filename));
|
||||||
|
const nmPattern = path.join(basePath, "**/node_modules/**");
|
||||||
|
return globby.sync(includePatterns, {ignore: [nmPattern]});
|
||||||
|
}
|
||||||
|
|
||||||
|
function getNodeModulesPaths(basePath) {
|
||||||
|
return getExamplePaths(basePath).map((examplePath) => {
|
||||||
|
return path.join(examplePath, "/node_modules");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPaths(basePath, filename, includeBase) {
|
||||||
|
const filenames = getFilenames(basePath, filename, includeBase);
|
||||||
|
return filenames.map((fileName) => {
|
||||||
|
return path.dirname(fileName);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function getUnitTestingPaths(basePath) {
|
||||||
|
const examples = getPaths(basePath, files.exampleConfigFilename, true);
|
||||||
|
return examples.filter((example) => {
|
||||||
|
const exampleConfig = fs.readJsonSync(`${example}/${files.exampleConfigFilename}`, {throws: false});
|
||||||
|
return exampleConfig && !!exampleConfig.unittesting;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function installNodeModules() {
|
||||||
|
shelljs.exec('yarn', {cwd: EXAMPLES_PATH});
|
||||||
|
}
|
||||||
|
|
||||||
|
function remove() {
|
||||||
|
shelljs.exec('git clean -xdf', {cwd: EXAMPLES_PATH});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
add: add,
|
||||||
|
remove: remove
|
||||||
|
};
|
||||||
|
|
||||||
|
// being executed from shell script
|
||||||
|
switch (process.argv[2]) {
|
||||||
|
case 'add':
|
||||||
|
add();
|
||||||
|
break;
|
||||||
|
case 'remove':
|
||||||
|
remove();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
console.error(`There is no function with the name: ${process.argv}`);
|
||||||
|
}
|
|
@ -2235,9 +2235,9 @@ fs-extra@^0.30.0:
|
||||||
path-is-absolute "^1.0.0"
|
path-is-absolute "^1.0.0"
|
||||||
rimraf "^2.2.8"
|
rimraf "^2.2.8"
|
||||||
|
|
||||||
fs-extra@^2.0.0:
|
fs-extra@^2.0.0, fs-extra@^2.1.1:
|
||||||
version "2.0.0"
|
version "2.1.2"
|
||||||
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-2.0.0.tgz#337352bded4a0b714f3eb84de8cea765e9d37600"
|
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-2.1.2.tgz#046c70163cef9aad46b0e4a7fa467fb22d71de35"
|
||||||
dependencies:
|
dependencies:
|
||||||
graceful-fs "^4.1.2"
|
graceful-fs "^4.1.2"
|
||||||
jsonfile "^2.1.0"
|
jsonfile "^2.1.0"
|
||||||
|
@ -2393,6 +2393,16 @@ globby@^5.0.0:
|
||||||
pify "^2.0.0"
|
pify "^2.0.0"
|
||||||
pinkie-promise "^2.0.0"
|
pinkie-promise "^2.0.0"
|
||||||
|
|
||||||
|
globby@^6.1.0:
|
||||||
|
version "6.1.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/globby/-/globby-6.1.0.tgz#f5a6d70e8395e21c858fb0489d64df02424d506c"
|
||||||
|
dependencies:
|
||||||
|
array-union "^1.0.1"
|
||||||
|
glob "^7.0.3"
|
||||||
|
object-assign "^4.0.1"
|
||||||
|
pify "^2.0.0"
|
||||||
|
pinkie-promise "^2.0.0"
|
||||||
|
|
||||||
globule@^1.0.0:
|
globule@^1.0.0:
|
||||||
version "1.1.0"
|
version "1.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/globule/-/globule-1.1.0.tgz#c49352e4dc183d85893ee825385eb994bb6df45f"
|
resolved "https://registry.yarnpkg.com/globule/-/globule-1.1.0.tgz#c49352e4dc183d85893ee825385eb994bb6df45f"
|
||||||
|
@ -5167,7 +5177,7 @@ sha.js@^2.3.6:
|
||||||
dependencies:
|
dependencies:
|
||||||
inherits "^2.0.1"
|
inherits "^2.0.1"
|
||||||
|
|
||||||
shelljs@^0.7.0:
|
shelljs@^0.7.0, shelljs@^0.7.7:
|
||||||
version "0.7.7"
|
version "0.7.7"
|
||||||
resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.7.7.tgz#b2f5c77ef97148f4b4f6e22682e10bba8667cff1"
|
resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.7.7.tgz#b2f5c77ef97148f4b4f6e22682e10bba8667cff1"
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|
Loading…
Reference in New Issue