mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-20 04:14:21 +08:00
chore(gulp): update gulp scripts
This commit is contained in:

committed by
Adam Bradley

parent
17fe72e4bc
commit
12c9fd12bd
1018
gulpfile.js
1018
gulpfile.js
File diff suppressed because it is too large
Load Diff
40
scripts/gulp/constants.ts
Normal file
40
scripts/gulp/constants.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import { join } from 'path';
|
||||
|
||||
|
||||
// Names
|
||||
export const COMPONENTS_NAME = 'components';
|
||||
export const DIST_NAME = 'dist';
|
||||
export const E2E_NAME = 'e2e';
|
||||
export const PACKAGE_NAME = 'ionic-angular';
|
||||
export const SCRIPTS_NAME = 'scripts';
|
||||
export const BUILD_NAME = 'build';
|
||||
export const SRC_NAME = 'src';
|
||||
export const VENDOR_NAME = 'vendor';
|
||||
export const NODE_MODULES = 'node_modules';
|
||||
export const COMMONJS_MODULE = 'commonjs';
|
||||
export const ES_MODULE = 'es2015';
|
||||
|
||||
|
||||
// File Paths
|
||||
export const PROJECT_ROOT = join(__dirname, '../..');
|
||||
export const DIST_ROOT = join(PROJECT_ROOT, DIST_NAME);
|
||||
export const DIST_E2E_ROOT = join(DIST_ROOT, E2E_NAME);
|
||||
export const DIST_E2E_COMPONENTS_ROOT = join(DIST_E2E_ROOT, COMPONENTS_NAME);
|
||||
export const DIST_BUILD_ROOT = join(DIST_ROOT, PACKAGE_NAME);
|
||||
export const DIST_BUILD_COMMONJS_ROOT = join(DIST_BUILD_ROOT, COMMONJS_MODULE);
|
||||
export const DIST_VENDOR_ROOT = join(DIST_ROOT, VENDOR_NAME);
|
||||
export const NODE_MODULES_ROOT = join(PROJECT_ROOT, NODE_MODULES);
|
||||
export const SCRIPTS_ROOT = join(PROJECT_ROOT, SCRIPTS_NAME);
|
||||
export const SRC_ROOT = join(PROJECT_ROOT, SRC_NAME);
|
||||
export const SRC_COMPONENTS_ROOT = join(SRC_ROOT, COMPONENTS_NAME);
|
||||
|
||||
|
||||
// NPM
|
||||
export const NPM_VENDOR_FILES = [
|
||||
'@angular', 'core-js/client', 'rxjs', 'systemjs/dist', 'zone.js/dist'
|
||||
];
|
||||
|
||||
|
||||
// SERVER
|
||||
export const LOCAL_SERVER_PORT = 8080;
|
||||
|
9
scripts/gulp/gulpfile.ts
Normal file
9
scripts/gulp/gulpfile.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import './tasks/build';
|
||||
import './tasks/clean';
|
||||
import './tasks/default';
|
||||
import './tasks/e2e';
|
||||
import './tasks/lint';
|
||||
import './tasks/release';
|
||||
import './tasks/snapshot';
|
||||
import './tasks/test';
|
||||
//import './tasks/theme';
|
51
scripts/gulp/tasks/build.ts
Normal file
51
scripts/gulp/tasks/build.ts
Normal file
@ -0,0 +1,51 @@
|
||||
import { COMMONJS_MODULE, DIST_BUILD_ROOT, DIST_BUILD_COMMONJS_ROOT, ES_MODULE } from '../constants';
|
||||
import { task } from 'gulp';
|
||||
import { copySourceToDest, copySwiperToPath, createTempTsConfig, deleteFiles, runNgc} from '../util';
|
||||
|
||||
|
||||
export function buildIonicAngularCommonJs(excludeSpec: boolean, done: Function) {
|
||||
const stream = copySourceToDest(DIST_BUILD_COMMONJS_ROOT, excludeSpec, true);
|
||||
stream.on('end', () => {
|
||||
// the source files are copied, copy over a tsconfig from
|
||||
createTempTsConfig(['./**/*.ts'], COMMONJS_MODULE, `${DIST_BUILD_COMMONJS_ROOT}/tsconfig.json`);
|
||||
runNgc(`${DIST_BUILD_COMMONJS_ROOT}/tsconfig.json`, (err) => {
|
||||
if (err) {
|
||||
done(err);
|
||||
return;
|
||||
}
|
||||
|
||||
copySwiperToPath(`${DIST_BUILD_COMMONJS_ROOT}/components/slides`, COMMONJS_MODULE);
|
||||
// clean up any .ts files that remain, as well as unneeded swiper stuff
|
||||
deleteFiles([`${DIST_BUILD_COMMONJS_ROOT}/**/*.ts`, `!${DIST_BUILD_COMMONJS_ROOT}/**/*.ngfactory.ts`, `!${DIST_BUILD_COMMONJS_ROOT}/**/*.d.ts`], done);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function buildIonicAngularEsm(done: Function) {
|
||||
const stream = copySourceToDest(DIST_BUILD_ROOT, true, true);
|
||||
stream.on('end', () => {
|
||||
// the source files are copied, copy over a tsconfig from
|
||||
createTempTsConfig(['./**/*.ts'], ES_MODULE, `${DIST_BUILD_ROOT}/tsconfig.json`);
|
||||
runNgc(`${DIST_BUILD_ROOT}/tsconfig.json`, (err) => {
|
||||
if (err) {
|
||||
done(err);
|
||||
return;
|
||||
}
|
||||
copySwiperToPath(`${DIST_BUILD_ROOT}/components/slides`, ES_MODULE);
|
||||
// clean up any .ts files that remain
|
||||
deleteFiles([`${DIST_BUILD_ROOT}/**/*.ts`, `!${DIST_BUILD_ROOT}/**/*.ngfactory.ts`, `!${DIST_BUILD_ROOT}/**/*.d.ts`], done);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/* this task builds out the necessary stuff for karma */
|
||||
task('compile.karma', (done: Function) => {
|
||||
buildIonicAngularCommonJs(false, done);
|
||||
});
|
||||
|
||||
/* this task builds out the ionic-angular (commonjs and esm) directories for release */
|
||||
task('compile.release', (done: Function) => {
|
||||
buildIonicAngularEsm(() => {
|
||||
buildIonicAngularCommonJs(true, done);
|
||||
});
|
||||
});
|
12
scripts/gulp/tasks/clean.ts
Normal file
12
scripts/gulp/tasks/clean.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { task } from 'gulp';
|
||||
|
||||
|
||||
task('clean', (done: () => void) => {
|
||||
const del = require('del');
|
||||
del(['dist/**'], done);
|
||||
});
|
||||
|
||||
task('clean.src', (done: () => void) => {
|
||||
const del = require('del');
|
||||
del(['src/**/*.js', 'src/**/*.d.ts', '!src/components/slides/swiper-widget.*'], done);
|
||||
});
|
17
scripts/gulp/tasks/default.ts
Normal file
17
scripts/gulp/tasks/default.ts
Normal file
@ -0,0 +1,17 @@
|
||||
const gulp = require('gulp');
|
||||
|
||||
|
||||
gulp.task('default', help);
|
||||
|
||||
gulp.task('help', help);
|
||||
|
||||
function help() {
|
||||
const taskList = Object.keys(gulp.tasks)
|
||||
.filter(taskName => taskName !== 'default' && taskName !== 'help')
|
||||
.sort()
|
||||
.map(taskName => taskName = ' ' + taskName);
|
||||
|
||||
console.log(taskList.join('\n'));
|
||||
}
|
||||
|
||||
gulp.task('validate', ['lint', 'test']);
|
278
scripts/gulp/tasks/e2e.ts
Normal file
278
scripts/gulp/tasks/e2e.ts
Normal file
@ -0,0 +1,278 @@
|
||||
import { COMMONJS_MODULE, DIST_E2E_COMPONENTS_ROOT, DIST_E2E_ROOT, DIST_NAME, E2E_NAME, LOCAL_SERVER_PORT, PROJECT_ROOT, SCRIPTS_ROOT, SRC_COMPONENTS_ROOT, SRC_ROOT } from '../constants';
|
||||
import {dest, src, start, task} from 'gulp';
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
|
||||
import { compileSass, copyFonts, createTempTsConfig, deleteFiles, runNgc, runWebpack, setSassIonicVersion, createTimestamp } from '../util';
|
||||
|
||||
|
||||
|
||||
task('e2e', e2eBuild);
|
||||
|
||||
function e2eBuild(done: Function) {
|
||||
const runSequence = require('run-sequence');
|
||||
runSequence('e2e.copySource', 'e2e.compileTests', 'e2e.copyExternalDependencies', 'e2e.sass', 'e2e.fonts', 'e2e.beforeWebpack', 'e2e.runWebpack', done);
|
||||
}
|
||||
|
||||
task('e2e.copyAndCompile', (done: Function) => {
|
||||
const runSequence = require('run-sequence');
|
||||
runSequence('e2e.copySource', 'e2e.compileTests', 'e2e.beforeWebpack', 'e2e.runWebpack', done);
|
||||
});
|
||||
|
||||
task('e2e.copySource', (done: Function) => {
|
||||
const gulpif = require('gulp-if');
|
||||
const _ = require('lodash');
|
||||
const VinylFile = require('vinyl');
|
||||
const through2 = require('through2');
|
||||
const buildConfig = require('../../build/config');
|
||||
|
||||
const stream = src([`${SRC_ROOT}/**/*`, `!${SRC_ROOT}/**/*.spec.ts`])
|
||||
.pipe(gulpif(/app-module.ts$/, createIndexHTML()))
|
||||
.pipe(gulpif(/e2e.ts$/, createPlatformTests()))
|
||||
.pipe(dest(DIST_E2E_ROOT));
|
||||
|
||||
stream.on('end', done);
|
||||
|
||||
function createIndexHTML() {
|
||||
const indexTemplate = fs.readFileSync('scripts/e2e/index.html');
|
||||
const indexTs = fs.readFileSync('scripts/e2e/entry.ts');
|
||||
|
||||
return through2.obj(function(file, enc, next) {
|
||||
this.push(new VinylFile({
|
||||
base: file.base,
|
||||
contents: new Buffer(indexTemplate),
|
||||
path: path.join(path.dirname(file.path), 'index.html'),
|
||||
}));
|
||||
this.push(new VinylFile({
|
||||
base: file.base,
|
||||
contents: new Buffer(indexTs),
|
||||
path: path.join(path.dirname(file.path), 'entry.ts'),
|
||||
}));
|
||||
next(null, file);
|
||||
});
|
||||
}
|
||||
|
||||
function createPlatformTests() {
|
||||
let platforms = [
|
||||
'android',
|
||||
'ios',
|
||||
'windows'
|
||||
];
|
||||
|
||||
let testTemplate = _.template(fs.readFileSync('scripts/e2e/e2e.template.js'));
|
||||
|
||||
return through2.obj(function(file, enc, next) {
|
||||
let self = this;
|
||||
let relativePath = path.dirname(file.path.replace(/^.*?src(\/|\\)components(\/|\\)/, ''));
|
||||
|
||||
let contents = file.contents.toString();
|
||||
platforms.forEach(function(platform) {
|
||||
let platformContents = testTemplate({
|
||||
contents: contents,
|
||||
buildConfig: buildConfig,
|
||||
relativePath: relativePath,
|
||||
platform: platform
|
||||
});
|
||||
self.push(new VinylFile({
|
||||
base: file.base,
|
||||
contents: new Buffer(platformContents),
|
||||
path: file.path.replace(/e2e.ts$/, platform + '.e2e.js')
|
||||
}));
|
||||
});
|
||||
next();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
task('e2e.compileTests', (done: Function) => {
|
||||
let folderInfo = getFolderInfo();
|
||||
buildE2ETests(folderInfo, done);
|
||||
});
|
||||
|
||||
function buildE2ETests(folderInfo: any, done: Function) {
|
||||
let includeGlob = ['./components/*/test/*/app-module.ts', './components/*/test/*/entry.ts'];
|
||||
if (folderInfo.componentName && folderInfo.componentTest) {
|
||||
includeGlob = [
|
||||
`./components/${folderInfo.componentName}/test/${folderInfo.componentTest}/app-module.ts`,
|
||||
`./components/${folderInfo.componentName}/test/${folderInfo.componentTest}/entry.ts`,
|
||||
];
|
||||
}
|
||||
createTempTsConfig(includeGlob, COMMONJS_MODULE, `${DIST_E2E_ROOT}/tsconfig.json`);
|
||||
runNgc(`${DIST_E2E_ROOT}/tsconfig.json`, (err) => {
|
||||
if (err) {
|
||||
done(err);
|
||||
return;
|
||||
}
|
||||
// clean up any .ts files that remain
|
||||
deleteFiles([`${DIST_E2E_ROOT}/**/*.ts`, `!${DIST_E2E_ROOT}/**/*.ngfactory.ts`, `!${DIST_E2E_ROOT}/**/*.d.ts`], done);
|
||||
});
|
||||
}
|
||||
|
||||
function getFolderInfo() {
|
||||
const argv = require('yargs').argv;
|
||||
let componentName: string = null;
|
||||
let componentTest: string = null;
|
||||
const folder: string = argv.folder || argv.f;
|
||||
if (folder && folder.length) {
|
||||
const folderSplit = folder.split('/');
|
||||
componentName = folderSplit[0];
|
||||
componentTest = (folderSplit.length > 1 ? folderSplit[1] : 'basic');
|
||||
}
|
||||
return {
|
||||
componentName: componentName,
|
||||
componentTest: componentTest
|
||||
};
|
||||
}
|
||||
|
||||
task('e2e.copyExternalDependencies', () => {
|
||||
src([`${SCRIPTS_ROOT}/e2e/*.css`]).pipe(dest(`${DIST_E2E_ROOT}/css`));
|
||||
});
|
||||
|
||||
task('e2e.sass', () => {
|
||||
// ensure there is a version.scss file
|
||||
setSassIonicVersion(`E2E-${createTimestamp()}`);
|
||||
return compileSass(`${DIST_E2E_ROOT}/css`);
|
||||
});
|
||||
|
||||
task('e2e.fonts', () => {
|
||||
return copyFonts(`${DIST_E2E_ROOT}/fonts`);
|
||||
});
|
||||
|
||||
task('e2e.beforeWebpack', (done) => {
|
||||
/**
|
||||
* Find all AppModule.ts files because the act as the entry points
|
||||
* for each e2e test.
|
||||
*/
|
||||
let glob = require('glob');
|
||||
let includeGlob = `${DIST_E2E_ROOT}/components/*/test/*/app-module.js`;
|
||||
let folderInfo = getFolderInfo();
|
||||
if (folderInfo.componentName && folderInfo.componentTest) {
|
||||
includeGlob = `${DIST_E2E_ROOT}/components/${folderInfo.componentName}/test/${folderInfo.componentTest}/app-module.js`;
|
||||
}
|
||||
glob(includeGlob, {}, function(er, files) {
|
||||
var directories = files.map(function(file) {
|
||||
return path.dirname(file);
|
||||
});
|
||||
|
||||
var webpackEntryPoints = directories.reduce(function(endObj, dir) {
|
||||
let relativePath = dir.replace(process.cwd() + '/', './');
|
||||
endObj[relativePath + '/index'] = relativePath + '/entry';
|
||||
return endObj;
|
||||
}, {});
|
||||
|
||||
let indexFileContents = directories.map(function(dir) {
|
||||
let testName = dir.replace(`${DIST_E2E_ROOT}/components/`, '');
|
||||
let fileName = dir.replace(`${PROJECT_ROOT}`, '');
|
||||
return `<p><a href="${fileName}/index.html">${testName}</a></p>`;
|
||||
}, []);
|
||||
|
||||
fs.writeFileSync('./scripts/e2e/webpackEntryPoints.json', JSON.stringify(webpackEntryPoints, null, 2));
|
||||
fs.writeFileSync(`${DIST_E2E_ROOT}/index.html`,
|
||||
'<!DOCTYPE html><html lang="en"><head></head><body style="width: 500px; margin: 100px auto">\n' +
|
||||
indexFileContents.join('\n') +
|
||||
'</center></body></html>'
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
task('e2e.runWebpack', (done: Function) => {
|
||||
const webpackConfigPath = `${SCRIPTS_ROOT}/e2e/webpack.config.js`;
|
||||
runWebpack(webpackConfigPath, done);
|
||||
});
|
||||
|
||||
|
||||
task('e2e.watch', ['e2e.copyExternalDependencies', 'e2e.sass', 'e2e.fonts'], (done: Function) => {
|
||||
const folderInfo = getFolderInfo();
|
||||
if (! folderInfo.componentName || ! folderInfo.componentTest) {
|
||||
done(new Error('Passing in a folder to watch is required for this command. Use the --folder or -f option.'));
|
||||
return;
|
||||
}
|
||||
|
||||
const e2eTestPath = path.join(SRC_COMPONENTS_ROOT, folderInfo.componentName, 'test', folderInfo.componentTest, 'app-module.ts');
|
||||
|
||||
try {
|
||||
fs.accessSync(e2eTestPath, fs.F_OK);
|
||||
} catch (e) {
|
||||
done(new Error(`Could not find e2e test: ${e2eTestPath}`));
|
||||
return;
|
||||
}
|
||||
|
||||
if (e2eComponentsExists()) {
|
||||
// already generated the e2e directory
|
||||
e2eWatch(folderInfo.componentName, folderInfo.componentTest);
|
||||
|
||||
} else {
|
||||
// generate the e2e directory
|
||||
console.log('Generated e2e builds first...');
|
||||
e2eBuild(() => {
|
||||
e2eWatch(folderInfo.componentName, folderInfo.componentTest);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function e2eWatch(componentName: string, componentTest: string) {
|
||||
const watch = require('gulp-watch');
|
||||
const webpack = require('webpack');
|
||||
const WebpackDevServer = require('webpack-dev-server');
|
||||
const config = require('../../e2e/webpack.config.js');
|
||||
|
||||
config.output.path = path.join(__dirname, '../../../');
|
||||
config.entry = {
|
||||
'dist/e2e/vendor': './scripts/e2e/vendor',
|
||||
'dist-e2e/polyfills': './scripts/e2e/polyfills'
|
||||
};
|
||||
config.entry[`./dist/e2e/components/${componentName}/test/${componentTest}/index`] = `./dist/e2e/components/${componentName}/test/${componentTest}/entry`;
|
||||
|
||||
const compiler = webpack(config);
|
||||
|
||||
// If any tests change within components then run e2e.resources.
|
||||
watch([
|
||||
'src/components/*/test/**/*'
|
||||
],
|
||||
function(file) {
|
||||
console.log('start e2e.resources - ' + JSON.stringify(file.history, null, 2));
|
||||
start('e2e.copyAndCompile');
|
||||
});
|
||||
|
||||
// If any src files change except for tests then transpile only the source ionic files
|
||||
watch([
|
||||
'src/**/*.ts',
|
||||
'!src/components/*/test/**/*',
|
||||
'!src/util/test/*'
|
||||
],
|
||||
function(file) {
|
||||
console.log('start e2e.ngcSource - ' + JSON.stringify(file.history, null, 2));
|
||||
start('e2e.copyAndCompile');
|
||||
});
|
||||
|
||||
// If any scss files change then recompile all sass
|
||||
watch(['src/**/*.scss'], (file) => {
|
||||
console.log('start sass - ' + JSON.stringify(file.history, null, 2));
|
||||
start('e2e.sass');
|
||||
});
|
||||
|
||||
new WebpackDevServer(compiler, {
|
||||
noInfo: true,
|
||||
quiet: false,
|
||||
watchOptions: {
|
||||
aggregateTimeout: 2000,
|
||||
poll: 1000
|
||||
}
|
||||
}).listen(LOCAL_SERVER_PORT, 'localhost', function(err) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
console.log(`http://localhost:${LOCAL_SERVER_PORT}/${DIST_NAME}/${E2E_NAME}/components/${componentName}/test/${componentTest}/`);
|
||||
});
|
||||
}
|
||||
|
||||
function e2eComponentsExists(): boolean {
|
||||
try {
|
||||
fs.accessSync(DIST_E2E_COMPONENTS_ROOT, fs.F_OK);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
25
scripts/gulp/tasks/lint.ts
Normal file
25
scripts/gulp/tasks/lint.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { task, src } from 'gulp';
|
||||
|
||||
|
||||
task('lint', ['lint.sass', 'lint.ts']);
|
||||
|
||||
|
||||
task('lint.ts', () => {
|
||||
const tslint = require('gulp-tslint');
|
||||
return src([
|
||||
'src/**/*.ts'
|
||||
]).pipe(tslint())
|
||||
.pipe(tslint.report('verbose'));
|
||||
});
|
||||
|
||||
|
||||
task('lint.sass', function() {
|
||||
const scsslint = require('gulp-scss-lint');
|
||||
return src([
|
||||
'src/**/*.scss',
|
||||
'!src/components/*/test/**/*',
|
||||
'!src/util/test/*'
|
||||
])
|
||||
.pipe(scsslint())
|
||||
.pipe(scsslint.failReporter());
|
||||
});
|
119
scripts/gulp/tasks/release.ts
Normal file
119
scripts/gulp/tasks/release.ts
Normal file
@ -0,0 +1,119 @@
|
||||
import { dest, src, task } from 'gulp';
|
||||
import { DIST_BUILD_ROOT, SRC_ROOT, PROJECT_ROOT } from '../constants';
|
||||
import { compileSass, copyFonts, setSassIonicVersion, createTimestamp } from '../util';
|
||||
|
||||
|
||||
task('nightly', (done: Function) => {
|
||||
const runSequence = require('run-sequence');
|
||||
runSequence('release.nightlyPackage', 'release.publishNightly', done);
|
||||
});
|
||||
|
||||
task('release.prepareNightly', (done: Function) => {
|
||||
const runSequence = require('run-sequence');
|
||||
runSequence(/*'release.pullLatest', 'validate', */'release.copyTools', 'release.copyNpmInfo', 'release.preparePackageJsonTemplate', 'release.nightlyPackageJson', done);
|
||||
});
|
||||
|
||||
task('release.nightlyPackage', (done: Function) => {
|
||||
const runSequence = require('run-sequence');
|
||||
runSequence('clean', /*'release.prepareNightly',*/ 'compile.release', 'release.prepareNightly', 'release.compileSass', 'release.fonts', 'release.scss', done);
|
||||
});
|
||||
|
||||
task('release.publishNightly', (done: Function) => {
|
||||
const spawn = require('child_process').spawn;
|
||||
|
||||
const npmCmd = spawn('npm', ['publish', '--tag=nightly', DIST_BUILD_ROOT]);
|
||||
npmCmd.stdout.on('data', function (data) {
|
||||
console.log(data.toString());
|
||||
});
|
||||
|
||||
npmCmd.stderr.on('data', function (data) {
|
||||
console.log('npm err: ' + data.toString());
|
||||
});
|
||||
|
||||
npmCmd.on('close', function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
task('release.compileSass', () => {
|
||||
return compileSass(`${DIST_BUILD_ROOT}/css`);
|
||||
});
|
||||
|
||||
task('release.fonts', () => {
|
||||
return copyFonts(`${DIST_BUILD_ROOT}/fonts`);
|
||||
});
|
||||
|
||||
task('release.scss', () => {
|
||||
return src([`${SRC_ROOT}/**/*.scss`, `!${SRC_ROOT}/components/*/test/**/*`, `!${SRC_ROOT}/util/test/*`]).pipe(dest(`${DIST_BUILD_ROOT}`));
|
||||
});
|
||||
|
||||
task('release.pullLatest', (done: Function) => {
|
||||
const gulpGit = require('gulp-git');
|
||||
gulpGit.pull('origin', ['master'], err => {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
task('release.prepareChangelog', () => {
|
||||
const changelog = require('gulp-conventional-changelog');
|
||||
return gulp.src(`${PROJECT_ROOT}/CHANGELOG.md`)
|
||||
.pipe(changelog({
|
||||
preset: 'angular'
|
||||
}))
|
||||
.pipe(gulp.dest(`${PROJECT_ROOT}`));
|
||||
});
|
||||
|
||||
|
||||
task('release.prepareRootPackageJson', () => {
|
||||
const semver = require('semver');
|
||||
const fs = require('fs');
|
||||
|
||||
let packageJSON = require('./package.json');
|
||||
packageJSON.version = semver.inc(packageJSON.version, 'prerelease', 'beta');
|
||||
fs.writeFileSync('package.json', JSON.stringify(packageJSON, null, 2));
|
||||
});
|
||||
|
||||
task('release.copyTools', () => {
|
||||
return src([`${PROJECT_ROOT}/tooling/**/*`]).pipe(dest(`${DIST_BUILD_ROOT}/tooling`));
|
||||
});
|
||||
|
||||
task('release.copyNpmInfo', () => {
|
||||
return src([`${PROJECT_ROOT}/scripts/npm/.npmignore`, `${PROJECT_ROOT}/scripts/npm/README.md`]).pipe(dest(DIST_BUILD_ROOT));
|
||||
});
|
||||
|
||||
task('release.preparePackageJsonTemplate', () => {
|
||||
const fs = require('fs');
|
||||
let templatePackageJSON = require(`${PROJECT_ROOT}/scripts/npm/package.json`);
|
||||
const sourcePackageJSON = require(`${PROJECT_ROOT}/package.json`);
|
||||
// copy source package.json data to template
|
||||
templatePackageJSON.version = sourcePackageJSON.version;
|
||||
templatePackageJSON.description = sourcePackageJSON.description;
|
||||
templatePackageJSON.keywords = sourcePackageJSON.keywords;
|
||||
|
||||
// copy source dependencies versions to the template's peerDependencies
|
||||
// only copy dependencies that show up as peerDependencies in the template
|
||||
for (let dependency in sourcePackageJSON.dependencies) {
|
||||
// if the dependency is in both, AND the value of the entry is empty, copy it over
|
||||
if (dependency in templatePackageJSON.dependencies && templatePackageJSON.dependencies[dependency] === '') {
|
||||
templatePackageJSON.dependencies[dependency] = sourcePackageJSON.dependencies[dependency];
|
||||
} else if (dependency === 'rxjs') {
|
||||
const value = sourcePackageJSON.dependencies[dependency];
|
||||
templatePackageJSON.dependencies['rxjs-es'] = value;
|
||||
}
|
||||
}
|
||||
|
||||
fs.writeFileSync(`${DIST_BUILD_ROOT}` + '/package.json', JSON.stringify(templatePackageJSON, null, 2));
|
||||
});
|
||||
|
||||
task('release.nightlyPackageJson', () => {
|
||||
const fs = require('fs');
|
||||
const packageJson: any = require(`${DIST_BUILD_ROOT}/package.json`);
|
||||
|
||||
packageJson.version = packageJson.version.split('-')
|
||||
.slice(0, 2)
|
||||
.concat(createTimestamp())
|
||||
.join('-');
|
||||
|
||||
fs.writeFileSync(`${DIST_BUILD_ROOT}/package.json`, JSON.stringify(packageJson, null, 2));
|
||||
setSassIonicVersion(packageJson.version);
|
||||
});
|
64
scripts/gulp/tasks/test.ts
Normal file
64
scripts/gulp/tasks/test.ts
Normal file
@ -0,0 +1,64 @@
|
||||
import { DIST_VENDOR_ROOT, NPM_VENDOR_FILES, PROJECT_ROOT, SCRIPTS_ROOT } from '../constants';
|
||||
import path = require('path');
|
||||
import { dest, src, task } from 'gulp';
|
||||
|
||||
|
||||
task('test', ['test.assembleVendorJs', 'compile.karma'], (done: Function) => {
|
||||
karmaTest(false, done);
|
||||
});
|
||||
|
||||
task('test.watch', ['test.assembleVendorJs', 'compile.karma'], (done: Function) => {
|
||||
karmaTest(true, done);
|
||||
});
|
||||
|
||||
task('test.coverage', ['test.assembleVendorJs', 'compile.karma'], (done: Function) => {
|
||||
karmaTest(false, () => {
|
||||
createKarmaCoverageReport(done);
|
||||
});
|
||||
});
|
||||
|
||||
function karmaTest(watch: boolean, done: Function) {
|
||||
const karma = require('karma');
|
||||
const argv = require('yargs').argv;
|
||||
|
||||
let karmaConfig = {
|
||||
configFile: path.join(SCRIPTS_ROOT, 'karma/karma.conf.js'),
|
||||
};
|
||||
|
||||
if (watch) {
|
||||
(karmaConfig as any).singleRun = false;
|
||||
}
|
||||
|
||||
if (argv.testGrep) {
|
||||
(<any>karmaConfig).client = {
|
||||
args: ['--grep', argv.testGrep]
|
||||
};
|
||||
}
|
||||
|
||||
new karma.Server(karmaConfig, done).start();
|
||||
}
|
||||
|
||||
|
||||
task('test.assembleVendorJs', () => {
|
||||
const files = NPM_VENDOR_FILES.map((root) => {
|
||||
const glob = path.join(root, '**/*.+(js|js.map)');
|
||||
return src(path.join('node_modules', glob))
|
||||
.pipe(dest(path.join(DIST_VENDOR_ROOT, root)));
|
||||
});
|
||||
const gulpMerge = require('merge2');
|
||||
return gulpMerge(files);
|
||||
});
|
||||
|
||||
|
||||
/* creates a karma code coverage report */
|
||||
function createKarmaCoverageReport(done: Function) {
|
||||
console.log('Generating Unit Test Coverage Report...');
|
||||
|
||||
let exec = require('child_process').exec;
|
||||
let command = `node_modules/.bin/remap-istanbul -i coverage/coverage-final.json -o coverage -t html`;
|
||||
|
||||
exec(command, function(err: any, stdout: any, stderr: any) {
|
||||
console.log(`file://${PROJECT_ROOT}/coverage/index.html`);
|
||||
done(err);
|
||||
});
|
||||
}
|
117
scripts/gulp/tasks/theme.ts
Normal file
117
scripts/gulp/tasks/theme.ts
Normal file
@ -0,0 +1,117 @@
|
||||
import { task } from 'gulp';
|
||||
import { SRC_ROOT, SRC_COMPONENTS_ROOT } from '../constants';
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
|
||||
|
||||
|
||||
task('theme', (done: () => void) => {
|
||||
let opts: GenerateThemeOptions = {
|
||||
src: path.join(SRC_COMPONENTS_ROOT),
|
||||
dest: path.join(SRC_ROOT, 'ionic-generate.scss')
|
||||
};
|
||||
generateThemeSource(opts);
|
||||
});
|
||||
|
||||
|
||||
export function generateThemeSource(opts: GenerateThemeOptions) {
|
||||
console.log(`[theme] src: ${opts.src}`);
|
||||
console.log(`[theme] desc: ${opts.dest}`);
|
||||
|
||||
let components = getSourceComponents(opts);
|
||||
generateManifest(opts, components);
|
||||
}
|
||||
|
||||
|
||||
function generateManifest(opts: GenerateThemeOptions, components: Component[]) {
|
||||
|
||||
components.forEach(c => {
|
||||
console.log(c.name);
|
||||
|
||||
c.modes.forEach(m => {
|
||||
console.log(` ${m.mode} ${m.src}`);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
function getSourceComponents(opts: GenerateThemeOptions) {
|
||||
let components: Component[] = [];
|
||||
|
||||
function readFiles(src: string, fillFiles: string[]) {
|
||||
fs.readdirSync(src).forEach((file, index) => {
|
||||
var filePath = path.join(src, file);
|
||||
var fsStats = fs.statSync(filePath);
|
||||
if (fsStats.isDirectory()) {
|
||||
readFiles(filePath, fillFiles);
|
||||
} else if (fsStats.isFile()) {
|
||||
fillFiles.push(filePath);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let files: string[] = [];
|
||||
readFiles(opts.src, files);
|
||||
|
||||
files = files.filter(f => f.slice(-5) === '.scss');
|
||||
files.sort();
|
||||
|
||||
files.forEach(f => {
|
||||
var componentRoot = f.replace(opts.src + '/', '');
|
||||
var fileSplit = componentRoot.split('/');
|
||||
var componentName = fileSplit[0];
|
||||
var fileName = fileSplit[1];
|
||||
|
||||
var component = components.find(c => c.name === componentName);
|
||||
if (!component) {
|
||||
component = {
|
||||
name: componentName,
|
||||
modes: []
|
||||
};
|
||||
components.push(component);
|
||||
}
|
||||
|
||||
fileSplit = fileName.split('.');
|
||||
if (fileSplit.length === 3) {
|
||||
component.modes.push({
|
||||
src: f,
|
||||
mode: fileSplit[1]
|
||||
});
|
||||
|
||||
} else {
|
||||
component.modes.unshift({
|
||||
src: f,
|
||||
mode: DEFAULT_MODE
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
console.log(`[theme] components: ${components.length}`);
|
||||
|
||||
return components;
|
||||
}
|
||||
|
||||
|
||||
export interface GenerateThemeOptions {
|
||||
src: string;
|
||||
dest: string;
|
||||
includeModes?: string[];
|
||||
excludeModes?: string[];
|
||||
includeComponents?: string[];
|
||||
excludeComponents?: string[];
|
||||
}
|
||||
|
||||
export interface Component {
|
||||
name: string;
|
||||
modes: FileDetails[];
|
||||
}
|
||||
|
||||
export interface FileDetails {
|
||||
src: string;
|
||||
mode: string;
|
||||
}
|
||||
|
||||
const DEFAULT_MODE = '*';
|
25
scripts/gulp/tsconfig.json
Normal file
25
scripts/gulp/tsconfig.json
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"declaration": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"lib": ["es6", "es2015"],
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node",
|
||||
"noEmitOnError": true,
|
||||
"noImplicitAny": false,
|
||||
"outDir": "../../dist/gulp",
|
||||
"rootDir": ".",
|
||||
"sourceMap": true,
|
||||
"target": "es5",
|
||||
"inlineSources": true,
|
||||
"stripInternal": true,
|
||||
"baseUrl": "",
|
||||
"typeRoots": [
|
||||
"../../node_modules/@types"
|
||||
],
|
||||
"types": [
|
||||
"node"
|
||||
]
|
||||
}
|
||||
}
|
175
scripts/gulp/util.ts
Normal file
175
scripts/gulp/util.ts
Normal file
@ -0,0 +1,175 @@
|
||||
import { COMMONJS_MODULE, ES_MODULE, NODE_MODULES_ROOT, PROJECT_ROOT, SRC_ROOT, SRC_COMPONENTS_ROOT } from './constants';
|
||||
import { src, dest } from 'gulp';
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
|
||||
export function mergeObjects(obj1: any, obj2: any ) {
|
||||
if (! obj1) {
|
||||
obj1 = {};
|
||||
}
|
||||
if (! obj2) {
|
||||
obj2 = {};
|
||||
}
|
||||
var obj3 = {};
|
||||
for (var attrname in obj1) {
|
||||
(<any>obj3)[attrname] = obj1[attrname];
|
||||
}
|
||||
for (var attrname in obj2) {
|
||||
(<any>obj3)[attrname] = obj2[attrname];
|
||||
}
|
||||
return obj3;
|
||||
}
|
||||
|
||||
function getRootTsConfig(): any {
|
||||
const json = fs.readFileSync(`${PROJECT_ROOT}/tsconfig.json`);
|
||||
|
||||
let tsConfig = JSON.parse(json.toString());
|
||||
return tsConfig;
|
||||
}
|
||||
|
||||
export function createTempTsConfig(includeGlob: string[], moduleType: String, pathToWriteFile: string): any {
|
||||
let config = getRootTsConfig();
|
||||
if (!config.compilerOptions) {
|
||||
config.compilerOptions = {};
|
||||
}
|
||||
// for now, we only compiling to same directory (no outdir)
|
||||
if (config.compilerOptions && config.compilerOptions.outDir) {
|
||||
delete config.compilerOptions.outDir;
|
||||
}
|
||||
if (config.compilerOptions) {
|
||||
config.compilerOptions.module = moduleType;
|
||||
}
|
||||
config.include = includeGlob;
|
||||
let json = JSON.stringify(config, null, 2);
|
||||
fs.writeFileSync(pathToWriteFile, json);
|
||||
}
|
||||
|
||||
export function copySourceToDest(destinationPath: string, excludeSpecs: boolean = true, excludeE2e: boolean = true) {
|
||||
let glob = [`${SRC_ROOT}/**/*.ts`];
|
||||
if (excludeSpecs) {
|
||||
glob.push(`!${SRC_ROOT}/**/*.spec.ts`);
|
||||
} else {
|
||||
glob.push(`${SRC_ROOT}/**/*.spec.ts`);
|
||||
}
|
||||
if (excludeE2e) {
|
||||
glob.push(`!${SRC_ROOT}/components/*/test/*/*.ts`);
|
||||
}
|
||||
return src(glob)
|
||||
.pipe(dest(destinationPath));
|
||||
}
|
||||
|
||||
export function copyGlobToDest(sourceGlob: string[], destPath: string) {
|
||||
return src(sourceGlob).pipe(dest(destPath));
|
||||
}
|
||||
|
||||
export function copyFonts(destinationPath: string) {
|
||||
return src([
|
||||
'src/fonts/*.+(ttf|woff|woff2)',
|
||||
'node_modules/ionicons/dist/fonts/*.+(ttf|woff|woff2)'
|
||||
])
|
||||
.pipe(dest(destinationPath));
|
||||
}
|
||||
|
||||
export function compileSass(destinationPath: string) {
|
||||
let sass = require('gulp-sass');
|
||||
let autoprefixer = require('gulp-autoprefixer');
|
||||
let cleanCSS = require('gulp-clean-css');
|
||||
let rename = require('gulp-rename');
|
||||
let buildConfig = require('../build/config');
|
||||
|
||||
let ioniconsPath = path.join(NODE_MODULES_ROOT, 'ionicons/dist/scss/');
|
||||
|
||||
return src([
|
||||
path.join(SRC_ROOT, 'themes/ionic.build.default.scss'),
|
||||
path.join(SRC_ROOT, 'themes/ionic.build.dark.scss')
|
||||
])
|
||||
.pipe(sass({
|
||||
includePaths: [ioniconsPath]
|
||||
}).on('error', sass.logError)
|
||||
)
|
||||
.pipe(autoprefixer(buildConfig.autoprefixer))
|
||||
|
||||
.pipe(rename(function (path) {
|
||||
path.basename = path.basename.replace('.default', '');
|
||||
path.basename = path.basename.replace('.build', '');
|
||||
}))
|
||||
|
||||
.pipe(dest(destinationPath))
|
||||
|
||||
.pipe(cleanCSS())
|
||||
|
||||
.pipe(rename({
|
||||
extname: '.min.css'
|
||||
}))
|
||||
|
||||
.pipe(dest(destinationPath));
|
||||
}
|
||||
|
||||
export function setSassIonicVersion(version: string) {
|
||||
fs.writeFileSync(path.join(SRC_ROOT, 'themes/version.scss'), `$ionic-version: "${version}";`);
|
||||
}
|
||||
|
||||
export function copyFile(srcPath: string, destPath: string) {
|
||||
const sourceData = fs.readFileSync(srcPath);
|
||||
fs.writeFileSync(destPath, sourceData);
|
||||
}
|
||||
|
||||
export function copySwiperToPath(distPath: string, moduleType: string) {
|
||||
copyFile(`${SRC_COMPONENTS_ROOT}/slides/swiper-widget.d.ts`, `${distPath}/swiper-widget.d.ts`);
|
||||
if (!moduleType || moduleType === COMMONJS_MODULE) {
|
||||
copyFile(`${SRC_COMPONENTS_ROOT}/slides/swiper-widget.js`, `${distPath}/swiper-widget.js`);
|
||||
} else if (moduleType === ES_MODULE) {
|
||||
copyFile(`${SRC_COMPONENTS_ROOT}/slides/swiper-widget.es2015.js`, `${distPath}/swiper-widget.js`);
|
||||
} else {
|
||||
copyFile(`${SRC_COMPONENTS_ROOT}/slides/swiper-widget.system.js`, `${distPath}/swiper-widget.system.js`);
|
||||
}
|
||||
}
|
||||
|
||||
export function runNgc(pathToConfigFile: string, done: Function) {
|
||||
let exec = require('child_process').exec;
|
||||
var shellCommand = `node --max_old_space_size=8096 ${PROJECT_ROOT}/node_modules/.bin/ngc -p ${pathToConfigFile}`;
|
||||
|
||||
exec(shellCommand, function(err, stdout, stderr) {
|
||||
console.log(stdout);
|
||||
console.log(stderr);
|
||||
done(err);
|
||||
});
|
||||
}
|
||||
|
||||
export function runTsc(pathToConfigFile: string, done: Function) {
|
||||
let exec = require('child_process').exec;
|
||||
var shellCommand = `node --max_old_space_size=8096 ${PROJECT_ROOT}/node_modules/.bin/tsc -p ${pathToConfigFile}`;
|
||||
|
||||
exec(shellCommand, function(err, stdout, stderr) {
|
||||
console.log(stdout);
|
||||
console.log(stderr);
|
||||
done(err);
|
||||
});
|
||||
}
|
||||
|
||||
export function runWebpack(pathToWebpackConfig: string, done: Function) {
|
||||
let exec = require('child_process').exec;
|
||||
let shellCommand = `node --max_old_space_size=8096 ./node_modules/.bin/webpack --config ${pathToWebpackConfig} --display-error-details`;
|
||||
|
||||
exec(shellCommand, function(err, stdout, stderr) {
|
||||
console.log(stdout);
|
||||
console.log(stderr);
|
||||
done(err);
|
||||
});
|
||||
}
|
||||
|
||||
export function deleteFiles(glob: string[], done: Function) {
|
||||
let del = require('del');
|
||||
del.sync(glob);
|
||||
done();
|
||||
}
|
||||
|
||||
export function createTimestamp() {
|
||||
// YYYYMMDDHHMM
|
||||
var d = new Date();
|
||||
return d.getUTCFullYear() + // YYYY
|
||||
('0' + (d.getUTCMonth() + 1)).slice(-2) + // MM
|
||||
('0' + (d.getUTCDate())).slice(-2) + // DD
|
||||
('0' + (d.getUTCHours())).slice(-2) + // HH
|
||||
('0' + (d.getUTCMinutes())).slice(-2); // MM
|
||||
}
|
Reference in New Issue
Block a user