Merge pull request #133 from Microsoft/removeGulpTasks

Removing gulp prep/unprep tasks. New corresponding steps would "npm i…
This commit is contained in:
Nisheet Jain 2015-11-11 20:55:29 -08:00
Родитель ef3e83da8a 86778c7206
Коммит 3305605689
10 изменённых файлов: 160 добавлений и 129 удалений

20
gulpfile.js Normal file
Просмотреть файл

@ -0,0 +1,20 @@
/* placeholder gulpfile, allows calling gulpmain tasks */
var fs = require("fs"),
path = require('path'),
gulp = require("gulp"),
buildConfig = require('./tools/build_config.json');
gulp.on("task_not_found", function (err) {
console.error("\nPlease run 'npm install' from project root\n");
});
/*
To add additional gulp tasks, add gulpfile in folder and reference it below
for example: require('./src/compile/gulpfile');
*/
var gulpMain = path.resolve(buildConfig.buildTools, "gulpmain.js");
if (fs.existsSync(gulpMain)) {
require(gulpMain);
}
module.exports = gulp;

Просмотреть файл

@ -15,7 +15,6 @@
"gulp-tslint": "latest",
"gulp-typescript": "~2.9.2",
"jsdoc-parse": "latest",
"merge2": "latest",
"mocha-teamcity-reporter": "latest",
"ncp": "latest",
"nopt": "latest",
@ -24,5 +23,11 @@
"replace": "latest",
"run-sequence": "latest",
"typescript": "~1.6.2"
},
"scripts" : {
"postinstall" : "node tools/tacoUtil.js",
"clean" : "node tools/tacoUtil.js",
"rebuild" : "node tools/tacoUtil.js"
}
}

Просмотреть файл

@ -1,12 +0,0 @@
{
"src": ".",
"templates": "../templates",
"build": "../build",
"buildCoverage": "../build/coverage",
"buildSrc": "../build/src",
"buildPackages": "../build/packages/node_modules",
"buildTools": "../build/tools",
"buildTemplates": "../build/packages/node_modules/taco-kits/templates",
"tsCompileOptions": { "noImplicitAny": true, "noEmitOnError": true, "target": "ES5", "module": "commonjs", "sourceMap": true, "sortOutput": true }
}

Просмотреть файл

@ -1,67 +0,0 @@
/* starter gulpfile, bootstraps compiling gulpmain.ts and runs it */
var exec = require("child_process").exec,
fs = require("fs"),
path = require('path'),
gulp = require("gulp"),
npmUtil = require ("../tools/npmInstallerUtil"),
buildConfig = require('./build_config.json'),
devDependencies = require('../package.json').devDependencies;
gulp.on("task_not_found", function (err) {
console.error("\nPlease run 'gulp prep' to prepare project\n");
});
/* compile the gulpmain.ts file into JS */
gulp.task("prep", ["installDevDependencies"], function (callback) {
var ts = require('gulp-typescript');
var merge = require("merge2");
var sourcemaps = require("gulp-sourcemaps");
return merge([
gulp.src(["gulpmain.ts"])
.pipe(sourcemaps.init())
.pipe(ts(buildConfig.tsCompileOptions))
.pipe(sourcemaps.write("."))
.pipe(gulp.dest(buildConfig.buildSrc)),
gulp.src(["../tools/**/*.ts"])
.pipe(sourcemaps.init())
.pipe(ts(buildConfig.tsCompileOptions))
.pipe(sourcemaps.write("."))
.pipe(gulp.dest(buildConfig.buildTools))
]);
});
gulp.task("unprep", ["uninstallDevDependencies"], function (callback) {
var gulpMain = path.join(buildConfig.buildSrc, "gulpmain.js");
if (fs.existsSync(gulpMain)) {
fs.unlink(gulpMain, callback)
} else {
callback();
}
});
/* install dev dependencies in root folder */
gulp.task("installDevDependencies", function (callback) {
exec("npm install", { cwd: ".." }, callback);
});
/* uninstall dev dependencies from root folder */
gulp.task("uninstallDevDependencies", function (callback) {
var dependencies = [];
for (var devPackage in devDependencies) {
dependencies.push(devPackage);
}
npmUtil.uninstallPackages(dependencies, "..", callback);
});
/*
to add additional gulp tasks, add gulpfile in folder and reference it below
for example: require('./src/compile/gulpfile');
*/
var gulpMain = path.join(buildConfig.buildSrc, "gulpmain.js");
if (fs.existsSync(gulpMain)) {
require(gulpMain);
}
module.exports = gulp;

1
src/typings/buildConfig.d.ts поставляемый
Просмотреть файл

