Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit 8ce3a05

Browse files
committed
refactor(tasks): generate context before running any tasks
1 parent 3532bdc commit 8ce3a05

File tree

16 files changed

+46
-55
lines changed

16 files changed

+46
-55
lines changed

src/build.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { bundle, bundleUpdate } from './bundle';
66
import { clean } from './clean';
77
import { copy } from './copy';
88
import { emit, EventType } from './util/events';
9-
import { generateContext } from './util/config';
109
import { lint, lintUpdate } from './lint';
1110
import { Logger } from './logger/logger';
1211
import { minifyCss, minifyJs } from './minify';
@@ -17,7 +16,6 @@ import { transpile, transpileUpdate, transpileDiagnosticsOnly } from './transpil
1716

1817

1918
export function build(context: BuildContext) {
20-
context = generateContext(context);
2119
setContext(context);
2220
const logger = new Logger(`build ${(context.isProd ? 'prod' : 'dev')}`);
2321

@@ -33,7 +31,7 @@ export function build(context: BuildContext) {
3331
}
3432

3533
function handleDeprecations(error: Error) {
36-
if (error && error.message && error.message.indexOf('ENOENT') >= 0 && error.message.indexOf(process.env.IONIC_APP_ENTRY_POINT_PATH)) {
34+
if (error && error.message && error.message.indexOf('ENOENT') >= 0 && error.message.indexOf(process.env.IONIC_APP_ENTRY_POINT)) {
3735
const error = new BuildError(`"main.dev.ts" and "main.prod.ts" have been deprecated. Please create a new file "main.ts" containing the content of "main.dev.ts", and then delete the deprecated files.
3836
For more information, please see the default Ionic project main.ts file here:
3937
https://github.com/driftyco/ionic2-app-base/tree/master/src/app/main.ts`);
@@ -55,7 +53,7 @@ function buildWorker(context: BuildContext) {
5553
function validateRequiredFilesExist() {
5654
// for now, just do the entry point
5755
// eventually this could be Promise.all and load a bunch of stuff
58-
return readFileAsync(process.env.IONIC_APP_ENTRY_POINT_PATH);
56+
return readFileAsync(process.env.IONIC_APP_ENTRY_POINT);
5957
}
6058

6159
function buildProject(context: BuildContext) {
@@ -75,7 +73,7 @@ function buildProject(context: BuildContext) {
7573
const minPromise = (context.runMinifyJs) ? minifyJs(context) : Promise.resolve();
7674
const sassPromise = sass(context)
7775
.then(() => {
78-
return (context.runMinifyCss) ? minifyCss(context) : Promise.resolve()
76+
return (context.runMinifyCss) ? minifyCss(context) : Promise.resolve();
7977
});
8078

8179
return Promise.all([

src/bundle.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import { BuildContext, ChangedFile } from './util/interfaces';
22
import { BuildError, IgnorableError } from './util/errors';
3-
import { generateContext, BUNDLER_ROLLUP } from './util/config';
3+
import { BUNDLER_ROLLUP } from './util/config';
44
import { rollup, rollupUpdate, getRollupConfig, getOutputDest as rollupGetOutputDest } from './rollup';
55
import { webpack, webpackUpdate, getWebpackConfig, getOutputDest as webpackGetOutputDest } from './webpack';
66

77

8-
export function bundle(context?: BuildContext, configFile?: string) {
9-
context = generateContext(context);
10-
8+
export function bundle(context: BuildContext, configFile?: string) {
119
return bundleWorker(context, configFile)
1210
.catch((err: Error) => {
1311
throw new BuildError(err);

src/clean.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import { BuildContext } from './util/interfaces';
22
import { BuildError } from './util/errors';
33
import { emptyDirSync } from 'fs-extra';
4-
import { generateContext } from './util/config';
54
import { Logger } from './logger/logger';
65

76

8-
export function clean(context?: BuildContext) {
9-
context = generateContext(context);
10-
7+
export function clean(context: BuildContext) {
118
const logger = new Logger('clean');
129

1310
try {

src/cleancss.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import { join } from 'path';
22
import { BuildContext, TaskInfo } from './util/interfaces';
33
import { BuildError } from './util/errors';
4-
import { fillConfigDefaults, generateContext, getUserConfigFile } from './util/config';
4+
import { fillConfigDefaults, getUserConfigFile } from './util/config';
55
import { Logger } from './logger/logger';
66
import { readFileAsync, writeFileAsync } from './util/helpers';
77
import { runWorker } from './worker-client';
88
import * as cleanCss from 'clean-css';
99

1010

11-
export function cleancss(context?: BuildContext, configFile?: string) {
12-
context = generateContext(context);
11+
export function cleancss(context: BuildContext, configFile?: string) {
1312
configFile = getUserConfigFile(context, taskInfo, configFile);
1413

1514
const logger = new Logger('cleancss');

src/closure.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1+
import { execSync } from 'child_process';
12
import { BuildContext, TaskInfo } from './util/interfaces';
2-
import { generateContext, getUserConfigFile } from './util/config';
3+
import { fillConfigDefaults, getUserConfigFile } from './util/config';
34
import { Logger } from './logger/logger';
45
import { runWorker } from './worker-client';
56

6-
7-
export function closure(context?: BuildContext, configFile?: string) {
8-
context = generateContext(context);
7+
export function closure(context: BuildContext, configFile?: string) {
98
configFile = getUserConfigFile(context, taskInfo, configFile);
109

1110
const logger = new Logger('closure');
@@ -19,7 +18,6 @@ export function closure(context?: BuildContext, configFile?: string) {
1918
});
2019
}
2120

22-
2321
export function closureWorker(context: BuildContext, configFile: string): Promise<any> {
2422
return new Promise((resolve, reject) => {
2523
Logger.warn('Closer Compiler unsupported at this time.');
@@ -28,11 +26,24 @@ export function closureWorker(context: BuildContext, configFile: string): Promis
2826
}
2927

3028

31-
export function isClosureSupported(context: BuildContext) {
32-
// TODO: check for Java and compiler.jar executable
29+
export function isClosureSupported(context: BuildContext): boolean{
30+
/*const config = getClosureConfig(context, '');
31+
try {
32+
execSync(`${config.pathToJavaExecutable} --version`);
33+
return true;
34+
} catch (ex) {
35+
Logger.debug('[Closure] isClosureSupported: Failed to execute java command');
36+
return false;
37+
}
38+
*/
3339
return false;
3440
}
3541

42+
function getClosureConfig(context: BuildContext, configFile: string): ClosureConfig {
43+
configFile = getUserConfigFile(context, taskInfo, configFile);
44+
45+
return fillConfigDefaults(configFile, taskInfo.defaultConfigFile);
46+
}
3647

3748
const taskInfo: TaskInfo = {
3849
fullArg: '--closure',
@@ -46,4 +57,5 @@ const taskInfo: TaskInfo = {
4657
export interface ClosureConfig {
4758
// https://developers.google.com/closure/compiler/docs/gettingstarted_app
4859
pathToJavaExecutable: string;
60+
pathToClosureJar: string;
4961
}

src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export * from './util/config';
1414
export * from './util/helpers';
1515
export * from './util/interfaces';
1616

17+
import { generateContext } from './util/config';
1718
import { getAppScriptsVersion } from './util/helpers';
1819
import { Logger } from './logger/logger';
1920

@@ -23,7 +24,8 @@ export function run(task: string) {
2324
} catch (e) {}
2425

2526
try {
26-
require(`../dist/${task}`)[task]().catch((err: any) => {
27+
const context = generateContext(null);
28+
require(`../dist/${task}`)[task](context).catch((err: any) => {
2729
errorLog(task, err);
2830
});
2931
} catch (e) {

src/lint.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { access } from 'fs';
22
import { BuildContext, ChangedFile, TaskInfo } from './util/interfaces';
33
import { BuildError } from './util/errors';
44
import { createProgram, findConfiguration, getFileNames } from 'tslint';
5-
import { generateContext, getUserConfigFile } from './util/config';
5+
import { getUserConfigFile } from './util/config';
66
import { join } from 'path';
77
import { Logger } from './logger/logger';
88
import { printDiagnostics, DiagnosticsType } from './logger/logger-diagnostics';
@@ -13,9 +13,7 @@ import * as fs from 'fs';
1313
import * as ts from 'typescript';
1414

1515

16-
export function lint(context?: BuildContext, configFile?: string) {
17-
context = generateContext(context);
18-
16+
export function lint(context: BuildContext, configFile?: string) {
1917
return runWorker('lint', 'lintWorker', context, configFile)
2018
.catch(err => {
2119
throw new BuildError(err);

src/minify.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import { BuildContext } from './util/interfaces';
22
import { cleancss } from './cleancss';
33
import { closure, isClosureSupported } from './closure';
4-
import { generateContext } from './util/config';
54
import { Logger } from './logger/logger';
65
import { uglifyjs } from './uglifyjs';
76

87

9-
export function minify(context?: BuildContext) {
10-
context = generateContext(context);
8+
export function minify(context: BuildContext) {
119

1210
const logger = new Logger('minify');
1311

src/ngc.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { Logger } from './logger/logger';
2-
import { generateContext, getUserConfigFile} from './util/config';
2+
import { getUserConfigFile} from './util/config';
33
import { BuildContext, TaskInfo } from './util/interfaces';
44
import { AotCompiler } from './aot/aot-compiler';
55

6-
export function ngc(context?: BuildContext, configFile?: string) {
7-
context = generateContext(context);
6+
export function ngc(context: BuildContext, configFile?: string) {
87
configFile = getUserConfigFile(context, taskInfo, configFile);
98

109
const logger = new Logger('ngc');
@@ -19,7 +18,7 @@ export function ngc(context?: BuildContext, configFile?: string) {
1918
}
2019

2120
export function ngcWorker(context: BuildContext, configFile: string) {
22-
const compiler = new AotCompiler(context, { entryPoint: process.env.IONIC_APP_ENTRY_POINT_PATH, rootDir: context.rootDir, tsConfigPath: process.env.IONIC_TS_CONFIG_PATH });
21+
const compiler = new AotCompiler(context, { entryPoint: process.env.IONIC_APP_ENTRY_POINT, rootDir: context.rootDir, tsConfigPath: process.env.IONIC_TS_CONFIG });
2322
return compiler.compile();
2423
}
2524

src/rollup.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import { BuildContext, BuildState, ChangedFile, TaskInfo } from './util/interfaces';
22
import { BuildError } from './util/errors';
3-
import { fillConfigDefaults, generateContext, getUserConfigFile, replacePathVars } from './util/config';
3+
import { fillConfigDefaults, getUserConfigFile, replacePathVars } from './util/config';
44
import { ionicRollupResolverPlugin, PLUGIN_NAME } from './rollup/ionic-rollup-resolver-plugin';
55
import { join, isAbsolute, normalize, sep } from 'path';
66
import { Logger } from './logger/logger';
77
import * as rollupBundler from 'rollup';
88

99

1010
export function rollup(context: BuildContext, configFile: string) {
11-
context = generateContext(context);
1211
configFile = getUserConfigFile(context, taskInfo, configFile);
1312

1413
const logger = new Logger('rollup');

0 commit comments

Comments
 (0)