mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 11:17:19 +08:00
57 lines
2.4 KiB
TypeScript
57 lines
2.4 KiB
TypeScript
import { dirname, join } from 'path';
|
|
import { readFileSync } from 'fs';
|
|
import { spawnSync } from 'child_process';
|
|
|
|
import { task } from 'gulp';
|
|
|
|
import { ES_2015, PROJECT_ROOT } from '../constants';
|
|
import { createTempTsConfig, getFolderInfo, runAppScriptsServe } from '../util';
|
|
|
|
task('e2e.watch', ['e2e.prepare', 'core.watch'], (done: Function) => {
|
|
const folderInfo = getFolderInfo();
|
|
if (!folderInfo || !folderInfo.componentName || !folderInfo.componentTest) {
|
|
done(new Error(`Usage: gulp e2e.watch --folder nav/basic`));
|
|
return;
|
|
}
|
|
|
|
serveTest(folderInfo).then(() => {
|
|
done();
|
|
}).catch((err: Error) => {
|
|
done(err);
|
|
});
|
|
});
|
|
|
|
function serveTest(folderInfo: any) {
|
|
const testOrDemoName = join(folderInfo.componentName, folderInfo.componentTest);
|
|
const ionicAngularDir = join(PROJECT_ROOT, 'src');
|
|
const coreCompilerFilePath = join(PROJECT_ROOT, '..', 'ionic-core', 'dist', 'compiler');
|
|
const coreDir = join(PROJECT_ROOT, 'dist', 'core');
|
|
const srcTestRoot = join(PROJECT_ROOT, 'src', 'components', folderInfo.componentName, 'test', folderInfo.componentTest);
|
|
const distTestRoot = join(PROJECT_ROOT, 'dist', 'e2e', 'components', folderInfo.componentName, 'test', folderInfo.componentTest);
|
|
const includeGlob = [ join(ionicAngularDir, '**', '*.ts')];
|
|
const pathToWriteFile = join(distTestRoot, 'tsconfig.json');
|
|
const pathToReadFile = join(PROJECT_ROOT, 'tsconfig.json');
|
|
|
|
spawnSync('npm', ['run', 'build.stencil']);
|
|
|
|
createTempTsConfig(includeGlob, ES_2015, ES_2015, pathToReadFile, pathToWriteFile, { removeComments: true});
|
|
|
|
const sassConfigPath = join('scripts', 'e2e', 'sass.config.js');
|
|
const copyConfigPath = join('scripts', 'e2e', 'copy.config.js');
|
|
|
|
let appEntryPoint = join(srcTestRoot, 'app', 'main.ts');
|
|
try {
|
|
// check if the entry point exists, otherwise fall back to the legacy entry point without 'app' folder
|
|
readFileSync(appEntryPoint);
|
|
} catch (ex) {
|
|
// the file doesn't exist, so use the legacy entry point
|
|
appEntryPoint = join(srcTestRoot, 'main.ts');
|
|
}
|
|
|
|
// this assume that app.module.ts and main.ts are peers, which they should be no matter what
|
|
const appNgModulePath = join(dirname(appEntryPoint), 'app.module.ts');
|
|
const distDir = join(distTestRoot, 'www');
|
|
|
|
return runAppScriptsServe(testOrDemoName, appEntryPoint, appNgModulePath, ionicAngularDir, distDir, pathToWriteFile, ionicAngularDir, coreCompilerFilePath, coreDir, sassConfigPath, copyConfigPath, null);
|
|
}
|