@ -12,7 +12,6 @@ declare module BuildConfig {
templates: string;
build: string;
buildCoverage: string;
buildSrc: string;
buildPackages: string;
buildTools: string;
buildTemplates: string;

11
tools/build_config.json Normal file
Просмотреть файл

@ -0,0 +1,11 @@
{
"src": "src",
"templates": "templates",
"tools": "tools",
"build": "build",
"buildCoverage": "build/coverage",
"buildPackages": "build/packages/node_modules",
"buildTools": "build/tools",
"buildTemplates": "build/packages/node_modules/taco-kits/templates",
"tsCompileOptions": { "noImplicitAny": true, "noEmitOnError": true, "target": "ES5", "module": "commonjs", "sourceMap": true, "sortOutput": true }
}

Просмотреть файл

@ -1,12 +1,12 @@
/// <reference path="typings/node.d.ts" />
/// <reference path="typings/Q.d.ts" />
/// <reference path="typings/gulp.d.ts" />
/// <reference path="typings/gulpExtensions.d.ts" />
/// <reference path="typings/nopt.d.ts" />
/// <reference path="typings/gulp-typescript.d.ts" />
/// <reference path="typings/gulp-sourcemaps.d.ts" />
/// <reference path="typings/run-sequence.d.ts" />
/// <reference path="typings/buildConfig.d.ts" />
/// <reference path="../src/typings/node.d.ts" />
/// <reference path="../src/typings/Q.d.ts" />
/// <reference path="../src/typings/gulp.d.ts" />
/// <reference path="../src/typings/gulpExtensions.d.ts" />
/// <reference path="../src/typings/nopt.d.ts" />
/// <reference path="../src/typings/gulp-typescript.d.ts" />
/// <reference path="../src/typings/gulp-sourcemaps.d.ts" />
/// <reference path="../src/typings/run-sequence.d.ts" />
/// <reference path="../src/typings/buildConfig.d.ts" />
import runSequence = require ("run-sequence");
import gulp = require ("gulp");
@ -16,13 +16,13 @@ import nopt = require ("nopt");
import path = require ("path");
import Q = require ("q");
import GulpUtils = require ("../tools/GulpUtils");
import GulpCoverageUtils = require ("../tools/GulpCoverageUtils");
import GulpPackageUtils = require ("../tools/GulpPackageUtils");
import GulpUtils = require ("./GulpUtils");
import GulpCoverageUtils = require ("./GulpCoverageUtils");
import GulpPackageUtils = require ("./GulpPackageUtils");
/* tslint:disable:no-var-requires */
// var require needed to require build_config.json
var buildConfig: BuildConfig.IBuildConfig = require("../../src/build_config.json");
var buildConfig: BuildConfig.IBuildConfig = require("./build_config.json");
/* tslint:enable:no-var-requires */
var tacoModules: string[] = [

Просмотреть файл

@ -1,35 +0,0 @@
var exec = require("child_process").exec;
/**
* Utility for installing npm packages asynchronously.
*/
function uninstallPackage(pkg, installRoot, callback) {
console.info("Uninstalling " + pkg);
exec("npm uninstall " + pkg, { cwd: installRoot }, function (error, stdout, stderr) {
callback(error);
});
};
function executePackageAction(modules, installRoot, callback, action) {
var asyncLoop = function (idx) {
if (idx < modules.length) {
action(modules[idx], installRoot, function (error) {
if (!error) {
asyncLoop(idx + 1);
}
else {
callback(error);
}
});
}
else {
callback();
}
;
};
asyncLoop(0);
}
module.exports.uninstallPackages = function (modules, installRoot, callback) {
executePackageAction(modules, installRoot, callback, uninstallPackage);
};

110
tools/tacoUtil.js Normal file
Просмотреть файл

@ -0,0 +1,110 @@
var exec = require("child_process").exec;
var fs = require("fs");
var path = require ("path");
var util = require("util");
var buildConfig = require('./build_config.json');
switch(process.env.npm_lifecycle_event){
case "clean":
cleanBuild();
break;
case "rebuild":
case "postinstall":
compileBuildScripts();
break;
default:
console.error("Error: script called in unknown stage "+process.env.npm_lifecycle_event);
break;
}
function compileBuildScripts(callback) {
console.log("Compiling build tools...");
var success = true;
var gulp = require("gulp");
var ts = require('gulp-typescript');
var sourcemaps = require("gulp-sourcemaps");
gulp.src(["tools/**/*.ts"])
.pipe(sourcemaps.init())
.pipe(ts(buildConfig.tsCompileOptions))
.on("error", function(error){
if (error){
success = false;
}
})
.pipe(sourcemaps.write("."))
.pipe(gulp.dest(path.resolve(buildConfig.buildTools)))
.on("end", function(){
if (success){
// copy over build config to build\tools
// this is needed to make sure compile gulp scripts have same path to build_config
fs.writeFileSync(path.resolve(buildConfig.buildTools, "build_config.json"), JSON.stringify(buildConfig));
console.log(greenColorFunction("Success!!! To build the project, run 'gulp' from project root directory"));
}
});
}
function cleanBuild(callback) {
deleteFolderRecursive(buildConfig.buildTools);
var devDependencies = [];
if (fs.existsSync("node_modules")){
devDependencies = fs.readdirSync("node_modules").filter(function(file){
return fs.lstatSync(path.join("node_modules", file)).isDirectory() &&
file !== ".bin";
});
}
var asyncLoop = function (idx) {
if (idx < devDependencies.length) {
var pkg = devDependencies[idx];
console.info("Uninstalling " + pkg);
exec("npm uninstall " + pkg, {}, function (error, stdout, stderr) {
if (!error) {
asyncLoop(idx + 1);
}
else {
if (error){
console.error(util.format("Failed: 'npm uninstall %s'. Error: error", pkg, error));
if (callback){
callback(error);
}
}
}
});
} else {
if (callback){
callback();
}
}
};
asyncLoop(0);
}
function deleteFolderRecursive (dirPath) {
if(fs.existsSync(dirPath)) {
console.log("Removing "+dirPath);
fs.readdirSync(dirPath).forEach(function(file){
var curPath = path.join(dirPath, file);
// recurse
if(fs.lstatSync(curPath).isDirectory()) {
deleteFolderRecursive(curPath);
} else {
// delete file
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(dirPath);
}
};
function greenColorFunction(s) {
// https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_codes
// \u001b[3Xm == "set foreground colour to colour in slot X"
// Slot 2 defaults to green
// \u001b[39m == "reset foreground colour"
// \u001b[1m == "bold" which is interpreted differently by different terminals
// \u001b[22m == "stop being bold (or faint)"
return "\u001b[32m\u001b[1m" + s + "\u001b[22m\u001b[39m";
}

Просмотреть файл