mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-20 12:29:55 +08:00

* trying Circle CI v2 * paths are fun * seeing how long a demos build takes * Batching Demo builds * testing demo builds on CI2 * batches count from 0 * ok, looks good. preparing for master branch * forgot `production=true` flag. let’s test that quick. * forgot to save the file * making sure that docs are still copied over to ionic-site in the deploy phase * getting ready for the PR again
139 lines
4.0 KiB
TypeScript
139 lines
4.0 KiB
TypeScript
import { dirname, join, relative } from 'path';
|
|
|
|
import * as glob from 'glob';
|
|
import { task } from 'gulp';
|
|
import * as del from 'del';
|
|
import * as runSequence from 'run-sequence';
|
|
import { argv } from 'yargs';
|
|
|
|
|
|
import { DEMOS_SRC_ROOT, ES_2015, PROJECT_ROOT } from '../constants';
|
|
import { createTempTsConfig, getFolderInfo, runAppScriptsBuild, writePolyfills } from '../util';
|
|
|
|
import * as pAll from 'p-all';
|
|
|
|
task('demos.prepare', (done: Function) => {
|
|
runSequence('demos.clean', 'demos.polyfill', 'demos.sass', (err: any) => done(err));
|
|
});
|
|
|
|
task('demos.prod', ['demos.prepare'], (done: Function) => {
|
|
|
|
// okay, first find out all of the demos tests to run by finding all of the 'main.ts' files
|
|
filterDemosEntryPoints().then((filePaths: string[]) => {
|
|
return buildDemos(filePaths);
|
|
}).then(() => {
|
|
done();
|
|
}).catch((err: Error) => {
|
|
done(err);
|
|
});
|
|
});
|
|
|
|
function filterDemosEntryPoints() {
|
|
return getDemosEntryPoints().then((entryPoints: string[]) => {
|
|
const folderInfo = getFolderInfo();
|
|
if (folderInfo && folderInfo.componentName) {
|
|
const filtered = entryPoints.filter(entryPoint => {
|
|
return entryPoint.indexOf(folderInfo.componentName) >= 0;
|
|
});
|
|
return filtered;
|
|
}
|
|
return entryPoints;
|
|
});
|
|
}
|
|
|
|
function getDemosEntryPoints() {
|
|
return new Promise((resolve, reject) => {
|
|
const mainGlob = join(DEMOS_SRC_ROOT, '**', 'main.ts');
|
|
glob(mainGlob, (err: Error, matches: string[]) => {
|
|
if (err) {
|
|
return reject(err);
|
|
}
|
|
resolve(matches);
|
|
});
|
|
});
|
|
}
|
|
|
|
|
|
function buildDemos(filePaths: string[]) {
|
|
var batches = chunkArrayInGroups(filePaths, argv.batches || 1);
|
|
var batch = argv.batch || 0;
|
|
if(batch >= batches.length) {
|
|
throw new Error(`Batch number higher than total number of batches.`);
|
|
}
|
|
|
|
console.log(`Compiling ${batches[batch].length} of ${filePaths.length} Demos ...`);
|
|
|
|
const functions = batches[batch].map(filePath => () => {
|
|
return buildDemo(filePath);
|
|
});
|
|
let concurrentNumber = 2;
|
|
if (argv.concurrency) {
|
|
concurrentNumber = argv.concurrency;
|
|
}
|
|
return pAll(functions, {concurrency: concurrentNumber});
|
|
}
|
|
|
|
function buildDemo(filePath: string) {
|
|
const start = Date.now();
|
|
const ionicAngularDir = join(process.cwd(), 'src');
|
|
|
|
const componentDir = dirname(dirname(filePath));
|
|
const relativePathFromComponents = relative(dirname(DEMOS_SRC_ROOT), componentDir);
|
|
|
|
const distTestRoot = join(process.cwd(), 'dist', 'demos', relativePathFromComponents);
|
|
|
|
const includeGlob = [ join(ionicAngularDir, '**', '*.ts'), join(componentDir, '**', '*.ts')];
|
|
const pathToWriteFile = join(distTestRoot, 'tsconfig.json');
|
|
const pathToReadFile = join(PROJECT_ROOT, 'tsconfig.json');
|
|
|
|
createTempTsConfig(includeGlob, ES_2015, ES_2015, pathToReadFile, pathToWriteFile, { removeComments: true});
|
|
|
|
const sassConfigPath = join('scripts', 'demos', 'sass.config.js');
|
|
const copyConfigPath = join('scripts', 'demos', 'copy.config.js');
|
|
|
|
const appEntryPoint = filePath;
|
|
const appNgModulePath = join(dirname(filePath), 'app.module.ts');
|
|
const distDir = join(distTestRoot, 'www');
|
|
|
|
return runAppScriptsBuild(appEntryPoint, appNgModulePath, ionicAngularDir, distDir, pathToWriteFile, ionicAngularDir, sassConfigPath, copyConfigPath).then(() => {
|
|
const end = Date.now();
|
|
console.log(`${filePath} took a total of ${(end - start) / 1000} seconds to build`);
|
|
});
|
|
}
|
|
|
|
function chunkArrayInGroups(arr, size) {
|
|
var result = [];
|
|
for(var i = 0; i < arr.length; i++) {
|
|
if (!Array.isArray(result[i % size])) {
|
|
result[i % size] = [];
|
|
}
|
|
result[i % size].push(arr[i]);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
task('demos.clean', (done: Function) => {
|
|
// this is a super hack, but it works for now
|
|
if (argv.skipClean) {
|
|
return done();
|
|
}
|
|
|
|
del(['dist/demos/**']).then(() => {
|
|
done();
|
|
}).catch(err => {
|
|
done(err);
|
|
});
|
|
});
|
|
|
|
task('demos.polyfill', (done: Function) => {
|
|
if (argv.skipPolyfill) {
|
|
return done();
|
|
}
|
|
|
|
writePolyfills('dist/demos/polyfills').then(() => {
|
|
done();
|
|
}).catch(err => {
|
|
done(err);
|
|
});
|
|
});
|