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");
|
2015-09-18 22:51:10 -04:00
|
|
|
// delPromise is a 'promise' version of del
|
|
|
|
var delPromise = Q.denodeify(del);
|
2015-09-12 03:28:01 -04:00
|
|
|
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);
|
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");
|
2015-09-16 02:21:55 -04:00
|
|
|
|
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';
|
|
|
|
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');
|
2015-11-12 17:16:46 -05: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');
|
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'));
|
2015-11-22 23:56:28 -05:00
|
|
|
var plunkerBuilder = require(path.resolve(TOOLS_PATH, 'plunker-builder/plunkerBuilder'));
|
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
|
|
|
|
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'),
|
|
|
|
zipDir: path.join(RESOURCES_PATH, 'zips')
|
2015-08-03 20:45:58 -04:00
|
|
|
};
|
|
|
|
|
2016-01-19 05:11:58 -05:00
|
|
|
var _devguideShredJadeOptions = {
|
|
|
|
jadeDir: DOCS_PATH
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2015-09-18 22:51:10 -04:00
|
|
|
var _apiShredOptions = {
|
2015-11-04 05:55:02 -05:00
|
|
|
examplesDir: path.join(ANGULAR_PROJECT_PATH, 'modules/angular2/examples'),
|
|
|
|
fragmentsDir: path.join(DOCS_PATH, '_fragments/_api'),
|
|
|
|
zipDir: path.join(RESOURCES_PATH, 'zips/api')
|
2015-09-18 22:51:10 -04:00
|
|
|
};
|
|
|
|
|
2015-10-14 20:12:31 -04:00
|
|
|
var _excludePatterns = ['**/node_modules/**', '**/typings/**', '**/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-11 18:08:06 -05:00
|
|
|
var _exampleBoilerplateFiles = ['package.json', 'tsconfig.json', 'typings.json', 'karma.conf.js', 'karma-test-shim.js' ];
|
2015-12-07 01:54:43 -05:00
|
|
|
|
2015-12-20 16:17:16 -05:00
|
|
|
// --filter may be passed in to filter/select _example app subdir names
|
|
|
|
// i.e. gulp run-e2e-tests --filter=foo ; would select all example apps with
|
|
|
|
// 'foo' in their folder names.
|
|
|
|
gulp.task('run-e2e-tests', function() {
|
|
|
|
var spawnInfo = spawnExt('npm', ['install'], { cwd: EXAMPLES_PATH});
|
|
|
|
return spawnInfo.promise.then(function() {
|
|
|
|
copyExampleBoilerplate();
|
|
|
|
var exePath = path.join(process.cwd(), "./node_modules/.bin/");
|
|
|
|
spawnInfo = spawnExt('webdriver-manager', ['update'], {cwd: exePath});
|
|
|
|
return spawnInfo.promise;
|
2016-01-03 14:32:57 -05:00
|
|
|
}).then(function() {
|
2015-12-20 16:17:16 -05:00
|
|
|
return findAndRunE2eTests(argv.filter);
|
2016-01-03 14:32:57 -05:00
|
|
|
}).then(function(status) {
|
|
|
|
reportStatus(status);
|
2015-12-20 16:17:16 -05:00
|
|
|
}).fail(function(e) {
|
|
|
|
return e;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
function findAndRunE2eTests(filter) {
|
2016-01-03 14:32:57 -05:00
|
|
|
var startTime = new Date().getTime();
|
2015-12-20 16:17:16 -05:00
|
|
|
// create an output file with header.
|
|
|
|
var outputFile = path.join(process.cwd(), 'protractor-results.txt');
|
|
|
|
var header = "Protractor example results for: " + (new Date()).toLocaleString() + "\n\n";
|
|
|
|
if (filter) {
|
|
|
|
header += ' Filter: ' + filter.toString() + '\n\n';
|
|
|
|
}
|
|
|
|
fs.writeFileSync(outputFile, header);
|
|
|
|
|
|
|
|
// create an array of combos where each
|
|
|
|
// combo consists of { examplePath: ... , protractorConfigFilename: ... }
|
|
|
|
var exeConfigs = [];
|
|
|
|
var e2eSpecPaths = getE2eSpecPaths(EXAMPLES_PATH);
|
|
|
|
var srcConfig = path.join(EXAMPLES_PATH, 'protractor.config.js');
|
|
|
|
e2eSpecPaths.forEach(function(specPath) {
|
|
|
|
var destConfig = path.join(specPath, 'protractor.config.js');
|
|
|
|
fsExtra.copySync(srcConfig, destConfig);
|
|
|
|
// get all of the examples under each dir where a pcFilename is found
|
|
|
|
examplePaths = getExamplePaths(specPath, true);
|
|
|
|
if (filter) {
|
|
|
|
examplePaths = examplePaths.filter(function (fn) {
|
|
|
|
return fn.match(filter) != null;
|
|
|
|
})
|
|
|
|
}
|
|
|
|
examplePaths.forEach(function(exPath) {
|
|
|
|
exeConfigs.push( { examplePath: exPath, protractorConfigFilename: destConfig });
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
// run the tests sequentially
|
2016-01-03 14:32:57 -05:00
|
|
|
var status = { passed: [], failed: [] };
|
2015-12-20 16:17:16 -05:00
|
|
|
return exeConfigs.reduce(function (promise, combo) {
|
|
|
|
return promise.then(function () {
|
2016-01-03 14:32:57 -05:00
|
|
|
return runE2eTests(combo.examplePath, combo.protractorConfigFilename, outputFile).then(function(ok) {
|
|
|
|
var arr = ok ? status.passed : status.failed;
|
|
|
|
arr.push(combo.examplePath);
|
|
|
|
})
|
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;
|
|
|
|
fs.appendFileSync(outputFile, '\nElaped Time: ' + status.elapsedTime + ' seconds');
|
|
|
|
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.
|
|
|
|
function runE2eTests(appDir, protractorConfigFilename, outputFile ) {
|
|
|
|
// start the app
|
|
|
|
var appRunSpawnInfo = spawnExt('npm',['run','http-server', '--', '-s' ], { cwd: appDir });
|
|
|
|
|
|
|
|
// start protractor
|
|
|
|
var pcFilename = path.resolve(protractorConfigFilename); // need to resolve because we are going to be running from a different dir
|
|
|
|
var exePath = path.join(process.cwd(), "./node_modules/.bin/");
|
|
|
|
var spawnInfo = spawnExt('protractor',
|
|
|
|
[ pcFilename, '--params.appDir=' + appDir, '--params.outputFile=' + outputFile], { cwd: exePath });
|
|
|
|
return spawnInfo.promise.then(function(data) {
|
|
|
|
// kill the app now that protractor has completed.
|
|
|
|
// Ugh... proc.kill does not work properly on windows with child processes.
|
|
|
|
// appRun.proc.kill();
|
2016-01-03 14:32:57 -05:00
|
|
|
treeKill(appRunSpawnInfo.proc.pid);
|
|
|
|
return true;
|
2015-12-20 16:17:16 -05:00
|
|
|
}).fail(function(err) {
|
|
|
|
// Ugh... proc.kill does not work properly on windows with child processes.
|
|
|
|
// appRun.proc.kill();
|
2016-01-03 14:32:57 -05:00
|
|
|
treeKill(appRunSpawnInfo.proc.pid);
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function reportStatus(status) {
|
|
|
|
gutil.log('Suites passed:');
|
|
|
|
status.passed.forEach(function(val) {
|
|
|
|
gutil.log(' ' + val);
|
|
|
|
});
|
|
|
|
|
|
|
|
gutil.log('Suites failed:');
|
|
|
|
status.failed.forEach(function(val) {
|
|
|
|
gutil.log(' ' + val);
|
2015-12-20 16:17:16 -05:00
|
|
|
});
|
2016-01-03 14:32:57 -05:00
|
|
|
|
|
|
|
if (status.failed.length == 0) {
|
|
|
|
gutil.log('All tests passed');
|
|
|
|
}
|
|
|
|
gutil.log('Elapsed time: ' + status.elapsedTime + ' seconds');
|
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());
|
|
|
|
});
|
|
|
|
proc.on('close', function (data) {
|
|
|
|
gutil.log('completed: ' + descr);
|
|
|
|
deferred.resolve(data);
|
|
|
|
});
|
|
|
|
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;
|
|
|
|
}));
|
|
|
|
|
2015-12-11 14:59:57 -05:00
|
|
|
// requires admin access
|
2015-12-20 16:17:16 -05:00
|
|
|
gulp.task('add-example-boilerplate', function() {
|
2015-12-07 01:54:43 -05:00
|
|
|
var realPath = path.join(EXAMPLES_PATH, '/node_modules');
|
|
|
|
var nodeModulesPaths = getNodeModulesPaths(EXAMPLES_PATH);
|
|
|
|
|
|
|
|
nodeModulesPaths.forEach(function(linkPath) {
|
|
|
|
gutil.log("symlinking " + linkPath + ' -> ' + realPath)
|
|
|
|
fsUtils.addSymlink(realPath, linkPath);
|
|
|
|
});
|
2016-02-11 18:08:06 -05:00
|
|
|
|
|
|
|
realPath = path.join(EXAMPLES_PATH, '/typings');
|
|
|
|
var typingsPaths = getTypingsPaths(EXAMPLES_PATH);
|
|
|
|
typingsPaths.forEach(function(linkPath) {
|
|
|
|
gutil.log("symlinking " + linkPath + ' -> ' + realPath)
|
|
|
|
fsUtils.addSymlink(realPath, linkPath);
|
|
|
|
});
|
|
|
|
|
2015-12-20 16:17:16 -05:00
|
|
|
copyExampleBoilerplate();
|
|
|
|
});
|
|
|
|
|
|
|
|
// copies boilerplate files to locations
|
|
|
|
// where an example app is found
|
|
|
|
// also copies protractor.config.js file
|
|
|
|
function copyExampleBoilerplate() {
|
2015-12-11 14:59:57 -05:00
|
|
|
var sourceFiles = _exampleBoilerplateFiles.map(function(fn) {
|
|
|
|
return path.join(EXAMPLES_PATH, fn);
|
|
|
|
});
|
|
|
|
var examplePaths = getExamplePaths(EXAMPLES_PATH);
|
2015-12-20 16:17:16 -05:00
|
|
|
// copies protractor.config.js from _examples dir to each subdir that
|
|
|
|
// contains a e2e-spec file.
|
|
|
|
return copyFiles(sourceFiles, examplePaths).then(function() {
|
|
|
|
var sourceFiles = [ path.join(EXAMPLES_PATH, 'protractor.config.js') ];
|
|
|
|
var e2eSpecPaths = getE2eSpecPaths(EXAMPLES_PATH);
|
|
|
|
return copyFiles(sourceFiles, e2eSpecPaths);
|
|
|
|
});
|
|
|
|
}
|
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-02-11 18:08:06 -05:00
|
|
|
|
|
|
|
var typingsPaths = getTypingsPaths(EXAMPLES_PATH);
|
|
|
|
typingsPaths.forEach(function(linkPath) {
|
|
|
|
fsUtils.removeSymlink(linkPath);
|
|
|
|
});
|
|
|
|
|
2015-12-11 14:59:57 -05:00
|
|
|
var examplePaths = getExamplePaths(EXAMPLES_PATH);
|
2015-12-20 16:17:16 -05:00
|
|
|
return deleteFiles(_exampleBoilerplateFiles, examplePaths).then(function() {
|
|
|
|
var e2eSpecPaths = getE2eSpecPaths(EXAMPLES_PATH);
|
|
|
|
return deleteFiles(['protractor.config.js'], e2eSpecPaths);
|
|
|
|
})
|
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
|
|
|
|
2015-11-30 20:24:16 -05:00
|
|
|
gulp.task('build-docs', ['build-devguide-docs', 'build-api-docs', 'build-plunkers', '_zip-examples']);
|
2015-11-13 03:38:32 -05:00
|
|
|
|
2015-12-09 12:19:29 -05:00
|
|
|
gulp.task('build-api-docs', ['build-js-api-docs', 'build-ts-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
|
|
|
});
|
|
|
|
|
2015-11-30 20:24:16 -05:00
|
|
|
gulp.task('build-plunkers', function() {
|
|
|
|
return plunkerBuilder.buildPlunkers(EXAMPLES_PATH, LIVE_EXAMPLES_PATH, { errFn: gutil.log });
|
|
|
|
});
|
|
|
|
|
2015-12-08 15:23:43 -05:00
|
|
|
gulp.task('build-dart-cheatsheet', [], function() {
|
|
|
|
return buildApiDocs('dart');
|
|
|
|
});
|
|
|
|
|
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;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-12-15 01:08:52 -05:00
|
|
|
gulp.task('check-deploy', ['build-docs'], function() {
|
2016-01-08 20:55:46 -05:00
|
|
|
return harpCompile().then(function() {
|
2015-12-07 01:54:43 -05:00
|
|
|
gutil.log('compile ok - running live server ...');
|
2015-09-28 14:14:12 -04:00
|
|
|
execPromise('npm run live-server ./www');
|
2015-09-25 04:28:36 -04:00
|
|
|
return askDeploy();
|
|
|
|
}).then(function(shouldDeploy) {
|
|
|
|
if (shouldDeploy) {
|
2015-11-13 04:35:05 -05:00
|
|
|
gutil.log('deploying...');
|
2015-09-28 14:14:12 -04:00
|
|
|
return execPromise('firebase deploy');
|
|
|
|
} 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
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-11-13 03:38:32 -05:00
|
|
|
gulp.task('test-api-builder', function (cb) {
|
|
|
|
execCommands(['npm run test-api-builder'], {}, cb);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
2015-11-13 03:38:32 -05:00
|
|
|
gulp.task('_shred-devguide-examples', ['_shred-clean-devguide'], function() {
|
|
|
|
return docShredder.shred( _devguideShredOptions);
|
|
|
|
});
|
|
|
|
|
2016-01-19 05:11:58 -05:00
|
|
|
gulp.task('_shred-devguide-shared-jade', ['_shred-clean-devguide-shared-jade'], function() {
|
|
|
|
return docShredder.shred( _devguideShredJadeOptions);
|
|
|
|
});
|
|
|
|
|
|
|
|
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 ... ???
|
|
|
|
// return delPromise([ newCleanPath, oldCleanPath]);
|
|
|
|
var files = globby.sync( [newCleanPath, oldCleanPath]);
|
|
|
|
return delPromise(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, '**/*.*')
|
|
|
|
return delPromise([ cleanPath, '!**/*.ovr.*', '!**/_api/**']);
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('_shred-api-examples', ['_shred-clean-api'], function() {
|
|
|
|
checkAngularProjectPath();
|
|
|
|
return docShredder.shred( _apiShredOptions);
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('_shred-clean-api', function(cb) {
|
|
|
|
var cleanPath = path.join(_apiShredOptions.fragmentsDir, '**/*.*')
|
|
|
|
return delPromise([ cleanPath, '!**/*.ovr.*' ]);
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('_zip-examples', function() {
|
|
|
|
exampleZipper.zipExamples(_devguideShredOptions.examplesDir, _devguideShredOptions.zipDir);
|
|
|
|
exampleZipper.zipExamples(_apiShredOptions.examplesDir, _apiShredOptions.zipDir);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
env({
|
|
|
|
vars: { NODE_ENV: "production" }
|
|
|
|
});
|
|
|
|
gutil.log("NODE_ENV: " + process.env.NODE_ENV);
|
|
|
|
|
2016-01-08 20:55:46 -05:00
|
|
|
var deferred = Q.defer();
|
|
|
|
gutil.log('running harp compile...');
|
|
|
|
showHideExampleNodeModules('hide');
|
|
|
|
var spawnInfo = spawnExt('npm',['run','harp', '--', 'compile', '.', './www' ]);
|
|
|
|
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');
|
|
|
|
if (x !== 0) {
|
|
|
|
deferred.reject(x)
|
|
|
|
} else {
|
|
|
|
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');
|
|
|
|
deferred.reject(e);
|
|
|
|
});
|
|
|
|
return deferred.promise;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-11 14:59:57 -05:00
|
|
|
// returns a promise
|
|
|
|
function copyFiles(fileNames, destPaths) {
|
|
|
|
var copy = Q.denodeify(fsExtra.copy);
|
|
|
|
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});
|
|
|
|
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) {
|
|
|
|
var paths = getPaths(basePath, '*e2e-spec.js', true);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-02-11 18:08:06 -05:00
|
|
|
function getTypingsPaths(basePath) {
|
|
|
|
var paths = getExamplePaths(basePath).map(function(examplePath) {
|
|
|
|
return path.join(examplePath, "/typings");
|
|
|
|
});
|
|
|
|
return paths;
|
|
|
|
}
|
|
|
|
|
2015-12-20 16:17:16 -05:00
|
|
|
function getExamplePaths(basePath, includeBase) {
|
|
|
|
// includeBase defaults to false
|
|
|
|
return getPaths(basePath, "example-config.json", includeBase)
|
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
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" }
|
|
|
|
});
|
|
|
|
|
2015-11-13 03:38:32 -05:00
|
|
|
execCommands(['npm run harp -- server .'], {}, cb);
|
|
|
|
|
|
|
|
var browserSync = require('browser-sync').create();
|
|
|
|
browserSync.init({proxy: 'localhost:9000'});
|
|
|
|
|
|
|
|
if (options.devGuide) {
|
|
|
|
devGuideExamplesWatch(_devguideShredOptions, browserSync.reload);
|
|
|
|
}
|
2016-01-19 05:11:58 -05:00
|
|
|
if (options.devGuideJade) {
|
|
|
|
devGuideSharedJadeWatch( { jadeDir: DOCS_PATH}, browserSync.reload);
|
|
|
|
}
|
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() {
|
|
|
|
|
|
|
|
prompt.start();
|
|
|
|
var schema = {
|
|
|
|
name: 'shouldDeploy',
|
|
|
|
description: 'Deploy to Firebase? (y/n): ',
|
|
|
|
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) {
|
2015-11-04 05:55:02 -05:00
|
|
|
var srcPattern = [path.join(ANGULAR_PROJECT_PATH, 'modules/angular2/src/**/*.*')];
|
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) {
|
2015-11-14 05:56:41 -05:00
|
|
|
var examplesPath = path.join(ANGULAR_PROJECT_PATH, 'modules/angular2/examples/**');
|
|
|
|
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
|
|
|
|
|
|
|
return delPromise(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
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-11-13 04:37:43 -05:00
|
|
|
function devGuideExamplesWatch(shredOptions, postShredAction) {
|
2015-11-14 05:56:41 -05:00
|
|
|
var includePattern = path.join(shredOptions.examplesDir, '**/*.*');
|
2016-02-16 12:16:17 -05:00
|
|
|
// removed this version because gulp.watch has the same glob issue that dgeni has.
|
|
|
|
// 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-02-16 12:16:17 -05:00
|
|
|
var files = globby.sync( [includePattern], { ignore: [ '**/node_modules/**', '**/_fragments/**']});
|
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-01-19 05:11:58 -05:00
|
|
|
function devGuideSharedJadeWatch(shredOptions, postShredAction) {
|
|
|
|
var includePattern = path.join(DOCS_PATH, '**/*.jade');
|
|
|
|
// 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-02-16 12:16:17 -05:00
|
|
|
var files = globby.sync( [includePattern], { ignore: [ '**/node_modules/**', '**/_fragments/**']});
|
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'))]);
|
2015-12-08 15:23:43 -05:00
|
|
|
package.config(function(targetEnvironments, writeFilesProcessor, readTypeScriptModules) {
|
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;
|
|
|
|
}
|
2015-11-06 16:40:30 -05:00
|
|
|
writeFilesProcessor.outputFolder = targetLanguage + '/latest/api';
|
|
|
|
}
|
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) {
|
2015-11-13 04:35:05 -05:00
|
|
|
gutil.log(err);
|
|
|
|
gutil.log(err.stack);
|
2015-09-18 15:41:20 -04:00
|
|
|
throw err;
|
2015-09-16 02:21:55 -04:00
|
|
|
}
|
2015-11-06 16:40:30 -05:00
|
|
|
|
|
|
|
function copyApiDocsToJsFolder() {
|
|
|
|
// Make a copy of the JS API docs to the TS folder
|
|
|
|
return gulp.src([path.join(DOCS_PATH, 'ts/latest/api/**/*.*'), '!' + path.join(DOCS_PATH, 'ts/latest/api/index.jade')])
|
|
|
|
.pipe(gulp.dest('./public/docs/js/latest/api'));
|
|
|
|
}
|
2015-09-18 22:51:10 -04:00
|
|
|
}
|
2015-09-16 02:21:55 -04:00
|
|
|
|
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',
|
2015-08-08 16:55:53 -04:00
|
|
|
writeFilesEnabled: shouldWrite
|
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) {
|
|
|
|
diff.patches().forEach(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);
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-11-06 16:40:30 -05:00
|
|
|
function checkAngularProjectPath() {
|
|
|
|
if (!fs.existsSync(ANGULAR_PROJECT_PATH)) {
|
|
|
|
throw new Error('API related tasks require the angular2 repo to be at ' + path.resolve(ANGULAR_PROJECT_PATH));
|
|
|
|
}
|
|
|
|
}
|
2015-08-03 20:45:58 -04:00
|
|
|
|