2015-08-03 20:45:58 -04:00
|
|
|
var gulp = require('gulp');
|
|
|
|
var gutil = require('gulp-util');
|
2015-08-08 16:55:53 -04:00
|
|
|
var taskListing = require('gulp-task-listing');
|
|
|
|
var path = require('canonical-path');
|
2015-08-03 20:45:58 -04:00
|
|
|
var del = require('del');
|
2015-08-11 03:27:09 -04:00
|
|
|
var _ = require('lodash');
|
2015-08-08 16:55:53 -04:00
|
|
|
var argv = require('yargs').argv;
|
2016-02-16 20:40:46 -05:00
|
|
|
var env = require('gulp-env');
|
2015-09-12 03:28:01 -04:00
|
|
|
var Q = require("q");
|
|
|
|
var Minimatch = require("minimatch").Minimatch;
|
2015-09-16 02:21:55 -04:00
|
|
|
var Dgeni = require('dgeni');
|
2015-11-06 16:40:30 -05:00
|
|
|
var Package = require('dgeni').Package;
|
2015-09-16 02:21:55 -04:00
|
|
|
var fsExtra = require('fs-extra');
|
|
|
|
var fs = fsExtra;
|
2015-09-25 04:28:36 -04:00
|
|
|
var exec = require('child_process').exec;
|
|
|
|
var execPromise = Q.denodeify(exec);
|
2016-11-02 19:16:35 -04:00
|
|
|
var execSync = require('child_process').execSync;
|
2015-12-20 16:17:16 -05:00
|
|
|
// cross platform version of spawn that also works on windows.
|
|
|
|
var xSpawn = require('cross-spawn');
|
2015-09-25 04:28:36 -04:00
|
|
|
var prompt = require('prompt');
|
2015-12-07 01:54:43 -05:00
|
|
|
var globby = require("globby");
|
2015-12-20 16:17:16 -05:00
|
|
|
// Ugh... replacement needed to kill processes on any OS
|
|
|
|
// - because childProcess.kill does not work properly on windows
|
|
|
|
var treeKill = require("tree-kill");
|
2016-03-11 02:24:28 -05:00
|
|
|
var blc = require("broken-link-checker");
|
2016-07-15 05:59:23 -04:00
|
|
|
var less = require('gulp-less');
|
2016-04-26 01:42:22 -04:00
|
|
|
var tslint = require('gulp-tslint');
|
|
|
|
|
2015-09-28 14:14:12 -04:00
|
|
|
// TODO:
|
|
|
|
// 1. Think about using runSequence
|
|
|
|
// 2. Think about using spawn instead of exec in case of long error messages.
|
|
|
|
|
2015-11-04 05:55:02 -05:00
|
|
|
var TOOLS_PATH = './tools';
|
2016-07-15 17:10:12 -04:00
|
|
|
var ANGULAR_IO_PROJECT_PATH = path.resolve('.');
|
2015-11-04 05:55:02 -05:00
|
|
|
var ANGULAR_PROJECT_PATH = '../angular';
|
|
|
|
var PUBLIC_PATH = './public';
|
2016-01-08 20:55:46 -05:00
|
|
|
var TEMP_PATH = './_temp';
|
2015-11-04 05:55:02 -05:00
|
|
|
var DOCS_PATH = path.join(PUBLIC_PATH, 'docs');
|
2016-01-08 20:55:46 -05:00
|
|
|
|
2015-11-22 23:56:28 -05:00
|
|
|
var EXAMPLES_PATH = path.join(DOCS_PATH, '_examples');
|
2016-10-06 18:25:52 -04:00
|
|
|
var BOILERPLATE_PATH = path.join(EXAMPLES_PATH, '_boilerplate');
|
2016-09-24 15:03:08 -04:00
|
|
|
var EXAMPLES_TESTING_PATH = path.join(EXAMPLES_PATH, 'testing/ts');
|
2016-06-19 21:12:42 -04:00
|
|
|
var NOT_API_DOCS_GLOB = path.join(PUBLIC_PATH, './{docs/*/latest/!(api),!(docs)}/**/*.*');
|
2015-11-04 05:55:02 -05:00
|
|
|
var RESOURCES_PATH = path.join(PUBLIC_PATH, 'resources');
|
2015-11-30 20:24:16 -05:00
|
|
|
var LIVE_EXAMPLES_PATH = path.join(RESOURCES_PATH, 'live-examples');
|
2016-07-15 05:59:23 -04:00
|
|
|
var STYLES_SOURCE_PATH = path.join(TOOLS_PATH, 'styles-builder/less');
|
2015-08-03 20:45:58 -04:00
|
|
|
|
2015-11-04 05:55:02 -05:00
|
|
|
var docShredder = require(path.resolve(TOOLS_PATH, 'doc-shredder/doc-shredder'));
|
|
|
|
var exampleZipper = require(path.resolve(TOOLS_PATH, '_example-zipper/exampleZipper'));
|
2016-08-25 13:44:22 -04:00
|
|
|
var regularPlunker = require(path.resolve(TOOLS_PATH, 'plunker-builder/regularPlunker'));
|
|
|
|
var embeddedPlunker = require(path.resolve(TOOLS_PATH, 'plunker-builder/embeddedPlunker'));
|
2015-12-07 01:54:43 -05:00
|
|
|
var fsUtils = require(path.resolve(TOOLS_PATH, 'fs-utils/fsUtils'));
|
2015-08-03 20:45:58 -04:00
|
|
|
|
2016-10-03 17:58:50 -04:00
|
|
|
const WWW = argv.page ? 'www-pages' : 'www'
|
|
|
|
|
2016-07-04 11:56:14 -04:00
|
|
|
const isSilent = !!argv.silent;
|
|
|
|
if (isSilent) gutil.log = gutil.noop;
|
|
|
|
const _dgeniLogLevel = argv.dgeniLog || (isSilent ? 'error' : 'info');
|
2016-04-26 01:42:22 -04:00
|
|
|
|
2015-09-18 22:51:10 -04:00
|
|
|
var _devguideShredOptions = {
|
2015-11-04 05:55:02 -05:00
|
|
|
examplesDir: path.join(DOCS_PATH, '_examples'),
|
|
|
|
fragmentsDir: path.join(DOCS_PATH, '_fragments'),
|
2016-07-04 11:56:14 -04:00
|
|
|
zipDir: path.join(RESOURCES_PATH, 'zips'),
|
|
|
|
logLevel: _dgeniLogLevel
|
2015-08-03 20:45:58 -04:00
|
|
|
};
|
|
|
|
|
2016-01-19 05:11:58 -05:00
|
|
|
var _devguideShredJadeOptions = {
|
2016-07-04 11:56:14 -04:00
|
|
|
jadeDir: DOCS_PATH,
|
|
|
|
logLevel: _dgeniLogLevel
|
2016-01-19 05:11:58 -05:00
|
|
|
};
|
|
|
|
|
2015-09-18 22:51:10 -04:00
|
|
|
var _apiShredOptions = {
|
2016-07-15 17:10:12 -04:00
|
|
|
lang: 'ts',
|
2016-05-25 14:49:11 -04:00
|
|
|
examplesDir: path.join(ANGULAR_PROJECT_PATH, 'modules/@angular/examples'),
|
2015-11-04 05:55:02 -05:00
|
|
|
fragmentsDir: path.join(DOCS_PATH, '_fragments/_api'),
|
2016-07-04 11:56:14 -04:00
|
|
|
zipDir: path.join(RESOURCES_PATH, 'zips/api'),
|
|
|
|
logLevel: _dgeniLogLevel
|
2015-09-18 22:51:10 -04:00
|
|
|
};
|
|
|
|
|
2016-08-24 16:54:04 -04:00
|
|
|
const relDartDocApiDir = path.join('doc', 'api');
|
2016-07-15 17:10:12 -04:00
|
|
|
var _apiShredOptionsForDart = {
|
|
|
|
lang: 'dart',
|
2016-10-06 15:12:39 -04:00
|
|
|
examplesDir: path.resolve(ANGULAR_PROJECT_PATH + '2_api_examples'),
|
2016-07-15 17:10:12 -04:00
|
|
|
fragmentsDir: path.join(DOCS_PATH, '_fragments/_api'),
|
|
|
|
zipDir: path.join(RESOURCES_PATH, 'zips/api'),
|
|
|
|
logLevel: _dgeniLogLevel
|
|
|
|
};
|
|
|
|
|
2016-10-20 20:01:16 -04:00
|
|
|
var _excludePatterns = ['**/node_modules/**', '**/packages/**'];
|
2015-08-08 16:55:53 -04:00
|
|
|
|
2015-09-12 03:28:01 -04:00
|
|
|
var _excludeMatchers = _excludePatterns.map(function(excludePattern){
|
|
|
|
return new Minimatch(excludePattern)
|
2015-08-08 16:55:53 -04:00
|
|
|
});
|
|
|
|
|
2016-02-27 16:48:24 -05:00
|
|
|
var _exampleBoilerplateFiles = [
|
2016-07-15 05:59:23 -04:00
|
|
|
'a2docs.css',
|
2016-03-30 00:23:43 -04:00
|
|
|
'package.json',
|
|
|
|
'styles.css',
|
2016-04-27 14:28:22 -04:00
|
|
|
'systemjs.config.js',
|
2016-03-30 00:23:43 -04:00
|
|
|
'tsconfig.json',
|
2016-10-06 18:25:52 -04:00
|
|
|
'tslint.json'
|
2016-09-24 15:03:08 -04:00
|
|
|
];
|
2016-02-27 16:48:24 -05:00
|
|
|
|
2016-07-15 05:59:23 -04:00
|
|
|
var _exampleDartWebBoilerPlateFiles = ['a2docs.css', 'styles.css'];
|
2015-12-07 01:54:43 -05:00
|
|
|
|
2016-09-24 15:03:08 -04:00
|
|
|
var _exampleUnitTestingBoilerplateFiles = [
|
|
|
|
'karma-test-shim.js',
|
|
|
|
'karma.conf.js'
|
|
|
|
];
|
|
|
|
|
2016-06-10 07:50:16 -04:00
|
|
|
var _exampleConfigFilename = 'example-config.json';
|
|
|
|
|
2016-07-15 05:59:23 -04:00
|
|
|
var _styleLessName = 'a2docs.less';
|
|
|
|
|
2016-07-18 14:35:57 -04:00
|
|
|
// Gulp flags:
|
|
|
|
//
|
2016-08-01 17:30:12 -04:00
|
|
|
// --lang=[all | ts | js | dart | 'ts|js' | 'ts|js|dart' | ...]
|
2016-07-18 14:35:57 -04:00
|
|
|
//
|
|
|
|
// This affects which language API docs and E2E tests are run. Can be 'all',
|
|
|
|
// or a regex pattern to match any one of 'ts', 'js', or 'dart'.
|
2016-08-01 17:30:12 -04:00
|
|
|
// Default: 'ts|js' except for the "full site build" tasks (see below),
|
|
|
|
// for which it is 'all'.
|
2016-08-26 17:58:13 -04:00
|
|
|
|
|
|
|
// langs and skipLangs partition ['ts', 'js', 'dart'].
|
|
|
|
var lang, langs, skipLangs, buildDartApiDocs = false;
|
2016-07-15 17:10:12 -04:00
|
|
|
function configLangs(langOption) {
|
2016-08-26 17:58:13 -04:00
|
|
|
const fullSiteBuildTasks = ['build-compile', 'check-deploy', 'harp-compile'];
|
2016-07-15 05:59:23 -04:00
|
|
|
const buildAllDocs = argv['_'] &&
|
2016-07-18 18:59:42 -04:00
|
|
|
fullSiteBuildTasks.some((task) => argv['_'].indexOf(task) >= 0);
|
2016-08-01 17:30:12 -04:00
|
|
|
const langDefault = buildAllDocs ? 'all' : 'ts|js';
|
2016-08-26 17:58:13 -04:00
|
|
|
if (langOption === '') {
|
|
|
|
lang = '';
|
|
|
|
langs = [];
|
|
|
|
} else {
|
|
|
|
lang = (langOption || langDefault).toLowerCase();
|
|
|
|
if (lang === 'all') lang = 'ts|js|dart';
|
|
|
|
langs = lang.match(/\w+/g); // the languages in `lang` as an array
|
|
|
|
}
|
|
|
|
gutil.log(`Building docs for: [${langs}]`);
|
2016-07-18 14:35:57 -04:00
|
|
|
if (langs.indexOf('dart') >= 0) {
|
|
|
|
buildDartApiDocs = true;
|
|
|
|
// For Dart, be proactive about checking for the repo
|
|
|
|
checkAngularProjectPath(ngPathFor('dart'));
|
2016-08-26 17:58:13 -04:00
|
|
|
} else {
|
|
|
|
argv.pub = false;
|
2016-07-18 14:35:57 -04:00
|
|
|
}
|
2016-08-26 17:58:13 -04:00
|
|
|
skipLangs = [];
|
|
|
|
['ts', 'js', 'dart'].forEach(lang => {
|
|
|
|
if (langs.indexOf(lang) < 0) skipLangs.push(lang);
|
|
|
|
});
|
|
|
|
gutil.log(`Skipped languages: [${skipLangs}]`);
|
2016-07-15 17:10:12 -04:00
|
|
|
}
|
|
|
|
configLangs(argv.lang);
|
|
|
|
|
2016-06-10 17:10:30 -04:00
|
|
|
function isDartPath(path) {
|
|
|
|
// Testing via indexOf() for now. If we need to match only paths with folders
|
|
|
|
// named 'dart' vs 'dart*' then try: path.match('/dart(/|$)') != null;
|
|
|
|
return path.indexOf('/dart') > -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
function excludeDartPaths(paths) {
|
|
|
|
return paths.filter(function (p) { return !isDartPath(p); });
|
|
|
|
}
|
|
|
|
|
2016-05-30 14:05:09 -04:00
|
|
|
/**
|
|
|
|
* Run Protractor End-to-End Specs for Doc Samples
|
|
|
|
* Alias for 'run-e2e-tests'
|
|
|
|
*/
|
|
|
|
gulp.task('e2e', runE2e);
|
|
|
|
|
|
|
|
gulp.task('run-e2e-tests', runE2e);
|
|
|
|
|
2016-05-20 22:07:01 -04:00
|
|
|
/**
|
|
|
|
* Run Protractor End-to-End Tests for Doc Samples
|
|
|
|
*
|
|
|
|
* Flags
|
|
|
|
* --filter to filter/select _example app subdir names
|
2016-05-30 14:05:09 -04:00
|
|
|
* e.g. gulp e2e --filter=foo // all example apps with 'foo' in their folder names.
|
2016-05-20 22:07:01 -04:00
|
|
|
*
|
|
|
|
* --fast by-passes the npm install and webdriver update
|
|
|
|
* Use it for repeated test runs (but not the FIRST run)
|
2016-05-30 14:05:09 -04:00
|
|
|
* e.g. gulp e2e --fast
|
2016-05-20 22:07:01 -04:00
|
|
|
*
|
2016-08-01 17:30:12 -04:00
|
|
|
* --lang to filter by code language (see above for details)
|
2016-05-30 14:05:09 -04:00
|
|
|
* e.g. gulp e2e --lang=ts // only TypeScript apps
|
2016-05-20 22:07:01 -04:00
|
|
|
*/
|
2016-05-30 14:05:09 -04:00
|
|
|
function runE2e() {
|
2016-05-20 22:07:01 -04:00
|
|
|
var promise;
|
|
|
|
if (argv.fast) {
|
|
|
|
// fast; skip all setup
|
|
|
|
promise = Promise.resolve(true);
|
|
|
|
} else {
|
2016-05-30 14:05:09 -04:00
|
|
|
/*
|
|
|
|
// Not 'fast'; do full setup
|
2016-05-20 22:07:01 -04:00
|
|
|
var spawnInfo = spawnExt('npm', ['install'], { cwd: EXAMPLES_PATH});
|
|
|
|
promise = spawnInfo.promise.then(function() {
|
|
|
|
copyExampleBoilerplate();
|
2016-05-22 09:30:15 -04:00
|
|
|
spawnInfo = spawnExt('npm', ['run', 'webdriver:update'], {cwd: EXAMPLES_PATH});
|
2016-05-20 22:07:01 -04:00
|
|
|
return spawnInfo.promise;
|
|
|
|
});
|
2016-05-30 14:05:09 -04:00
|
|
|
*/
|
|
|
|
// Not 'fast'; do full setup
|
2016-10-06 18:25:52 -04:00
|
|
|
gutil.log('runE2e: install _examples stuff');
|
|
|
|
var spawnInfo = spawnExt('npm', ['install'], { cwd: EXAMPLES_PATH});
|
2016-05-30 14:05:09 -04:00
|
|
|
promise = spawnInfo.promise
|
|
|
|
.then(function() {
|
2016-07-15 05:59:23 -04:00
|
|
|
buildStyles(copyExampleBoilerplate, _.noop);
|
2016-05-30 14:05:09 -04:00
|
|
|
gutil.log('runE2e: update webdriver');
|
2016-10-06 18:25:52 -04:00
|
|
|
spawnInfo = spawnExt('npm', ['run', 'webdriver:update'], {cwd: EXAMPLES_PATH});
|
2016-05-30 14:05:09 -04:00
|
|
|
return spawnInfo.promise;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
var outputFile = path.join(process.cwd(), 'protractor-results.txt');
|
2016-05-20 22:07:01 -04:00
|
|
|
|
|
|
|
promise.then(function() {
|
2016-05-30 14:05:09 -04:00
|
|
|
return findAndRunE2eTests(argv.filter, outputFile);
|
2016-01-03 14:32:57 -05:00
|
|
|
}).then(function(status) {
|
2016-05-30 14:05:09 -04:00
|
|
|
reportStatus(status, outputFile);
|
2016-05-22 09:30:15 -04:00
|
|
|
if (status.failed.length > 0){
|
|
|
|
return Promise.reject('Some test suites failed');
|
|
|
|
}
|
2016-05-20 22:07:01 -04:00
|
|
|
}).catch(function(e) {
|
|
|
|
gutil.log(e);
|
2016-05-30 14:05:09 -04:00
|
|
|
process.exitCode = 1;
|
2015-12-20 16:17:16 -05:00
|
|
|
});
|
2016-05-30 14:05:09 -04:00
|
|
|
return promise;
|
|
|
|
}
|
2015-12-20 16:17:16 -05:00
|
|
|
|
|
|
|
// finds all of the *e2e-spec.tests under the _examples folder along
|
|
|
|
// with the corresponding apps that they should run under. Then run
|
|
|
|
// each app/spec collection sequentially.
|
2016-05-30 14:05:09 -04:00
|
|
|
function findAndRunE2eTests(filter, outputFile) {
|
|
|
|
// create an output file with header.
|
2016-01-03 14:32:57 -05:00
|
|
|
var startTime = new Date().getTime();
|
2016-05-20 22:07:01 -04:00
|
|
|
var header = `Doc Sample Protractor Results for ${lang} on ${new Date().toLocaleString()}\n`;
|
|
|
|
header += argv.fast ?
|
|
|
|
' Fast Mode (--fast): no npm install, webdriver update, or boilerplate copy\n' :
|
|
|
|
' Slow Mode: npm install, webdriver update, and boilerplate copy\n';
|
|
|
|
header += ` Filter: ${filter ? filter : 'All tests'}\n\n`;
|
2015-12-20 16:17:16 -05:00
|
|
|
fs.writeFileSync(outputFile, header);
|
|
|
|
|
|
|
|
// create an array of combos where each
|
2016-10-06 18:25:52 -04:00
|
|
|
// combo consists of { examplePath: ... }
|
2016-05-30 14:05:09 -04:00
|
|
|
var examplePaths = [];
|
2015-12-20 16:17:16 -05:00
|
|
|
var e2eSpecPaths = getE2eSpecPaths(EXAMPLES_PATH);
|
2016-05-30 14:05:09 -04:00
|
|
|
e2eSpecPaths.forEach(function(specPath) {
|
2015-12-20 16:17:16 -05:00
|
|
|
// get all of the examples under each dir where a pcFilename is found
|
2016-05-30 14:05:09 -04:00
|
|
|
localExamplePaths = getExamplePaths(specPath, true);
|
2016-05-12 11:19:17 -04:00
|
|
|
// Filter by language
|
2016-05-30 14:05:09 -04:00
|
|
|
localExamplePaths = localExamplePaths.filter(function (fn) {
|
2016-05-12 11:19:17 -04:00
|
|
|
return fn.match('/'+lang+'$') != null;
|
|
|
|
});
|
2015-12-20 16:17:16 -05:00
|
|
|
if (filter) {
|
2016-05-30 14:05:09 -04:00
|
|
|
localExamplePaths = localExamplePaths.filter(function (fn) {
|
2015-12-20 16:17:16 -05:00
|
|
|
return fn.match(filter) != null;
|
|
|
|
})
|
|
|
|
}
|
2016-05-30 14:05:09 -04:00
|
|
|
localExamplePaths.forEach(function(examplePath) {
|
|
|
|
examplePaths.push(examplePath);
|
2015-12-20 16:17:16 -05:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
// run the tests sequentially
|
2016-01-03 14:32:57 -05:00
|
|
|
var status = { passed: [], failed: [] };
|
2016-05-30 14:05:09 -04:00
|
|
|
return examplePaths.reduce(function (promise, examplePath) {
|
2015-12-20 16:17:16 -05:00
|
|
|
return promise.then(function () {
|
2016-06-10 17:10:30 -04:00
|
|
|
var runTests = isDartPath(examplePath) ? runE2eDartTests : runE2eTsTests;
|
2016-05-30 14:05:09 -04:00
|
|
|
return runTests(examplePath, outputFile).then(function(ok) {
|
2016-01-03 14:32:57 -05:00
|
|
|
var arr = ok ? status.passed : status.failed;
|
2016-05-30 14:05:09 -04:00
|
|
|
arr.push(examplePath);
|
2016-01-03 14:32:57 -05:00
|
|
|
})
|
2015-12-20 16:17:16 -05:00
|
|
|
});
|
2016-01-03 14:32:57 -05:00
|
|
|
}, Q.resolve()).then(function() {
|
|
|
|
var stopTime = new Date().getTime();
|
|
|
|
status.elapsedTime = (stopTime - startTime)/1000;
|
|
|
|
return status;
|
|
|
|
});
|
2015-12-20 16:17:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// start the example in appDir; then run protractor with the specified
|
|
|
|
// fileName; then shut down the example. All protractor output is appended
|
|
|
|
// to the outputFile.
|
2016-05-30 14:05:09 -04:00
|
|
|
function runE2eTsTests(appDir, outputFile) {
|
2016-06-10 07:50:16 -04:00
|
|
|
// Grab protractor configuration or defaults to systemjs config.
|
|
|
|
try {
|
|
|
|
var exampleConfig = fs.readJsonSync(`${appDir}/${_exampleConfigFilename}`);
|
|
|
|
} catch (e) {
|
2016-09-27 06:16:17 -04:00
|
|
|
exampleConfig = {};
|
2016-06-05 14:25:16 -04:00
|
|
|
}
|
|
|
|
|
2016-09-27 06:16:17 -04:00
|
|
|
var config = {
|
|
|
|
build: exampleConfig.build || 'tsc',
|
|
|
|
run: exampleConfig.run || 'http-server:e2e'
|
|
|
|
};
|
2016-06-05 14:25:16 -04:00
|
|
|
|
2016-09-27 06:16:17 -04:00
|
|
|
var appBuildSpawnInfo = spawnExt('npm', ['run', config.build], { cwd: appDir });
|
|
|
|
var appRunSpawnInfo = spawnExt('npm', ['run', config.run, '--', '-s'], { cwd: appDir });
|
2016-06-10 07:50:16 -04:00
|
|
|
|
2016-10-12 04:44:49 -04:00
|
|
|
var run = runProtractor(appBuildSpawnInfo.promise, appDir, appRunSpawnInfo, outputFile);
|
|
|
|
|
|
|
|
if (fs.existsSync(appDir + '/aot/index.html')) {
|
|
|
|
run = run.then(() => runProtractorAoT(appDir, outputFile));
|
|
|
|
}
|
|
|
|
return run;
|
2016-05-12 11:19:17 -04:00
|
|
|
}
|
|
|
|
|
2016-05-30 14:05:09 -04:00
|
|
|
function runProtractor(prepPromise, appDir, appRunSpawnInfo, outputFile) {
|
2016-06-01 16:58:01 -04:00
|
|
|
var specFilename = path.resolve(`${appDir}/../e2e-spec.ts`);
|
2016-05-20 22:07:01 -04:00
|
|
|
return prepPromise
|
|
|
|
.catch(function(){
|
2016-06-01 16:58:01 -04:00
|
|
|
var emsg = `Application at ${appDir} failed to transpile.\n\n`;
|
2016-05-20 22:07:01 -04:00
|
|
|
gutil.log(emsg);
|
|
|
|
fs.appendFileSync(outputFile, emsg);
|
|
|
|
return Promise.reject(emsg);
|
|
|
|
})
|
|
|
|
.then(function (data) {
|
2016-06-01 16:58:01 -04:00
|
|
|
var transpileError = false;
|
|
|
|
|
2016-05-20 22:07:01 -04:00
|
|
|
// start protractor
|
2016-06-01 16:58:01 -04:00
|
|
|
|
2016-05-30 14:05:09 -04:00
|
|
|
var spawnInfo = spawnExt('npm', [ 'run', 'protractor', '--', 'protractor.config.js',
|
2016-10-06 18:25:52 -04:00
|
|
|
`--specs=${specFilename}`, '--params.appDir=' + appDir, '--params.outputFile=' + outputFile], { cwd: EXAMPLES_PATH });
|
2016-06-01 16:58:01 -04:00
|
|
|
|
|
|
|
spawnInfo.proc.stderr.on('data', function (data) {
|
|
|
|
transpileError = transpileError || /npm ERR! Exit status 100/.test(data.toString());
|
|
|
|
});
|
|
|
|
return spawnInfo.promise.catch(function(err) {
|
|
|
|
if (transpileError) {
|
|
|
|
var emsg = `${specFilename} failed to transpile.\n\n`;
|
|
|
|
gutil.log(emsg);
|
|
|
|
fs.appendFileSync(outputFile, emsg);
|
|
|
|
}
|
|
|
|
return Promise.reject(emsg);
|
|
|
|
});
|
2016-05-20 22:07:01 -04:00
|
|
|
})
|
|
|
|
.then(
|
|
|
|
function() { return finish(true);},
|
|
|
|
function() { return finish(false);}
|
|
|
|
)
|
|
|
|
|
|
|
|
function finish(ok){
|
|
|
|
// Ugh... proc.kill does not work properly on windows with child processes.
|
|
|
|
// appRun.proc.kill();
|
|
|
|
treeKill(appRunSpawnInfo.proc.pid);
|
|
|
|
return ok;
|
|
|
|
}
|
2016-01-03 14:32:57 -05:00
|
|
|
}
|
|
|
|
|
2016-10-12 04:44:49 -04:00
|
|
|
function runProtractorAoT(appDir, outputFile) {
|
|
|
|
fs.appendFileSync(outputFile, '++ AoT version ++\n');
|
|
|
|
var aotBuildSpawnInfo = spawnExt('npm', ['run', 'build:aot'], { cwd: appDir });
|
|
|
|
var promise = aotBuildSpawnInfo.promise;
|
|
|
|
|
|
|
|
var copyFileCmd = 'copy-dist-files.js';
|
|
|
|
if (fs.existsSync(appDir + '/' + copyFileCmd)) {
|
|
|
|
promise = promise.then(() =>
|
|
|
|
spawnExt('node', [copyFileCmd], { cwd: appDir }).promise );
|
|
|
|
}
|
|
|
|
var aotRunSpawnInfo = spawnExt('npm', ['run', 'http-server:e2e', 'aot', '--', '-s'], { cwd: appDir });
|
|
|
|
return runProtractor(promise, appDir, aotRunSpawnInfo, outputFile);
|
|
|
|
}
|
|
|
|
|
2016-05-12 11:19:17 -04:00
|
|
|
// start the server in appDir/build/web; then run protractor with the specified
|
|
|
|
// fileName; then shut down the example. All protractor output is appended
|
|
|
|
// to the outputFile.
|
2016-05-30 14:05:09 -04:00
|
|
|
function runE2eDartTests(appDir, outputFile) {
|
2016-10-26 09:10:42 -04:00
|
|
|
// Launch http server out of ts directory because all the config files are there.
|
|
|
|
var httpLaunchDir = path.resolve(appDir, '../ts');
|
|
|
|
var deployDir = path.resolve(appDir, 'build/web');
|
2016-05-12 11:19:17 -04:00
|
|
|
gutil.log('AppDir for Dart e2e: ' + appDir);
|
|
|
|
gutil.log('Deploying from: ' + deployDir);
|
|
|
|
|
2016-10-26 09:10:42 -04:00
|
|
|
var appRunSpawnInfo = spawnExt('npm', ['run', 'http-server:e2e', '--', deployDir, '-s'], { cwd: httpLaunchDir });
|
2016-05-12 11:19:17 -04:00
|
|
|
if (!appRunSpawnInfo.proc.pid) {
|
|
|
|
gutil.log('http-server failed to launch over ' + deployDir);
|
|
|
|
return false;
|
|
|
|
}
|
2016-08-22 18:02:19 -04:00
|
|
|
if (argv.pub === false) {
|
|
|
|
var prepPromise = Promise.resolve(true);
|
2016-08-24 16:54:04 -04:00
|
|
|
gutil.log('Skipping pub upgrade and pub build (--no-pub flag present)');
|
2016-08-22 18:02:19 -04:00
|
|
|
} else {
|
|
|
|
var pubUpgradeSpawnInfo = spawnExt('pub', ['upgrade'], { cwd: appDir });
|
|
|
|
var prepPromise = pubUpgradeSpawnInfo.promise.then(function (data) {
|
|
|
|
return spawnExt('pub', ['build'], { cwd: appDir }).promise;
|
|
|
|
});
|
|
|
|
}
|
2016-05-30 14:05:09 -04:00
|
|
|
return runProtractor(prepPromise, appDir, appRunSpawnInfo, outputFile);
|
2016-05-12 11:19:17 -04:00
|
|
|
}
|
|
|
|
|
2016-05-30 14:05:09 -04:00
|
|
|
function reportStatus(status, outputFile) {
|
|
|
|
var log = [''];
|
|
|
|
log.push('Suites passed:');
|
2016-01-03 14:32:57 -05:00
|
|
|
status.passed.forEach(function(val) {
|
2016-05-30 14:05:09 -04:00
|
|
|
log.push(' ' + val);
|
2016-01-03 14:32:57 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
if (status.failed.length == 0) {
|
2016-05-30 14:05:09 -04:00
|
|
|
log.push('All tests passed');
|
2016-05-12 11:19:17 -04:00
|
|
|
} else {
|
2016-05-30 14:05:09 -04:00
|
|
|
log.push('Suites failed:');
|
2016-05-12 11:19:17 -04:00
|
|
|
status.failed.forEach(function (val) {
|
2016-05-30 14:05:09 -04:00
|
|
|
log.push(' ' + val);
|
2016-05-12 11:19:17 -04:00
|
|
|
});
|
2016-01-03 14:32:57 -05:00
|
|
|
}
|
2016-05-30 14:05:09 -04:00
|
|
|
log.push('\nElapsed time: ' + status.elapsedTime + ' seconds');
|
|
|
|
var log = log.join('\n');
|
|
|
|
gutil.log(log);
|
|
|
|
fs.appendFileSync(outputFile, log);
|
2015-12-20 16:17:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// returns both a promise and the spawned process so that it can be killed if needed.
|
|
|
|
function spawnExt(command, args, options) {
|
|
|
|
var deferred = Q.defer();
|
|
|
|
var descr = command + " " + args.join(' ');
|
|
|
|
var proc;
|
|
|
|
gutil.log('running: ' + descr);
|
|
|
|
try {
|
|
|
|
proc = xSpawn.spawn(command, args, options);
|
|
|
|
} catch(e) {
|
|
|
|
gutil.log(e);
|
|
|
|
deferred.reject(e);
|
|
|
|
return { proc: null, promise: deferred.promise };
|
|
|
|
}
|
|
|
|
proc.stdout.on('data', function (data) {
|
|
|
|
gutil.log(data.toString());
|
|
|
|
});
|
|
|
|
proc.stderr.on('data', function (data) {
|
|
|
|
gutil.log(data.toString());
|
|
|
|
});
|
2016-05-20 22:07:01 -04:00
|
|
|
proc.on('close', function (returnCode) {
|
2015-12-20 16:17:16 -05:00
|
|
|
gutil.log('completed: ' + descr);
|
2016-05-20 22:07:01 -04:00
|
|
|
// Many tasks (e.g., tsc) complete but are actually errors;
|
|
|
|
// Confirm return code is zero.
|
|
|
|
returnCode === 0 ? deferred.resolve(0) : deferred.reject(returnCode);
|
2015-12-20 16:17:16 -05:00
|
|
|
});
|
|
|
|
proc.on('error', function (data) {
|
|
|
|
gutil.log('completed with error:' + descr);
|
|
|
|
gutil.log(data.toString());
|
|
|
|
deferred.reject(data);
|
|
|
|
});
|
|
|
|
return { proc: proc, promise: deferred.promise };
|
|
|
|
}
|
|
|
|
|
2015-11-13 03:38:32 -05:00
|
|
|
// Public tasks
|
|
|
|
|
|
|
|
gulp.task('default', ['help']);
|
|
|
|
|
2015-09-18 22:51:10 -04:00
|
|
|
gulp.task('help', taskListing.withFilters(function(taskName) {
|
|
|
|
var isSubTask = taskName.substr(0,1) == "_";
|
|
|
|
return isSubTask;
|
|
|
|
}, function(taskName) {
|
|
|
|
var shouldRemove = taskName === 'default';
|
|
|
|
return shouldRemove;
|
|
|
|
}));
|
|
|
|
|
2016-05-30 14:05:09 -04:00
|
|
|
// requires admin access because it adds symlinks
|
2016-07-15 05:59:23 -04:00
|
|
|
gulp.task('add-example-boilerplate', function(done) {
|
2015-12-07 01:54:43 -05:00
|
|
|
var realPath = path.join(EXAMPLES_PATH, '/node_modules');
|
2016-06-15 18:28:06 -04:00
|
|
|
var nodeModulesPaths = excludeDartPaths(getNodeModulesPaths(EXAMPLES_PATH));
|
2015-12-07 01:54:43 -05:00
|
|
|
|
|
|
|
nodeModulesPaths.forEach(function(linkPath) {
|
|
|
|
gutil.log("symlinking " + linkPath + ' -> ' + realPath)
|
|
|
|
fsUtils.addSymlink(realPath, linkPath);
|
|
|
|
});
|
2016-03-30 00:23:43 -04:00
|
|
|
|
2016-07-15 05:59:23 -04:00
|
|
|
return buildStyles(copyExampleBoilerplate, done);
|
2015-12-20 16:17:16 -05:00
|
|
|
});
|
|
|
|
|
2016-05-30 14:05:09 -04:00
|
|
|
|
|
|
|
// copies boilerplate files to locations
|
|
|
|
// where an example app is found
|
2016-07-15 05:59:23 -04:00
|
|
|
gulp.task('_copy-example-boilerplate', function (done) {
|
2016-08-17 12:23:29 -04:00
|
|
|
return argv.fast ? done() : buildStyles(copyExampleBoilerplate, done);
|
2016-07-08 00:35:40 -04:00
|
|
|
});
|
2016-05-30 14:05:09 -04:00
|
|
|
|
2016-09-19 23:24:40 -04:00
|
|
|
//Builds Angular Docs CSS file from Bootstrap npm LESS source
|
2016-07-15 05:59:23 -04:00
|
|
|
//and copies the result to the _examples folder to be included as
|
|
|
|
//part of the example boilerplate.
|
|
|
|
function buildStyles(cb, done){
|
|
|
|
gulp.src(path.join(STYLES_SOURCE_PATH, _styleLessName))
|
|
|
|
.pipe(less())
|
2016-10-06 18:25:52 -04:00
|
|
|
.pipe(gulp.dest(BOILERPLATE_PATH)).on('end', function(){
|
2016-07-15 05:59:23 -04:00
|
|
|
cb().then(function() { done(); });
|
|
|
|
});
|
|
|
|
}
|
2016-05-30 14:05:09 -04:00
|
|
|
|
2015-12-20 16:17:16 -05:00
|
|
|
// copies boilerplate files to locations
|
|
|
|
// where an example app is found
|
2016-02-27 16:48:24 -05:00
|
|
|
// also copies certain web files (e.g., styles.css) to ~/_examples/**/dart/**/web
|
2015-12-20 16:17:16 -05:00
|
|
|
function copyExampleBoilerplate() {
|
2016-05-30 14:05:09 -04:00
|
|
|
gutil.log('Copying example boilerplate files');
|
2015-12-11 14:59:57 -05:00
|
|
|
var sourceFiles = _exampleBoilerplateFiles.map(function(fn) {
|
2016-10-06 18:25:52 -04:00
|
|
|
return path.join(BOILERPLATE_PATH, fn);
|
2015-12-11 14:59:57 -05:00
|
|
|
});
|
2016-06-10 17:10:30 -04:00
|
|
|
var examplePaths = excludeDartPaths(getExamplePaths(EXAMPLES_PATH));
|
2016-03-30 00:23:43 -04:00
|
|
|
|
2016-02-27 16:48:24 -05:00
|
|
|
var dartWebSourceFiles = _exampleDartWebBoilerPlateFiles.map(function(fn){
|
2016-10-06 18:25:52 -04:00
|
|
|
return path.join(BOILERPLATE_PATH, fn);
|
2015-12-20 16:17:16 -05:00
|
|
|
});
|
2016-02-27 16:48:24 -05:00
|
|
|
var dartExampleWebPaths = getDartExampleWebPaths(EXAMPLES_PATH);
|
|
|
|
|
2016-06-10 17:10:30 -04:00
|
|
|
// Make boilerplate files read-only to avoid that they be edited by mistake.
|
|
|
|
var destFileMode = '444';
|
|
|
|
return copyFiles(sourceFiles, examplePaths, destFileMode)
|
2016-02-27 16:48:24 -05:00
|
|
|
.then(function() {
|
2016-06-10 17:10:30 -04:00
|
|
|
return copyFiles(dartWebSourceFiles, dartExampleWebPaths, destFileMode);
|
2016-02-27 16:48:24 -05:00
|
|
|
})
|
2016-09-24 15:03:08 -04:00
|
|
|
// copy the unit test boilerplate
|
|
|
|
.then(function() {
|
|
|
|
var unittestSourceFiles =
|
|
|
|
_exampleUnitTestingBoilerplateFiles
|
|
|
|
.map(function(name) { return path.join(EXAMPLES_TESTING_PATH, name); });
|
|
|
|
var unittestPaths = getUnitTestingPaths(EXAMPLES_PATH);
|
|
|
|
return copyFiles(unittestSourceFiles, unittestPaths, destFileMode);
|
2016-10-06 18:25:52 -04:00
|
|
|
})
|
|
|
|
.catch(function(err) {
|
|
|
|
gutil.log(err);
|
|
|
|
throw err;
|
2016-02-27 16:48:24 -05:00
|
|
|
});
|
2015-12-20 16:17:16 -05:00
|
|
|
}
|
2015-12-07 01:54:43 -05:00
|
|
|
|
2015-12-11 14:59:57 -05:00
|
|
|
gulp.task('remove-example-boilerplate', function() {
|
2015-12-07 01:54:43 -05:00
|
|
|
var nodeModulesPaths = getNodeModulesPaths(EXAMPLES_PATH);
|
|
|
|
nodeModulesPaths.forEach(function(linkPath) {
|
|
|
|
fsUtils.removeSymlink(linkPath);
|
|
|
|
});
|
2016-03-30 00:23:43 -04:00
|
|
|
|
2016-05-30 14:05:09 -04:00
|
|
|
deleteExampleBoilerPlate();
|
|
|
|
});
|
|
|
|
|
2016-07-14 15:27:11 -04:00
|
|
|
// Npm install Angular libraries into examples/node_modules,
|
|
|
|
// either release or current build packages
|
|
|
|
// Examples:
|
|
|
|
// gulp install-example-angular --build // use current build packages
|
2016-08-30 17:45:17 -04:00
|
|
|
// gulp install-example-angular --build=2.0.0-b43f954 // use tagged packages
|
2016-07-14 15:27:11 -04:00
|
|
|
// gulp install-example-angular // restore release packages
|
2016-08-30 17:45:17 -04:00
|
|
|
//
|
|
|
|
// Find the tags here: https://github.com/angular/core-builds/releases
|
2016-07-14 15:27:11 -04:00
|
|
|
gulp.task('install-example-angular', installExampleAngular);
|
|
|
|
|
|
|
|
function installExampleAngular() {
|
|
|
|
var sources;
|
|
|
|
var template;
|
|
|
|
var libs = [
|
2016-08-23 03:17:18 -04:00
|
|
|
'core', 'common', 'compiler', 'compiler-cli',
|
2016-07-14 15:27:11 -04:00
|
|
|
'platform-browser', 'platform-browser-dynamic',
|
2016-07-14 15:35:06 -04:00
|
|
|
'forms', 'http', 'router', 'upgrade'];
|
2016-07-14 15:27:11 -04:00
|
|
|
|
2016-08-30 17:45:17 -04:00
|
|
|
var build = argv.build;
|
|
|
|
if (build) {
|
|
|
|
if (typeof build === 'string') {
|
|
|
|
build = (build[0]==='#' ? '' : '#') + build;
|
|
|
|
} else {
|
|
|
|
build = '';
|
|
|
|
}
|
|
|
|
} else{
|
|
|
|
build = 'npm';
|
|
|
|
}
|
2016-07-14 15:27:11 -04:00
|
|
|
// Like: "angular/core-builds" or "@angular/core"
|
2016-08-30 17:45:17 -04:00
|
|
|
sources = libs.map( lib => {
|
|
|
|
return build === 'npm'
|
|
|
|
? `@angular/${lib}`
|
|
|
|
: `git+https://github.com/angular/${lib}-builds${build}`;
|
|
|
|
});
|
2016-07-14 15:27:11 -04:00
|
|
|
|
2016-08-23 03:17:18 -04:00
|
|
|
if (argv.build) { sources.push('@angular/tsc-wrapped');} // tsc-wrapped needed for builds
|
|
|
|
|
2016-07-14 15:35:06 -04:00
|
|
|
sources.push('@angular/router-deprecated');
|
|
|
|
|
2016-08-30 17:45:17 -04:00
|
|
|
gutil.log(`Installing Angular packages from ${build === 'npm' ? 'NPM' : 'BUILD ' + build}`);
|
2016-07-14 15:27:11 -04:00
|
|
|
|
|
|
|
var spawnInfo = spawnExt('rm', ['-rf', 'node_modules/@angular'], { cwd: EXAMPLES_PATH});
|
|
|
|
return spawnInfo.promise
|
|
|
|
.then(() => {
|
|
|
|
spawnInfo = spawnExt('npm', ['install', ...sources], {cwd: EXAMPLES_PATH});
|
|
|
|
return spawnInfo.promise
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-05-30 14:05:09 -04:00
|
|
|
// deletes boilerplate files that were added by copyExampleBoilerplate
|
|
|
|
// from locations where an example app is found
|
|
|
|
gulp.task('_delete-example-boilerplate', deleteExampleBoilerPlate);
|
|
|
|
|
|
|
|
function deleteExampleBoilerPlate() {
|
|
|
|
gutil.log('Deleting example boilerplate files');
|
2015-12-11 14:59:57 -05:00
|
|
|
var examplePaths = getExamplePaths(EXAMPLES_PATH);
|
2016-02-27 16:48:24 -05:00
|
|
|
var dartExampleWebPaths = getDartExampleWebPaths(EXAMPLES_PATH);
|
2016-03-30 00:23:43 -04:00
|
|
|
|
2016-02-27 16:48:24 -05:00
|
|
|
return deleteFiles(_exampleBoilerplateFiles, examplePaths)
|
|
|
|
.then(function() {
|
|
|
|
return deleteFiles(_exampleDartWebBoilerPlateFiles, dartExampleWebPaths);
|
2016-05-30 14:05:09 -04:00
|
|
|
});
|
|
|
|
}
|
2015-12-07 01:54:43 -05:00
|
|
|
|
2015-09-18 22:51:10 -04:00
|
|
|
gulp.task('serve-and-sync', ['build-docs'], function (cb) {
|
2016-01-19 05:11:58 -05:00
|
|
|
// watchAndSync({devGuide: true, apiDocs: true, apiExamples: true, localFiles: true}, cb);
|
|
|
|
watchAndSync({devGuide: true, devGuideJade: true, apiDocs: true, apiExamples: true, localFiles: true}, cb);
|
2015-11-13 03:38:32 -05:00
|
|
|
});
|
2015-08-08 16:55:53 -04:00
|
|
|
|
2015-12-01 14:50:59 -05:00
|
|
|
gulp.task('serve-and-sync-api', ['build-docs'], function (cb) {
|
2015-11-13 03:38:32 -05:00
|
|
|
watchAndSync({apiDocs: true, apiExamples: true}, cb);
|
|
|
|
});
|
2015-09-18 22:51:10 -04:00
|
|
|
|
2016-01-19 05:11:58 -05:00
|
|
|
gulp.task('serve-and-sync-devguide', ['build-devguide-docs', 'build-plunkers' ], function (cb) {
|
|
|
|
watchAndSync({devGuide: true, devGuideJade: true, localFiles: true}, cb);
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('_serve-and-sync-jade', function (cb) {
|
|
|
|
watchAndSync({devGuideJade: true, localFiles: true}, cb);
|
2015-08-03 20:45:58 -04:00
|
|
|
});
|
|
|
|
|
2015-10-16 12:09:44 -04:00
|
|
|
gulp.task('build-and-serve', ['build-docs'], function (cb) {
|
2015-11-13 03:38:32 -05:00
|
|
|
watchAndSync({localFiles: true}, cb);
|
2015-08-08 16:55:53 -04:00
|
|
|
});
|
2015-08-03 20:45:58 -04:00
|
|
|
|
2016-02-27 16:48:24 -05:00
|
|
|
gulp.task('build-docs', ['build-devguide-docs', 'build-api-docs', 'build-plunkers']);
|
|
|
|
// Stop zipping examples Feb 28, 2016
|
|
|
|
//gulp.task('build-docs', ['build-devguide-docs', 'build-api-docs', 'build-plunkers', '_zip-examples']);
|
2015-11-13 03:38:32 -05:00
|
|
|
|
2016-07-18 14:35:57 -04:00
|
|
|
gulp.task('build-api-docs', ['build-js-api-docs', 'build-ts-api-docs']
|
|
|
|
.concat(buildDartApiDocs ? ['build-dart-api-docs', 'build-dart-cheatsheet'] : []));
|
2015-08-03 20:45:58 -04:00
|
|
|
|
2016-01-19 05:11:58 -05:00
|
|
|
gulp.task('build-devguide-docs', ['_shred-devguide-examples', '_shred-devguide-shared-jade'], function() {
|
2015-09-18 22:51:10 -04:00
|
|
|
return buildShredMaps(true);
|
2015-08-03 20:45:58 -04:00
|
|
|
});
|
|
|
|
|
2015-11-06 16:40:30 -05:00
|
|
|
gulp.task('build-ts-api-docs', ['_shred-api-examples'], function() {
|
|
|
|
return buildApiDocs('ts');
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('build-js-api-docs', ['_shred-api-examples'], function() {
|
|
|
|
return buildApiDocs('js');
|
2015-09-18 22:51:10 -04:00
|
|
|
});
|
|
|
|
|
2016-07-15 17:10:12 -04:00
|
|
|
gulp.task('build-dart-api-docs', ['_shred-api-examples', 'dartdoc'], function() {
|
|
|
|
return buildApiDocsForDart();
|
|
|
|
});
|
|
|
|
|
2016-11-05 00:59:51 -04:00
|
|
|
// Using the --build flag will use systemjs.config.web.build.js (for preview builds)
|
2016-06-01 16:58:01 -04:00
|
|
|
gulp.task('build-plunkers', ['_copy-example-boilerplate'], function() {
|
2016-08-25 13:44:22 -04:00
|
|
|
regularPlunker.buildPlunkers(EXAMPLES_PATH, LIVE_EXAMPLES_PATH, { errFn: gutil.log, build: argv.build });
|
2016-09-13 17:39:39 -04:00
|
|
|
return embeddedPlunker.buildPlunkers(EXAMPLES_PATH, LIVE_EXAMPLES_PATH, { errFn: gutil.log, build: argv.build, targetSelf: argv.targetSelf });
|
2015-11-30 20:24:16 -05:00
|
|
|
});
|
|
|
|
|
2016-07-19 15:35:39 -04:00
|
|
|
gulp.task('build-dart-cheatsheet', [], function() {
|
|
|
|
return buildDartCheatsheet();
|
2016-07-15 17:10:12 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('dartdoc', ['pub upgrade'], function() {
|
|
|
|
const ngRepoPath = ngPathFor('dart');
|
2016-08-24 16:54:04 -04:00
|
|
|
if (argv.fast && fs.existsSync(path.resolve(ngRepoPath, relDartDocApiDir))) {
|
|
|
|
gutil.log(`Skipping dartdoc: --fast flag enabled and api dir exists (${relDartDocApiDir})`);
|
2016-07-15 17:10:12 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
checkAngularProjectPath(ngRepoPath);
|
2016-08-01 17:30:12 -04:00
|
|
|
const topLevelLibFilePath = path.resolve(ngRepoPath, 'lib', 'angular2.dart');
|
|
|
|
const tmpPath = topLevelLibFilePath + '.disabled';
|
2016-08-10 13:36:23 -04:00
|
|
|
renameIfExistsSync(topLevelLibFilePath, tmpPath);
|
2016-08-01 17:30:12 -04:00
|
|
|
gutil.log(`Hiding top-level angular2 library: ${topLevelLibFilePath}`);
|
2016-08-22 18:03:50 -04:00
|
|
|
// Remove dartdoc '--add-crossdart' flag while we are fixing links to API pages.
|
2016-08-24 16:54:04 -04:00
|
|
|
const dartdoc = spawnExt('dartdoc', ['--output', relDartDocApiDir], { cwd: ngRepoPath});
|
2016-08-01 17:30:12 -04:00
|
|
|
return dartdoc.promise.finally(() => {
|
|
|
|
gutil.log(`Restoring top-level angular2 library: ${topLevelLibFilePath}`);
|
2016-08-10 13:36:23 -04:00
|
|
|
renameIfExistsSync(tmpPath, topLevelLibFilePath);
|
2016-08-01 17:30:12 -04:00
|
|
|
})
|
2016-07-15 17:10:12 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('pub upgrade', [], function() {
|
|
|
|
const ngRepoPath = ngPathFor('dart');
|
|
|
|
if (argv.fast && fs.existsSync(path.resolve(ngRepoPath, 'packages'))) {
|
|
|
|
gutil.log('Skipping pub upgrade: --fast flag enabled and "packages" dir exists');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
checkAngularProjectPath(ngRepoPath);
|
|
|
|
const pubUpgrade = spawnExt('pub', ['upgrade'], { cwd: ngRepoPath});
|
|
|
|
return pubUpgrade.promise;
|
2015-12-08 15:23:43 -05:00
|
|
|
});
|
|
|
|
|
2015-09-18 22:51:10 -04:00
|
|
|
gulp.task('git-changed-examples', ['_shred-devguide-examples'], function(){
|
2015-09-12 03:28:01 -04:00
|
|
|
var after, sha, messageSuffix;
|
|
|
|
if (argv.after) {
|
|
|
|
try {
|
|
|
|
after = new Date(argv.after);
|
|
|
|
messageSuffix = ' after: ' + argv.after;
|
|
|
|
} catch (e) {
|
|
|
|
throw argv.after + " is not a valid date.";
|
|
|
|
}
|
|
|
|
} else if (argv.sha) {
|
|
|
|
sha = argv.sha;
|
|
|
|
messageSuffix = ' on commit: ' + (argv.sha.length ? argv.sha : '[last commit]');
|
|
|
|
} else {
|
2015-11-13 04:35:05 -05:00
|
|
|
gutil.log('git-changed-examples may be called with either an "--sha" argument like this:');
|
|
|
|
gutil.log(' gulp git-changed-examples --sha=4d2ac96fa247306ddd2d4c4e0c8dee2223502eb2');
|
|
|
|
gutil.log('or with an "--after" argument like this')
|
|
|
|
gutil.log(' gulp git-changed-examples --after="August 1, 2015"');
|
2015-09-12 03:28:01 -04:00
|
|
|
return;
|
|
|
|
}
|
2015-08-08 16:55:53 -04:00
|
|
|
var jadeShredMap;
|
|
|
|
return buildShredMaps(false).then(function(docs) {
|
|
|
|
jadeShredMap = docs[0];
|
2015-09-12 03:28:01 -04:00
|
|
|
if (after) {
|
|
|
|
return getChangedExamplesAfter(after);
|
|
|
|
} else if (sha) {
|
|
|
|
return getChangedExamples(sha);
|
|
|
|
} else {
|
2015-11-13 04:35:05 -05:00
|
|
|
gutil.log('git-changed-examples may be called with either an "--sha" argument like this:');
|
|
|
|
gutil.log(' gulp git-changed-examples --sha=4d2ac96fa247306ddd2d4c4e0c8dee2223502eb2');
|
|
|
|
gutil.log('or with an "--after" argument like this')
|
|
|
|
gutil.log(' gulp git-changed-examples --after="August 1, 2015"');
|
2015-09-12 03:28:01 -04:00
|
|
|
}
|
2015-08-08 16:55:53 -04:00
|
|
|
}).then(function(examplePaths) {
|
2015-09-12 03:28:01 -04:00
|
|
|
examplePaths = filterOutExcludedPatterns(examplePaths, _excludeMatchers);
|
2015-11-13 04:35:05 -05:00
|
|
|
gutil.log('\nExamples changed ' + messageSuffix);
|
|
|
|
gutil.log(examplePaths)
|
|
|
|
gutil.log("\nJade files affected by changed example files " + messageSuffix);
|
2015-08-08 16:55:53 -04:00
|
|
|
var jadeExampleMap = jadeShredMapToJadeExampleMap(jadeShredMap, examplePaths);
|
2015-11-13 04:35:05 -05:00
|
|
|
gutil.log(JSON.stringify(jadeExampleMap, null, " "));
|
|
|
|
gutil.log("-----");
|
2015-08-08 16:55:53 -04:00
|
|
|
}).catch(function(err) {
|
2015-11-13 04:35:05 -05:00
|
|
|
gutil.log(err);
|
2015-08-08 16:55:53 -04:00
|
|
|
throw err;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-08-26 17:58:13 -04:00
|
|
|
gulp.task('harp-compile', () => {
|
2016-07-15 17:10:12 -04:00
|
|
|
return harpCompile()
|
|
|
|
});
|
|
|
|
|
2016-08-26 17:58:13 -04:00
|
|
|
gulp.task('harp-serve', () => {
|
|
|
|
// Harp will watch and serve workspace files.
|
2016-07-15 17:10:12 -04:00
|
|
|
const cmd = 'npm run harp -- server .';
|
|
|
|
gutil.log('Launching harp server (over project files)');
|
|
|
|
gutil.log(` > ${cmd}`);
|
|
|
|
gutil.log('Note: issuing this command directly from the command line will show harp comiple warnings.');
|
|
|
|
return execPromise(cmd);
|
|
|
|
});
|
|
|
|
|
2016-08-26 17:58:13 -04:00
|
|
|
gulp.task('serve-www', () => {
|
2016-07-15 17:10:12 -04:00
|
|
|
// Serve generated site.
|
2016-10-03 17:58:50 -04:00
|
|
|
return execPromise(`npm run live-server ${WWW}`);
|
2016-07-15 17:10:12 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('build-compile', ['build-docs'], function() {
|
2016-07-11 10:54:29 -04:00
|
|
|
return harpCompile();
|
|
|
|
});
|
|
|
|
|
2016-11-02 19:16:35 -04:00
|
|
|
gulp.task('check-deploy', ['firebase-use-proj-check', 'build-docs'], () => {
|
2016-01-08 20:55:46 -05:00
|
|
|
return harpCompile().then(function() {
|
2016-05-22 09:30:15 -04:00
|
|
|
gutil.log('compile ok');
|
2016-07-11 10:54:29 -04:00
|
|
|
gutil.log('running live server ...');
|
2016-10-03 17:58:50 -04:00
|
|
|
execPromise(`npm run live-server ${WWW}`);
|
2016-07-11 10:54:29 -04:00
|
|
|
return askDeploy();
|
2015-09-25 04:28:36 -04:00
|
|
|
}).then(function(shouldDeploy) {
|
|
|
|
if (shouldDeploy) {
|
2015-11-13 04:35:05 -05:00
|
|
|
gutil.log('deploying...');
|
2016-11-02 19:16:35 -04:00
|
|
|
return execPromise(`firebase deploy -p ${WWW}`);
|
2015-09-28 14:14:12 -04:00
|
|
|
} else {
|
|
|
|
return ['Not deploying'];
|
2015-09-25 04:28:36 -04:00
|
|
|
}
|
2015-09-28 14:14:12 -04:00
|
|
|
}).then(function(s) {
|
2015-11-13 04:35:05 -05:00
|
|
|
gutil.log(s.join(''));
|
2015-12-07 01:54:43 -05:00
|
|
|
}).catch(function(e) {
|
|
|
|
gutil.log(e);
|
2015-09-25 04:28:36 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-11-02 19:16:35 -04:00
|
|
|
gulp.task('firebase-use-proj-check', cb => {
|
|
|
|
try {
|
|
|
|
execSync('firebase use');
|
|
|
|
} catch (e) {
|
|
|
|
// Rerun command so user gets project + alias info
|
|
|
|
execSync('firebase use', {stdio:[0,1,2]});
|
|
|
|
throw `\nAborting: no firebase project selected. Run:\n\n firebase use <project-or-alias-name>\n\n`;
|
|
|
|
}
|
|
|
|
return cb();
|
|
|
|
});
|
|
|
|
|
2015-11-13 03:38:32 -05:00
|
|
|
gulp.task('test-api-builder', function (cb) {
|
|
|
|
execCommands(['npm run test-api-builder'], {}, cb);
|
|
|
|
});
|
|
|
|
|
2016-03-11 02:24:28 -05:00
|
|
|
// Usage:
|
|
|
|
// angular.io: gulp link-checker
|
|
|
|
// local site: gulp link-checker --url=http://localhost:3000
|
|
|
|
gulp.task('link-checker', function(done) {
|
2016-07-06 17:48:19 -04:00
|
|
|
var method = 'get'; // the default 'head' fails for some sites
|
|
|
|
var exclude = [
|
|
|
|
// Dart API docs aren't working yet; ignore them
|
|
|
|
'*/dart/latest/api/*',
|
|
|
|
// Somehow the link checker sees ng1 {{...}} in the resource page; ignore it
|
|
|
|
'resources/%7B%7Bresource.url%7D%7D',
|
2016-07-14 15:27:11 -04:00
|
|
|
// API docs have links directly into GitHub repo sources; these can
|
2016-07-06 17:48:19 -04:00
|
|
|
// quickly become invalid, so ignore them for now:
|
|
|
|
'*/angular/tree/*'
|
|
|
|
];
|
|
|
|
var blcOptions = { requestMethod: method, excludedKeywords: exclude};
|
|
|
|
return linkChecker({ blcOptions: blcOptions });
|
2016-03-11 02:24:28 -05:00
|
|
|
});
|
|
|
|
|
2015-11-13 03:38:32 -05:00
|
|
|
|
|
|
|
// Internal tasks
|
2016-02-16 20:40:46 -05:00
|
|
|
gulp.task('set-prod-env', function () {
|
|
|
|
// Supposedly running in production makes harp faster
|
|
|
|
// and less likely to drown in node_modules.
|
|
|
|
env({
|
|
|
|
vars: { NODE_ENV: "production" }
|
|
|
|
});
|
|
|
|
gutil.log("NODE_ENV: " + process.env.NODE_ENV);
|
|
|
|
});
|
2015-11-13 03:38:32 -05:00
|
|
|
|
2016-01-08 20:55:46 -05:00
|
|
|
// used to test just harpCompile without a build step
|
|
|
|
gulp.task('_harp-compile', function() {
|
|
|
|
return harpCompile().then(function() {
|
|
|
|
gutil.log('compile ok');
|
|
|
|
}).catch(function(e) {
|
|
|
|
gutil.log('compile failed');
|
|
|
|
});
|
|
|
|
});
|
2015-12-07 01:54:43 -05:00
|
|
|
|
2016-06-01 16:58:01 -04:00
|
|
|
gulp.task('_shred-devguide-examples', ['_shred-clean-devguide', '_copy-example-boilerplate'], function() {
|
2016-06-14 00:27:51 -04:00
|
|
|
// Split big shredding task into partials 2016-06-14
|
2016-11-04 11:06:13 -04:00
|
|
|
var examplePaths = globby.sync(EXAMPLES_PATH+'/*/', {ignore: ['**/node_modules', '**/_boilerplate']});
|
2016-06-14 00:27:51 -04:00
|
|
|
var promise = Promise.resolve(true);
|
|
|
|
examplePaths.forEach(function (examplePath) {
|
|
|
|
promise = promise.then(() => docShredder.shredSingleExampleDir(_devguideShredOptions, examplePath));
|
|
|
|
});
|
|
|
|
return promise;
|
2015-11-13 03:38:32 -05:00
|
|
|
});
|
|
|
|
|
2016-06-01 16:58:01 -04:00
|
|
|
gulp.task('_shred-devguide-shared-jade', ['_shred-clean-devguide-shared-jade', '_copy-example-boilerplate'], function() {
|
2016-07-04 11:56:14 -04:00
|
|
|
return docShredder.shred(_devguideShredJadeOptions);
|
2016-01-19 05:11:58 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('_shred-clean-devguide-shared-jade', function(cb) {
|
2016-02-15 15:53:57 -05:00
|
|
|
// oldCleanPath is only needed to cleanup any jade fragments still sitting in the old location
|
|
|
|
var oldCleanPath = path.join(DOCS_PATH, '**/_.*.jade');
|
|
|
|
// jade fragments now all go into _fragments subdirs under their source.
|
|
|
|
var newCleanPath = path.join(DOCS_PATH, '**/_fragments/*.jade');
|
|
|
|
// Much slower 8-9x then using globby first ... ???
|
2016-06-05 17:46:52 -04:00
|
|
|
// return del([ newCleanPath, oldCleanPath]);
|
2016-02-15 15:53:57 -05:00
|
|
|
var files = globby.sync( [newCleanPath, oldCleanPath]);
|
2016-06-05 17:46:52 -04:00
|
|
|
return del(files);
|
2016-01-19 05:11:58 -05:00
|
|
|
});
|
|
|
|
|
2015-11-13 03:38:32 -05:00
|
|
|
gulp.task('_shred-clean-devguide', function(cb) {
|
|
|
|
var cleanPath = path.join(_devguideShredOptions.fragmentsDir, '**/*.*')
|
2016-06-05 17:46:52 -04:00
|
|
|
return del([ cleanPath, '!**/*.ovr.*', '!**/_api/**']);
|
2015-11-13 03:38:32 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('_shred-api-examples', ['_shred-clean-api'], function() {
|
2016-07-15 17:10:12 -04:00
|
|
|
const promises = [];
|
|
|
|
gutil.log('Shredding API examples for languages: ' + langs.join(', '));
|
2016-08-26 17:58:13 -04:00
|
|
|
langs.forEach(lang => {
|
2016-07-15 17:10:12 -04:00
|
|
|
if (lang === 'js') return; // JS is handled via TS.
|
|
|
|
checkAngularProjectPath(ngPathFor(lang));
|
|
|
|
const options = lang == 'dart' ? _apiShredOptionsForDart : _apiShredOptions;
|
|
|
|
promises.push(docShredder.shred(options));
|
|
|
|
});
|
|
|
|
return Q.all(promises);
|
2015-11-13 03:38:32 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('_shred-clean-api', function(cb) {
|
|
|
|
var cleanPath = path.join(_apiShredOptions.fragmentsDir, '**/*.*')
|
2016-06-05 17:46:52 -04:00
|
|
|
return del([ cleanPath, '!**/*.ovr.*' ]);
|
2015-11-13 03:38:32 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('_zip-examples', function() {
|
|
|
|
exampleZipper.zipExamples(_devguideShredOptions.examplesDir, _devguideShredOptions.zipDir);
|
|
|
|
exampleZipper.zipExamples(_apiShredOptions.examplesDir, _apiShredOptions.zipDir);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2016-04-26 01:42:22 -04:00
|
|
|
// Linting
|
|
|
|
|
|
|
|
gulp.task('lint', function() {
|
2016-06-07 19:06:25 -04:00
|
|
|
return gulp.src([
|
|
|
|
'./public/docs/_examples/**/*.ts',
|
|
|
|
'!./public/docs/_examples/**/ts-snippets/*.ts',
|
|
|
|
'!./public/docs/_examples/style-guide/ts/**/*.avoid.ts',
|
|
|
|
'!./public/docs/_examples/**/node_modules/**/*',
|
2016-06-29 17:26:38 -04:00
|
|
|
'!./public/docs/_examples/**/build/**/*',
|
2016-06-14 11:39:53 -04:00
|
|
|
// temporary until codelyzer is fixed mgechev/codelyzer#60
|
|
|
|
'!./public/docs/_examples/animations/ts/app/hero.service.ts'
|
2016-06-07 19:06:25 -04:00
|
|
|
])
|
2016-04-26 01:42:22 -04:00
|
|
|
.pipe(tslint({
|
|
|
|
rulesDirectory: ['node_modules/codelyzer'],
|
|
|
|
configuration: require('./tslint.json')
|
|
|
|
}))
|
|
|
|
.pipe(tslint.report('prose', {
|
|
|
|
summarizeFailureOutput: true
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2015-11-13 03:38:32 -05:00
|
|
|
// Helper functions
|
|
|
|
|
2016-01-08 20:55:46 -05:00
|
|
|
function harpCompile() {
|
2016-02-16 20:40:46 -05:00
|
|
|
// Supposedly running in production makes harp faster
|
|
|
|
// and less likely to drown in node_modules.
|
2016-08-26 17:58:13 -04:00
|
|
|
env({ vars: { NODE_ENV: "production" } });
|
2016-02-16 20:40:46 -05:00
|
|
|
gutil.log("NODE_ENV: " + process.env.NODE_ENV);
|
2016-03-30 00:23:43 -04:00
|
|
|
|
2016-10-03 17:58:50 -04:00
|
|
|
if(argv.page) harpJsonSetJade2NgTo(true);
|
2016-10-12 04:44:49 -04:00
|
|
|
|
2016-10-03 17:58:50 -04:00
|
|
|
if(skipLangs && fs.existsSync(WWW) && backupApiHtmlFilesExist(WWW)) {
|
2016-08-26 17:58:13 -04:00
|
|
|
gutil.log(`Harp site recompile: skipping recompilation of API docs for [${skipLangs}]`);
|
2016-10-03 17:58:50 -04:00
|
|
|
gutil.log(`API docs will be copied from existing ${WWW} folder.`)
|
|
|
|
del.sync(`${WWW}-backup`); // remove existing backup if it exists
|
|
|
|
renameIfExistsSync(WWW, `${WWW}-backup`);
|
2016-08-26 17:58:13 -04:00
|
|
|
} else {
|
|
|
|
gutil.log(`Harp full site compile, including API docs for all languages.`);
|
|
|
|
if (skipLangs)
|
2016-09-24 15:03:08 -04:00
|
|
|
gutil.log(`Ignoring API docs skip set (${skipLangs}) because full ` +
|
2016-09-06 14:22:29 -04:00
|
|
|
`site has not been built yet or some API HTML files are missing.`);
|
2016-08-26 17:58:13 -04:00
|
|
|
}
|
|
|
|
|
2016-01-08 20:55:46 -05:00
|
|
|
var deferred = Q.defer();
|
|
|
|
gutil.log('running harp compile...');
|
|
|
|
showHideExampleNodeModules('hide');
|
2016-08-26 17:58:13 -04:00
|
|
|
showHideApiDir('hide');
|
2016-10-03 17:58:50 -04:00
|
|
|
var spawnInfo = spawnExt('npm',['run','harp', '--', 'compile', '.', WWW ]);
|
2016-01-08 20:55:46 -05:00
|
|
|
spawnInfo.promise.then(function(x) {
|
2016-02-16 20:40:46 -05:00
|
|
|
gutil.log("NODE_ENV: " + process.env.NODE_ENV);
|
2016-01-08 20:55:46 -05:00
|
|
|
showHideExampleNodeModules('show');
|
2016-08-26 17:58:13 -04:00
|
|
|
showHideApiDir('show');
|
2016-10-03 17:58:50 -04:00
|
|
|
harpJsonSetJade2NgTo(false);
|
2016-01-08 20:55:46 -05:00
|
|
|
if (x !== 0) {
|
|
|
|
deferred.reject(x)
|
|
|
|
} else {
|
2016-08-26 17:58:13 -04:00
|
|
|
restoreApiHtml();
|
2016-01-08 20:55:46 -05:00
|
|
|
deferred.resolve(x);
|
|
|
|
}
|
|
|
|
}).catch(function(e) {
|
2016-02-16 20:40:46 -05:00
|
|
|
gutil.log("NODE_ENV: " + process.env.NODE_ENV);
|
2016-01-08 20:55:46 -05:00
|
|
|
showHideExampleNodeModules('show');
|
2016-08-26 17:58:13 -04:00
|
|
|
showHideApiDir('show');
|
2016-10-03 17:58:50 -04:00
|
|
|
harpJsonSetJade2NgTo(false);
|
2016-01-08 20:55:46 -05:00
|
|
|
deferred.reject(e);
|
|
|
|
});
|
|
|
|
return deferred.promise;
|
|
|
|
}
|
|
|
|
|
2016-03-11 02:24:28 -05:00
|
|
|
function linkChecker(options) {
|
2016-03-30 00:23:43 -04:00
|
|
|
var deferred = Q.defer();
|
2016-03-11 02:24:28 -05:00
|
|
|
var options = options || {};
|
2016-03-30 00:23:43 -04:00
|
|
|
|
2016-03-11 02:24:28 -05:00
|
|
|
var blcOptions = options.blcOptions || {};
|
|
|
|
var customData = options.customData || {};
|
2016-03-30 00:23:43 -04:00
|
|
|
|
2016-07-06 17:48:19 -04:00
|
|
|
// don't bother reporting bad links matching this RegExp
|
|
|
|
var excludeBad = argv.excludeBad ? new RegExp(argv.excludeBad) : (options.excludeBad || '');
|
2016-03-30 00:23:43 -04:00
|
|
|
|
|
|
|
var previousPage;
|
2016-03-11 02:24:28 -05:00
|
|
|
var siteUrl = argv.url || options.url || 'https://angular.io/';
|
|
|
|
|
|
|
|
// See https://github.com/stevenvachon/broken-link-checker#blcsitecheckeroptions-handlers
|
|
|
|
var handlers = {
|
|
|
|
robots: function(robots, customData){},
|
|
|
|
html: function(tree, robots, response, pageUrl, customData){
|
2016-06-01 03:12:51 -04:00
|
|
|
// gutil.log('Scanning ' + pageUrl);
|
2016-03-11 02:24:28 -05:00
|
|
|
},
|
|
|
|
junk: function(result, customData){},
|
2016-03-30 00:23:43 -04:00
|
|
|
|
2016-03-11 02:24:28 -05:00
|
|
|
// Analyze links
|
|
|
|
link: function(result, customData){
|
|
|
|
if (!result.broken) { return; }
|
|
|
|
if (excludeBad && excludeBad.test(result.url.resolved)) { return; }
|
2016-03-30 00:23:43 -04:00
|
|
|
|
2016-03-11 02:24:28 -05:00
|
|
|
var currentPage = result.base.resolved
|
|
|
|
if (previousPage !== currentPage) {
|
|
|
|
previousPage = currentPage;
|
|
|
|
fs.appendFileSync(outputFile, '\n' + currentPage);
|
|
|
|
gutil.log('broken: ' + currentPage);
|
|
|
|
}
|
|
|
|
var msg = '\n [' + result.html.location.line + ', ' + result.brokenReason + '] ' + result.url.resolved;
|
|
|
|
fs.appendFileSync(outputFile, msg);
|
2016-06-01 03:12:51 -04:00
|
|
|
// gutil.log(msg);
|
|
|
|
// gutil.log(result);
|
2016-03-11 02:24:28 -05:00
|
|
|
},
|
2016-03-30 00:23:43 -04:00
|
|
|
|
2016-03-11 02:24:28 -05:00
|
|
|
page: function(error, pageUrl, customData){},
|
|
|
|
site: function(error, siteUrl, customData){},
|
2016-03-30 00:23:43 -04:00
|
|
|
|
2016-03-11 02:24:28 -05:00
|
|
|
end: function(){
|
|
|
|
var stopTime = new Date().getTime();
|
|
|
|
var elapsed = 'Elapsed link-checking time: ' + ((stopTime - startTime)/1000) + ' seconds';
|
|
|
|
gutil.log(elapsed);
|
|
|
|
fs.appendFileSync(outputFile, '\n'+elapsed);
|
|
|
|
gutil.log('Output in file: ' + outputFile);
|
|
|
|
deferred.resolve(true);
|
|
|
|
}
|
|
|
|
};
|
2016-03-30 00:23:43 -04:00
|
|
|
|
2016-03-11 02:24:28 -05:00
|
|
|
// create an output file with header.
|
|
|
|
var outputFile = path.join(process.cwd(), 'link-checker-results.txt');
|
|
|
|
var header = 'Link checker results for: ' + siteUrl +
|
2016-03-30 00:23:43 -04:00
|
|
|
'\nStarted: ' + (new Date()).toLocaleString() +
|
2016-07-14 15:27:11 -04:00
|
|
|
'\nExcluded links (blc file globs): ' + blcOptions.excludedKeywords +
|
2016-07-06 17:48:19 -04:00
|
|
|
'\nExcluded links (custom --exclude-bad regex): ' + excludeBad.toString() + '\n\n';
|
2016-03-11 02:24:28 -05:00
|
|
|
gutil.log(header);
|
|
|
|
fs.writeFileSync(outputFile, header);
|
2016-03-30 00:23:43 -04:00
|
|
|
|
2016-03-11 02:24:28 -05:00
|
|
|
var siteChecker = new blc.SiteChecker(blcOptions, handlers);
|
|
|
|
var startTime = new Date().getTime();
|
2016-03-30 00:23:43 -04:00
|
|
|
|
|
|
|
try {
|
2016-06-01 03:12:51 -04:00
|
|
|
gutil.log('link checker started');
|
2016-03-11 02:24:28 -05:00
|
|
|
siteChecker.enqueue(siteUrl, customData);
|
|
|
|
} catch (err) {
|
2016-06-01 03:12:51 -04:00
|
|
|
gutil.log('link checker died');
|
|
|
|
console.error('link checker died', err);
|
2016-03-11 02:24:28 -05:00
|
|
|
deferred.reject(err);
|
2016-03-30 00:23:43 -04:00
|
|
|
}
|
|
|
|
return deferred.promise;
|
2016-03-11 02:24:28 -05:00
|
|
|
}
|
|
|
|
|
2016-01-08 20:55:46 -05:00
|
|
|
// harp has issues with node_modules under the public dir
|
|
|
|
// but we need them there for example testing and development
|
|
|
|
// this method allows the node modules folder under '_examples'
|
|
|
|
// to be temporarily moved out from under 'public' while harp
|
|
|
|
// compilation is occurring.
|
|
|
|
function showHideExampleNodeModules(showOrHide) {
|
|
|
|
var nmPath = path.join(EXAMPLES_PATH, "/node_modules");
|
|
|
|
var nmHiddenPath = path.join(TEMP_PATH, "/node_modules");
|
|
|
|
if (showOrHide == 'hide' && fs.existsSync(nmPath)) {
|
|
|
|
if (!fs.existsSync(TEMP_PATH)) {
|
|
|
|
fs.mkdirSync(TEMP_PATH);
|
|
|
|
}
|
|
|
|
fs.renameSync(nmPath, nmHiddenPath);
|
|
|
|
} else if (showOrHide == 'show' && fs.existsSync(nmHiddenPath)) {
|
|
|
|
fs.renameSync(nmHiddenPath, nmPath);
|
|
|
|
fs.rmdirSync(TEMP_PATH);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-26 17:58:13 -04:00
|
|
|
// Show/hide the API docs harp source folder for every lang in skipLangs.
|
|
|
|
function showHideApiDir(showOrHide) {
|
|
|
|
skipLangs.forEach(lang => {
|
|
|
|
_showHideApiDir(lang, showOrHide);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rename the API docs harp source folder for lang to/from 'api' to '_api-tmp-foo'.
|
|
|
|
function _showHideApiDir(lang, showOrHide) {
|
|
|
|
const vers = 'latest';
|
|
|
|
const basePath = path.join(DOCS_PATH, lang, vers);
|
|
|
|
const apiDirPath = path.join(basePath, 'api');
|
|
|
|
const disabledApiDirPath = path.join(basePath, '_api-tmp-hide-from-jade');
|
|
|
|
const args = showOrHide == 'hide'
|
|
|
|
? [apiDirPath, disabledApiDirPath]
|
|
|
|
: [disabledApiDirPath, apiDirPath];
|
|
|
|
renameIfExistsSync(...args);
|
|
|
|
}
|
|
|
|
|
2016-10-03 17:58:50 -04:00
|
|
|
// For each lang in skipLangs, copy the API dir from ${WWW}-backup to WWW.
|
2016-08-26 17:58:13 -04:00
|
|
|
function restoreApiHtml() {
|
|
|
|
const vers = 'latest';
|
|
|
|
skipLangs.forEach(lang => {
|
|
|
|
const relApiDir = path.join('docs', lang, vers, 'api');
|
2016-10-03 17:58:50 -04:00
|
|
|
const apiSubdir = path.join(WWW, relApiDir);
|
|
|
|
const backupApiSubdir = path.join(`${WWW}-backup`, relApiDir);
|
2016-09-13 13:56:18 -04:00
|
|
|
if (fs.existsSync(backupApiSubdir) || argv.forceSkipApi !== true) {
|
2016-10-03 17:58:50 -04:00
|
|
|
gutil.log(`cp ${backupApiSubdir} ${apiSubdir}`)
|
|
|
|
fs.copySync(backupApiSubdir, apiSubdir);
|
2016-09-13 13:56:18 -04:00
|
|
|
}
|
2016-08-26 17:58:13 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-10-03 17:58:50 -04:00
|
|
|
// For each lang in skipLangs, ensure API dir exists in folderName
|
2016-09-06 14:22:29 -04:00
|
|
|
function backupApiHtmlFilesExist(folderName) {
|
|
|
|
const vers = 'latest';
|
|
|
|
var result = 1;
|
|
|
|
skipLangs.forEach(lang => {
|
|
|
|
const relApiDir = path.join('docs', lang, vers, 'api');
|
|
|
|
const backupApiSubdir = path.join(folderName, relApiDir);
|
|
|
|
if (!fs.existsSync(backupApiSubdir)) {
|
|
|
|
gutil.log(`WARNING: API docs HTML folder doesn't exist: ${backupApiSubdir}`);
|
|
|
|
result = 0;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-10-03 17:58:50 -04:00
|
|
|
function harpJsonSetJade2NgTo(v) {
|
|
|
|
const harpJsonPath = path.join(ANGULAR_IO_PROJECT_PATH, 'harp.json');
|
|
|
|
execSync(`perl -pi -e 's/("jade2ng": *)\\w+/$1${v}/' ${harpJsonPath}`);
|
|
|
|
const harpJson = require(harpJsonPath);
|
|
|
|
gutil.log(`jade2ng: ${harpJson.globals.jade2ng}`);
|
|
|
|
}
|
|
|
|
|
2016-06-10 17:10:30 -04:00
|
|
|
// Copies fileNames into destPaths, setting the mode of the
|
|
|
|
// files at the destination as optional_destFileMode if given.
|
2015-12-11 14:59:57 -05:00
|
|
|
// returns a promise
|
2016-06-10 17:10:30 -04:00
|
|
|
function copyFiles(fileNames, destPaths, optional_destFileMode) {
|
2015-12-11 14:59:57 -05:00
|
|
|
var copy = Q.denodeify(fsExtra.copy);
|
2016-06-10 17:10:30 -04:00
|
|
|
var chmod = Q.denodeify(fsExtra.chmod);
|
2015-12-11 14:59:57 -05:00
|
|
|
var copyPromises = [];
|
|
|
|
destPaths.forEach(function(destPath) {
|
|
|
|
fileNames.forEach(function(fileName) {
|
|
|
|
var baseName = path.basename(fileName);
|
|
|
|
var destName = path.join(destPath, baseName);
|
|
|
|
var p = copy(fileName, destName, { clobber: true});
|
2016-06-10 17:10:30 -04:00
|
|
|
if(optional_destFileMode !== undefined) {
|
|
|
|
p = p.then(function () {
|
|
|
|
return chmod(destName, optional_destFileMode);
|
|
|
|
});
|
|
|
|
}
|
2015-12-11 14:59:57 -05:00
|
|
|
copyPromises.push(p);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return Q.all(copyPromises);
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteFiles(baseFileNames, destPaths) {
|
|
|
|
var remove = Q.denodeify(fsExtra.remove);
|
|
|
|
var delPromises = [];
|
|
|
|
destPaths.forEach(function(destPath) {
|
|
|
|
baseFileNames.forEach(function(baseFileName) {
|
|
|
|
var destFileName = path.join(destPath, baseFileName);
|
|
|
|
var p = remove(destFileName);
|
|
|
|
delPromises.push(p);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return Q.all(delPromises);
|
|
|
|
}
|
|
|
|
|
2015-12-20 16:17:16 -05:00
|
|
|
// TODO: filter out all paths that are subdirs of another
|
|
|
|
// path in the result.
|
|
|
|
function getE2eSpecPaths(basePath) {
|
2016-05-30 14:05:09 -04:00
|
|
|
var paths = getPaths(basePath, '*e2e-spec.+(js|ts)', true);
|
2015-12-20 16:17:16 -05:00
|
|
|
return _.uniq(paths);
|
2015-12-11 14:59:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function getNodeModulesPaths(basePath) {
|
|
|
|
var paths = getExamplePaths(basePath).map(function(examplePath) {
|
|
|
|
return path.join(examplePath, "/node_modules");
|
2015-12-07 01:54:43 -05:00
|
|
|
});
|
|
|
|
return paths;
|
|
|
|
}
|
|
|
|
|
2015-12-20 16:17:16 -05:00
|
|
|
function getExamplePaths(basePath, includeBase) {
|
|
|
|
// includeBase defaults to false
|
2016-10-06 18:25:52 -04:00
|
|
|
return getPaths(basePath, _exampleConfigFilename, includeBase);
|
2015-12-20 16:17:16 -05:00
|
|
|
}
|
|
|
|
|
2016-02-27 16:48:24 -05:00
|
|
|
function getDartExampleWebPaths(basePath) {
|
|
|
|
var paths = globby.sync([path.join(basePath,"**/dart/**/web")])
|
|
|
|
return paths;
|
|
|
|
}
|
|
|
|
|
2016-09-24 15:03:08 -04:00
|
|
|
function getUnitTestingPaths(basePath) {
|
|
|
|
var examples = getPaths(basePath, _exampleConfigFilename, true);
|
|
|
|
return examples.filter((example) => {
|
|
|
|
var exampleConfig = fs.readJsonSync(`${example}/${_exampleConfigFilename}`, {throws: false});
|
|
|
|
return exampleConfig && !!exampleConfig.unittesting;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-12-20 16:17:16 -05:00
|
|
|
function getPaths(basePath, filename, includeBase) {
|
|
|
|
var filenames = getFilenames(basePath, filename, includeBase);
|
|
|
|
var paths = filenames.map(function(fileName) {
|
|
|
|
return path.dirname(fileName);
|
|
|
|
});
|
|
|
|
return paths;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getFilenames(basePath, filename, includeBase) {
|
|
|
|
// includeBase defaults to false
|
|
|
|
var includePatterns = [path.join(basePath, "**/" + filename)];
|
|
|
|
if (!includeBase) {
|
|
|
|
// ignore (skip) the top level version.
|
|
|
|
includePatterns.push("!" + path.join(basePath, "/" + filename));
|
|
|
|
}
|
2016-10-06 18:25:52 -04:00
|
|
|
// ignore (skip) the files in BOILERPLATE_PATH.
|
|
|
|
includePatterns.push("!" + path.join(BOILERPLATE_PATH, "/" + filename));
|
2015-12-20 16:17:16 -05:00
|
|
|
var nmPattern = path.join(basePath, "**/node_modules/**");
|
|
|
|
var filenames = globby.sync(includePatterns, {ignore: [nmPattern]});
|
|
|
|
return filenames;
|
|
|
|
}
|
|
|
|
|
2015-11-13 03:38:32 -05:00
|
|
|
function watchAndSync(options, cb) {
|
2016-02-16 20:40:46 -05:00
|
|
|
// Supposedly running in production makes harp faster
|
|
|
|
// and less likely to drown in node_modules.
|
|
|
|
env({
|
|
|
|
vars: { NODE_ENV: "production" }
|
|
|
|
});
|
2016-03-30 00:23:43 -04:00
|
|
|
|
2015-11-13 03:38:32 -05:00
|
|
|
execCommands(['npm run harp -- server .'], {}, cb);
|
|
|
|
|
|
|
|
var browserSync = require('browser-sync').create();
|
2016-09-22 11:44:13 -04:00
|
|
|
browserSync.init(
|
|
|
|
{
|
|
|
|
proxy: 'localhost:9000',
|
|
|
|
scrollRestoreTechnique: 'cookie'
|
|
|
|
});
|
2015-11-13 03:38:32 -05:00
|
|
|
|
2016-09-02 21:54:45 -04:00
|
|
|
// When using the --focus=name flag, only **/name/**/*.* example files and
|
|
|
|
// **/name.jade files are watched. This is useful for performance reasons.
|
2016-09-24 15:03:08 -04:00
|
|
|
// Example: gulp serve-and-sync --focus=architecture
|
2016-09-02 21:54:45 -04:00
|
|
|
var focus = argv.focus;
|
|
|
|
|
2015-11-13 03:38:32 -05:00
|
|
|
if (options.devGuide) {
|
2016-09-02 21:54:45 -04:00
|
|
|
devGuideExamplesWatch(_devguideShredOptions, browserSync.reload, focus);
|
2015-11-13 03:38:32 -05:00
|
|
|
}
|
2016-01-19 05:11:58 -05:00
|
|
|
if (options.devGuideJade) {
|
2016-09-02 21:54:45 -04:00
|
|
|
devGuideSharedJadeWatch( { jadeDir: DOCS_PATH}, browserSync.reload, focus);
|
2016-01-19 05:11:58 -05:00
|
|
|
}
|
2015-11-13 03:38:32 -05:00
|
|
|
if (options.apiDocs) {
|
|
|
|
apiSourceWatch(browserSync.reload);
|
|
|
|
}
|
|
|
|
if (options.apiExamples) {
|
2015-11-13 04:37:43 -05:00
|
|
|
apiExamplesWatch(browserSync.reload);
|
2015-11-13 03:38:32 -05:00
|
|
|
}
|
|
|
|
if (options.localFiles) {
|
|
|
|
gulp.watch(NOT_API_DOCS_GLOB, browserSync.reload);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-25 04:28:36 -04:00
|
|
|
// returns a promise;
|
|
|
|
function askDeploy() {
|
2016-11-02 19:16:35 -04:00
|
|
|
// Show user what the currently active firebase project is:
|
|
|
|
execSync('firebase use', {stdio:[0,1,2]});
|
2015-09-25 04:28:36 -04:00
|
|
|
prompt.start();
|
|
|
|
var schema = {
|
|
|
|
name: 'shouldDeploy',
|
2016-11-02 19:16:35 -04:00
|
|
|
description: `Deploy ${WWW} to firebase? (y/n)`,
|
2015-09-25 04:28:36 -04:00
|
|
|
type: 'string',
|
|
|
|
pattern: /Y|N|y|n/,
|
|
|
|
message: "Respond with either a 'y' or 'n'",
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
var getPromise = Q.denodeify(prompt.get);
|
|
|
|
return getPromise([schema]).then(function(result) {
|
|
|
|
return result.shouldDeploy.toLowerCase() === 'y';
|
|
|
|
});
|
|
|
|
}
|
2015-09-18 22:51:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
function filterOutExcludedPatterns(fileNames, excludeMatchers) {
|
|
|
|
return fileNames.filter(function(fileName) {
|
|
|
|
return !excludeMatchers.some(function(excludeMatcher) {
|
|
|
|
return excludeMatcher.match(fileName);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-11-13 03:38:32 -05:00
|
|
|
function apiSourceWatch(postBuildAction) {
|
2016-09-07 19:54:11 -04:00
|
|
|
var srcPattern = [path.join(ANGULAR_PROJECT_PATH, 'modules/@angular/**/*.*')];
|
2015-11-14 05:56:41 -05:00
|
|
|
gulp.watch(srcPattern, {readDelay: 500}, function (event, done) {
|
2015-11-13 04:35:05 -05:00
|
|
|
gutil.log('API source changed');
|
|
|
|
gutil.log('Event type: ' + event.event); // added, changed, or deleted
|
|
|
|
gutil.log('Event path: ' + event.path); // The path of the modified file
|
2015-11-13 03:38:32 -05:00
|
|
|
|
2015-11-13 04:37:43 -05:00
|
|
|
return Q.all([buildApiDocs('ts'), buildApiDocs('js')]).then(postBuildAction);
|
2015-09-18 22:51:10 -04:00
|
|
|
});
|
2015-11-13 03:38:32 -05:00
|
|
|
}
|
|
|
|
|
2015-11-13 04:37:43 -05:00
|
|
|
function apiExamplesWatch(postShredAction) {
|
2016-05-25 14:49:11 -04:00
|
|
|
var examplesPath = path.join(ANGULAR_PROJECT_PATH, 'modules/@angular/examples/**');
|
2015-11-14 05:56:41 -05:00
|
|
|
var includePattern = path.join(examplesPath, '**/*.*');
|
|
|
|
var excludePattern = '!' + path.join(examplesPath, '**/node_modules/**/*.*');
|
2015-11-13 03:38:32 -05:00
|
|
|
var cleanPath = [path.join(_apiShredOptions.fragmentsDir, '**/*.*'), '!**/*.ovr.*'];
|
|
|
|
|
2015-11-14 05:56:41 -05:00
|
|
|
gulp.watch([includePattern, excludePattern], {readDelay: 500}, function (event, done) {
|
2015-11-13 04:35:05 -05:00
|
|
|
gutil.log('API example changed');
|
2015-11-14 05:56:41 -05:00
|
|
|
gutil.log('Event type: ' + event.type); // added, changed, or deleted
|
2015-11-13 04:35:05 -05:00
|
|
|
gutil.log('Event path: ' + event.path); // The path of the modified file
|
2015-11-13 03:38:32 -05:00
|
|
|
|
2016-06-05 17:46:52 -04:00
|
|
|
return del(cleanPath).then(function() {
|
2015-09-18 22:51:10 -04:00
|
|
|
return docShredder.shred(_apiShredOptions);
|
2015-11-13 03:38:32 -05:00
|
|
|
}).then(postShredAction);
|
2015-09-18 22:51:10 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-09-02 21:54:45 -04:00
|
|
|
function devGuideExamplesWatch(shredOptions, postShredAction, focus) {
|
2016-09-29 14:15:55 -04:00
|
|
|
var watchPattern = focus ? '**/{' + focus + ',cb-' + focus+ '}/**/*.*' : '**/*.*';
|
2016-09-02 21:54:45 -04:00
|
|
|
var includePattern = path.join(shredOptions.examplesDir, watchPattern);
|
2016-03-30 00:23:43 -04:00
|
|
|
// removed this version because gulp.watch has the same glob issue that dgeni has.
|
2016-02-16 12:16:17 -05:00
|
|
|
// var excludePattern = '!' + path.join(shredOptions.examplesDir, '**/node_modules/**/*.*');
|
2015-12-10 02:56:24 -05:00
|
|
|
// gulp.watch([includePattern, excludePattern], {readDelay: 500}, function (event, done) {
|
2016-10-20 20:01:16 -04:00
|
|
|
var ignoreThese = [ '**/node_modules/**', '**/_fragments/**', '**/dist/**',
|
2016-06-08 11:54:43 -04:00
|
|
|
'**/dart/.pub/**', '**/dart/build/**', '**/dart/packages/**'];
|
2016-06-19 21:12:42 -04:00
|
|
|
ignoreThese = ignoreThese.concat(_exampleBoilerplateFiles.map((file) => `public/docs/_examples/*/*/${file}`));
|
2016-06-08 11:54:43 -04:00
|
|
|
var files = globby.sync( [includePattern], { ignore: ignoreThese });
|
2015-12-10 02:56:24 -05:00
|
|
|
gulp.watch([files], {readDelay: 500}, function (event, done) {
|
2015-11-13 04:37:43 -05:00
|
|
|
gutil.log('Dev Guide example changed')
|
2015-11-14 05:56:41 -05:00
|
|
|
gutil.log('Event type: ' + event.type); // added, changed, or deleted
|
2015-11-13 04:37:43 -05:00
|
|
|
gutil.log('Event path: ' + event.path); // The path of the modified file
|
|
|
|
return docShredder.shredSingleDir(shredOptions, event.path).then(postShredAction);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-09-02 21:54:45 -04:00
|
|
|
function devGuideSharedJadeWatch(shredOptions, postShredAction, focus) {
|
|
|
|
var watchPattern = focus ? '**/' + focus + '.jade' : '**/*.jade';
|
|
|
|
var includePattern = path.join(DOCS_PATH, watchPattern);
|
2016-01-19 05:11:58 -05:00
|
|
|
// removed this version because gulp.watch has the same glob issue that dgeni has.
|
2016-01-20 14:59:40 -05:00
|
|
|
// var excludePattern = '!' + path.join(shredOptions.jadeDir, '**/node_modules/**/*.*');
|
2016-01-19 05:11:58 -05:00
|
|
|
// gulp.watch([includePattern, excludePattern], {readDelay: 500}, function (event, done) {
|
2016-06-19 21:12:42 -04:00
|
|
|
var ignoreThese = [ '**/node_modules/**', '**/_examples/**', '**/_fragments/**', '**/latest/api/**' ];
|
|
|
|
var files = globby.sync( [includePattern], { ignore: ignoreThese});
|
2016-01-19 05:11:58 -05:00
|
|
|
gulp.watch([files], {readDelay: 500}, function (event, done) {
|
|
|
|
gutil.log('Dev Guide jade file changed')
|
|
|
|
gutil.log('Event type: ' + event.type); // added, changed, or deleted
|
|
|
|
gutil.log('Event path: ' + event.path); // The path of the modified file
|
|
|
|
return docShredder.shredSingleJadeDir(shredOptions, event.path).then(postShredAction);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-11-13 04:37:43 -05:00
|
|
|
|
2015-11-06 16:40:30 -05:00
|
|
|
// Generate the API docs for the specified language, if not specified then it defaults to ts
|
|
|
|
function buildApiDocs(targetLanguage) {
|
2015-12-08 15:23:43 -05:00
|
|
|
var ALLOWED_LANGUAGES = ['ts', 'js', 'dart'];
|
|
|
|
var GENERATE_API_LANGUAGES = ['ts', 'js'];
|
2015-11-06 16:40:30 -05:00
|
|
|
checkAngularProjectPath();
|
2015-09-16 02:21:55 -04:00
|
|
|
try {
|
2015-11-06 16:40:30 -05:00
|
|
|
// Build a specialized package to generate different versions of the API docs
|
|
|
|
var package = new Package('apiDocs', [require(path.resolve(TOOLS_PATH, 'api-builder/angular.io-package'))]);
|
2016-07-08 00:35:40 -04:00
|
|
|
package.config(function(log, targetEnvironments, writeFilesProcessor, readTypeScriptModules, linkDocsInlineTagDef) {
|
2016-07-04 11:56:14 -04:00
|
|
|
log.level = _dgeniLogLevel;
|
2015-11-06 16:40:30 -05:00
|
|
|
ALLOWED_LANGUAGES.forEach(function(target) { targetEnvironments.addAllowed(target); });
|
|
|
|
if (targetLanguage) {
|
|
|
|
targetEnvironments.activate(targetLanguage);
|
2015-12-08 15:23:43 -05:00
|
|
|
|
|
|
|
if (GENERATE_API_LANGUAGES.indexOf(targetLanguage) === -1) {
|
|
|
|
// Don't read TypeScript modules if we are not generating API docs - Dart I am looking at you!
|
|
|
|
readTypeScriptModules.$enabled = false;
|
|
|
|
}
|
2016-07-08 00:35:40 -04:00
|
|
|
linkDocsInlineTagDef.lang = targetLanguage;
|
|
|
|
linkDocsInlineTagDef.vers = 'latest';
|
|
|
|
writeFilesProcessor.outputFolder = path.join(targetLanguage, linkDocsInlineTagDef.vers, 'api');
|
2015-11-06 16:40:30 -05:00
|
|
|
}
|
2015-11-04 05:55:02 -05:00
|
|
|
});
|
2015-11-06 16:40:30 -05:00
|
|
|
|
|
|
|
var dgeni = new Dgeni([package]);
|
|
|
|
return dgeni.generate();
|
2015-09-18 15:41:20 -04:00
|
|
|
} catch(err) {
|
2016-07-15 17:10:12 -04:00
|
|
|
console.error(err);
|
|
|
|
console.error(err.stack);
|
2015-09-18 15:41:20 -04:00
|
|
|
throw err;
|
2015-09-16 02:21:55 -04:00
|
|
|
}
|
2015-09-18 22:51:10 -04:00
|
|
|
}
|
2015-09-16 02:21:55 -04:00
|
|
|
|
2016-07-15 17:10:12 -04:00
|
|
|
|
2016-07-19 15:35:39 -04:00
|
|
|
function buildDartCheatsheet() {
|
|
|
|
'use strict';
|
|
|
|
const ALLOWED_LANGUAGES = ['ts', 'js', 'dart'];
|
|
|
|
const lang = 'dart';
|
|
|
|
const vers = 'latest';
|
|
|
|
checkAngularProjectPath(ngPathFor(lang));
|
|
|
|
try {
|
|
|
|
const pkg = new Package('dartApiDocs', [require(path.resolve(TOOLS_PATH, 'dart-api-builder'))]);
|
|
|
|
pkg.config(function(log, targetEnvironments, writeFilesProcessor) {
|
|
|
|
log.level = _dgeniLogLevel;
|
|
|
|
ALLOWED_LANGUAGES.forEach(function(target) { targetEnvironments.addAllowed(target); });
|
|
|
|
targetEnvironments.activate(lang);
|
|
|
|
const outputPath = path.join(lang, vers, 'can-be-any-name-read-comment-below');
|
|
|
|
// Note: cheatsheet data gets written to: outputPath + '/../guide';
|
|
|
|
writeFilesProcessor.outputFolder = outputPath;
|
|
|
|
});
|
|
|
|
var dgeni = new Dgeni([pkg]);
|
|
|
|
return dgeni.generate();
|
|
|
|
} catch(err) {
|
|
|
|
console.error(err);
|
|
|
|
console.error(err.stack);
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-15 17:10:12 -04:00
|
|
|
function buildApiDocsForDart() {
|
|
|
|
const vers = 'latest';
|
|
|
|
const dab = require('./tools/dart-api-builder/dab')(ANGULAR_IO_PROJECT_PATH);
|
|
|
|
const log = dab.log;
|
|
|
|
|
|
|
|
log.level = _dgeniLogLevel;
|
|
|
|
const dabInfo = dab.dartPkgConfigInfo;
|
2016-08-10 13:36:23 -04:00
|
|
|
dabInfo.ngIoDartApiDocPath = path.join(DOCS_PATH, 'dart', vers, 'api');
|
2016-08-24 16:54:04 -04:00
|
|
|
dabInfo.ngDartDocPath = path.join(ngPathFor('dart'), relDartDocApiDir);
|
2016-07-15 17:10:12 -04:00
|
|
|
// Exclude API entries for developer/internal libraries. Also exclude entries for
|
|
|
|
// the top-level catch all "angular2" library (otherwise every entry appears twice).
|
2016-10-20 17:29:08 -04:00
|
|
|
dabInfo.excludeLibRegExp = new RegExp(/^(?!angular2)|testing|_|codegen|^angular2$/);
|
2016-07-15 17:10:12 -04:00
|
|
|
|
|
|
|
try {
|
2016-07-18 14:35:57 -04:00
|
|
|
checkAngularProjectPath(ngPathFor('dart'));
|
2016-07-15 17:10:12 -04:00
|
|
|
var destPath = dabInfo.ngIoDartApiDocPath;
|
|
|
|
var sourceDirs = fs.readdirSync(dabInfo.ngDartDocPath)
|
2016-10-20 17:29:08 -04:00
|
|
|
.filter(name => !name.match(/^index|^(?!angular2)|testing|codegen/))
|
|
|
|
.map(name => path.join(dabInfo.ngDartDocPath, name));
|
2016-07-15 17:10:12 -04:00
|
|
|
log.info(`Building Dart API pages for ${sourceDirs.length} libraries`);
|
|
|
|
|
|
|
|
return copyFiles(sourceDirs, [destPath]).then(() => {
|
|
|
|
log.debug('Finished copying', sourceDirs.length, 'directories from', dabInfo.ngDartDocPath, 'to', destPath);
|
|
|
|
|
|
|
|
const apiEntries = dab.loadApiDataAndSaveToApiListFile();
|
|
|
|
const tmpDocsPath = path.resolve(path.join(process.env.HOME, 'tmp/docs.json'));
|
|
|
|
if (argv.dumpDocsJson) fs.writeFileSync(tmpDocsPath, JSON.stringify(apiEntries, null, 2));
|
|
|
|
dab.createApiDataAndJadeFiles(apiEntries);
|
|
|
|
}).catch((err) => {
|
2016-07-15 05:59:23 -04:00
|
|
|
console.error(err);
|
2016-07-15 17:10:12 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
} catch(err) {
|
|
|
|
console.error(err);
|
|
|
|
console.error(err.stack);
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-08 16:55:53 -04:00
|
|
|
function buildShredMaps(shouldWrite) {
|
2015-09-18 22:51:10 -04:00
|
|
|
var options = {
|
|
|
|
devguideExamplesDir: _devguideShredOptions.examplesDir,
|
|
|
|
apiExamplesDir: _apiShredOptions.examplesDir,
|
|
|
|
fragmentsDir: _devguideShredOptions.fragmentsDir,
|
2015-09-18 15:41:20 -04:00
|
|
|
jadeDir: './public/docs',
|
|
|
|
outputDir: './public/docs',
|
2016-07-04 11:56:14 -04:00
|
|
|
writeFilesEnabled: shouldWrite,
|
|
|
|
logLevel: _dgeniLogLevel
|
2015-09-18 22:51:10 -04:00
|
|
|
};
|
2015-08-08 16:55:53 -04:00
|
|
|
return docShredder.buildShredMap(options).then(function(docs) {
|
|
|
|
return docs;
|
2015-08-11 03:27:09 -04:00
|
|
|
});
|
2015-08-08 16:55:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// returns a promise containing filePaths with any changed or added examples;
|
|
|
|
function getChangedExamples(sha) {
|
2015-10-16 17:35:58 -04:00
|
|
|
var Git = require("nodegit");
|
2015-09-18 22:51:10 -04:00
|
|
|
var examplesPath = _devguideShredOptions.examplesDir;
|
2015-08-08 16:55:53 -04:00
|
|
|
var relativePath = path.relative(process.cwd(), examplesPath);
|
|
|
|
return Git.Repository.open(".").then(function(repo) {
|
2015-09-12 03:28:01 -04:00
|
|
|
if (sha.length) {
|
2015-08-08 16:55:53 -04:00
|
|
|
return repo.getCommit(sha);
|
|
|
|
} else {
|
|
|
|
return repo.getHeadCommit();
|
|
|
|
}
|
|
|
|
}).then(function(commit) {
|
2015-09-12 03:28:01 -04:00
|
|
|
return getChangedExamplesForCommit(commit, relativePath);
|
|
|
|
}).catch(function(err) {
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function getChangedExamplesAfter(date, relativePath) {
|
2015-10-16 17:35:58 -04:00
|
|
|
var Git = require("nodegit");
|
2015-09-18 22:51:10 -04:00
|
|
|
var examplesPath = _devguideShredOptions.examplesDir;
|
2015-09-12 03:28:01 -04:00
|
|
|
var relativePath = path.relative(process.cwd(), examplesPath);
|
|
|
|
return Git.Repository.open(".").then(function(repo) {
|
|
|
|
return repo.getHeadCommit();
|
|
|
|
}).then(function(commit) {
|
|
|
|
var repo = commit.owner();
|
|
|
|
var revWalker = repo.createRevWalk();
|
|
|
|
revWalker.sorting(Git.Revwalk.SORT.TIME);
|
|
|
|
revWalker.push(commit.id());
|
|
|
|
return revWalker.getCommitsUntil(function (commit) {
|
|
|
|
return commit.date().getTime() > date.getTime();
|
|
|
|
});
|
|
|
|
}).then(function(commits) {
|
|
|
|
return Q.all(commits.map(function(commit) {
|
|
|
|
return getChangedExamplesForCommit(commit, relativePath);
|
|
|
|
}));
|
|
|
|
}).then(function(arrayOfPaths) {
|
|
|
|
var pathMap = {};
|
|
|
|
arrayOfPaths.forEach(function(paths) {
|
|
|
|
paths.forEach(function(path) {
|
|
|
|
pathMap[path] = true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
var uniqPaths = _.keys(pathMap);
|
|
|
|
return uniqPaths;
|
|
|
|
}).catch(function(err) {
|
|
|
|
var x = err;
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function getChangedExamplesForCommit(commit, relativePath) {
|
|
|
|
return commit.getDiff().then(function(diffList) {
|
2015-08-08 16:55:53 -04:00
|
|
|
var filePaths = [];
|
2015-09-12 03:28:01 -04:00
|
|
|
diffList.forEach(function (diff) {
|
2016-06-02 09:27:04 -04:00
|
|
|
diff.patches().then(function (patch) {
|
2015-08-08 16:55:53 -04:00
|
|
|
if (patch.isAdded() || patch.isModified) {
|
|
|
|
var filePath = path.normalize(patch.newFile().path());
|
|
|
|
var isExample = filePath.indexOf(relativePath) >= 0;
|
2015-11-13 04:35:05 -05:00
|
|
|
// gutil.log(filePath + " isExample: " + isExample);
|
2015-08-08 16:55:53 -04:00
|
|
|
if (isExample) {
|
|
|
|
filePaths.push(filePath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return filePaths;
|
|
|
|
});
|
|
|
|
}
|
2015-08-11 03:27:09 -04:00
|
|
|
|
2015-09-18 22:51:10 -04:00
|
|
|
|
2015-08-03 20:45:58 -04:00
|
|
|
|
2015-09-12 03:28:01 -04:00
|
|
|
function jadeShredMapToJadeExampleMap(jadeShredMap, examplePaths) {
|
2015-09-18 15:41:20 -04:00
|
|
|
// remove dups in examplePaths
|
2015-09-12 03:28:01 -04:00
|
|
|
var exampleSet = {};
|
|
|
|
examplePaths.forEach(function(examplePath) {
|
|
|
|
exampleSet[examplePath] = examplePath;
|
|
|
|
});
|
2015-09-18 15:41:20 -04:00
|
|
|
var basePath = path.resolve(".");
|
2015-09-12 03:28:01 -04:00
|
|
|
var jadeToFragMap = jadeShredMap.jadeToFragMap;
|
|
|
|
var jadeExampleMap = {};
|
|
|
|
for (var jadePath in jadeToFragMap) {
|
2015-09-18 15:41:20 -04:00
|
|
|
var relativeJadePath = path.relative(basePath, jadePath);
|
2015-09-12 03:28:01 -04:00
|
|
|
var vals = jadeToFragMap[jadePath];
|
|
|
|
vals.forEach(function(val) {
|
2015-09-18 15:41:20 -04:00
|
|
|
var relativeExamplePath = path.relative(basePath, val.examplePath);
|
|
|
|
if (exampleSet[relativeExamplePath] != null) {
|
|
|
|
addKeyValue(jadeExampleMap, relativeJadePath, relativeExamplePath);
|
2015-09-12 03:28:01 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return jadeExampleMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
function jadeShredMapToExampleJadeMap(jadeShredMap) {
|
2015-09-18 15:41:20 -04:00
|
|
|
|
2015-09-12 03:28:01 -04:00
|
|
|
var jadeToFragMap = jadeShredMap.jadeToFragMap;
|
|
|
|
var exampleJadeMap = {};
|
|
|
|
for (var jadePath in jadeToFragMap) {
|
|
|
|
var vals = jadeToFragMap[jadePath];
|
|
|
|
vals.forEach(function(val) {
|
2015-09-18 15:41:20 -04:00
|
|
|
var examplePath = val.examplePath;
|
|
|
|
addKeyValue(exampleJadeMap, examplePath, jadePath);
|
2015-09-12 03:28:01 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
return exampleJadeMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
function addKeyValue(map, key, value) {
|
|
|
|
var vals = map[key];
|
|
|
|
if (vals) {
|
|
|
|
if (vals.indexOf(value) == -1) {
|
|
|
|
vals.push(value);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
map[key] = [value];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-07 01:54:43 -05:00
|
|
|
|
2015-09-18 15:41:20 -04:00
|
|
|
// Synchronously execute a chain of commands.
|
|
|
|
// cmds: an array of commands
|
|
|
|
// options: { shouldLog: true, shouldThrow: true }
|
|
|
|
// cb: function(err, stdout, stderr)
|
2015-08-03 20:45:58 -04:00
|
|
|
function execCommands(cmds, options, cb) {
|
|
|
|
options = options || {};
|
|
|
|
options.shouldThrow = options.shouldThrow == null ? true : options.shouldThrow;
|
|
|
|
options.shouldLog = options.shouldLog == null ? true : options.shouldLog;
|
|
|
|
if (!cmds || cmds.length == 0) cb(null, null, null);
|
|
|
|
var exec = require('child_process').exec; // just to make it more portable.
|
2016-02-16 20:40:46 -05:00
|
|
|
gutil.log("NODE_ENV: " + process.env.NODE_ENV);
|
2016-03-30 00:23:43 -04:00
|
|
|
|
2015-08-03 20:45:58 -04:00
|
|
|
exec(cmds[0], options, function(err, stdout, stderr) {
|
|
|
|
if (err == null) {
|
|
|
|
if (options.shouldLog) {
|
|
|
|
gutil.log('cmd: ' + cmds[0]);
|
|
|
|
gutil.log('stdout: ' + stdout);
|
|
|
|
}
|
|
|
|
if (cmds.length == 1) {
|
|
|
|
cb(err, stdout, stderr);
|
|
|
|
} else {
|
|
|
|
execCommands(cmds.slice(1), options, cb);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (options.shouldLog) {
|
|
|
|
gutil.log('exec error on cmd: ' + cmds[0]);
|
|
|
|
gutil.log('exec error: ' + err);
|
|
|
|
if (stdout) gutil.log('stdout: ' + stdout);
|
|
|
|
if (stderr) gutil.log('stderr: ' + stderr);
|
|
|
|
}
|
|
|
|
if (err && options.shouldThrow) throw err;
|
|
|
|
cb(err, stdout, stderr);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-07-15 17:10:12 -04:00
|
|
|
function ngPathFor(lang) {
|
|
|
|
return ANGULAR_PROJECT_PATH + (lang === 'dart' ? '-dart' : '');
|
|
|
|
}
|
|
|
|
|
2016-07-18 14:35:57 -04:00
|
|
|
function checkAngularProjectPath(_ngPath) {
|
|
|
|
var ngPath = path.resolve(_ngPath || ngPathFor('ts'));
|
|
|
|
if (fs.existsSync(ngPath)) return;
|
|
|
|
throw new Error('API related tasks require the angular2 repo to be at ' + ngPath);
|
2015-11-06 16:40:30 -05:00
|
|
|
}
|
2016-08-10 13:36:23 -04:00
|
|
|
|
|
|
|
function renameIfExistsSync(oldPath, newPath) {
|
|
|
|
if (fs.existsSync(oldPath)) {
|
2016-08-26 17:58:13 -04:00
|
|
|
gutil.log(`Rename: mv ${oldPath} ${newPath}`);
|
|
|
|
fs.renameSync(oldPath, newPath);
|
2016-08-10 13:36:23 -04:00
|
|
|
} else {
|
2016-08-26 17:58:13 -04:00
|
|
|
gutil.log(`renameIfExistsSync cannot rename, path not found: ${oldPath}`);
|
2016-08-10 13:36:23 -04:00
|
|
|
}
|
|
|
|
}
|