Skip to content
This repository was archived by the owner on Dec 8, 2022. It is now read-only.

Commit d3d8e68

Browse files
author
Bobby Earl
authored
Moved failed build logic from webpack into respective callers. (#404)
* Moved failed build logic from webpack into respective callers (needed for e2e). * Fixed linting error * Fixed errors. Making logs more quiet. * Refactored build into run-build. Having cli/build + cli/e2e call it. * Fixed linting errors. * Converting build stats to chunks for e2e
1 parent b038bec commit d3d8e68

16 files changed

+617
-698
lines changed

cli/build-public-library.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
const fs = require('fs-extra');
55
const rimraf = require('rimraf');
6+
const logger = require('@blackbaud/skyux-logger');
67

78
const stageTypeScriptFiles = require('./utils/stage-library-ts');
89
const preparePackage = require('./utils/prepare-library-package');
@@ -99,8 +100,9 @@ module.exports = (skyPagesConfig, webpack) => {
99100
cleanTemp();
100101
process.exit(0);
101102
})
102-
.catch(() => {
103+
.catch((err) => {
103104
cleanAll();
105+
logger.error(err);
104106
process.exit(1);
105107
});
106108
};

cli/build.js

+11-172
Original file line numberDiff line numberDiff line change
@@ -1,187 +1,26 @@
11
/*jshint node: true*/
22
'use strict';
33

4-
const fs = require('fs-extra');
5-
const merge = require('../utils/merge');
6-
7-
const skyPagesConfigUtil = require('../config/sky-pages/sky-pages.config');
8-
const generator = require('../lib/sky-pages-module-generator');
9-
const assetsProcessor = require('../lib/assets-processor');
10-
const pluginFileProcessor = require('../lib/plugin-file-processor');
11-
const localeAssetsProcessor = require('../lib/locale-assets-processor');
12-
13-
const server = require('./utils/server');
14-
const browser = require('./utils/browser');
15-
const runCompiler = require('./utils/run-compiler');
16-
const tsLinter = require('./utils/ts-linter');
17-
18-
function writeTSConfig() {
19-
var config = {
20-
'compilerOptions': {
21-
'target': 'es5',
22-
'module': 'es2015',
23-
'moduleResolution': 'node',
24-
'emitDecoratorMetadata': true,
25-
'experimentalDecorators': true,
26-
'sourceMap': true,
27-
'noEmitHelpers': true,
28-
'noImplicitAny': true,
29-
'rootDir': '.',
30-
'inlineSources': true,
31-
'declaration': true,
32-
'skipLibCheck': true,
33-
'lib': [
34-
'es2015',
35-
'dom'
36-
],
37-
'types': [
38-
'jasmine',
39-
'node'
40-
]
41-
},
42-
'files': [
43-
'./app/app.module.ts'
44-
],
45-
'exclude': [
46-
'node_modules',
47-
skyPagesConfigUtil.outPath('node_modules'),
48-
'**/*.spec.ts'
49-
],
50-
'compileOnSave': false,
51-
'buildOnSave': false,
52-
'angularCompilerOptions': {
53-
'debug': true,
54-
'genDir': './ngfactory',
55-
'skipMetadataEmit': true
56-
}
57-
};
58-
59-
fs.writeJSONSync(skyPagesConfigUtil.spaPathTempSrc('tsconfig.json'), config);
60-
}
61-
62-
function stageAot(skyPagesConfig, assetsBaseUrl, assetsRel) {
63-
let skyPagesConfigOverrides = {
64-
runtime: {
65-
spaPathAlias: '../..',
66-
skyPagesOutAlias: '../..',
67-
// These files won't be copied to the temp folder because the consuming project will
68-
// be referencing it by its Node package name. Make sure this code also references its
69-
// Node package name rather than a local path; otherwise TypeScript will treat them as
70-
// different types and Angular will throw an error when trying to inject an instance
71-
// of a class (such as SkyAuthHttp) by its type.
72-
runtimeAlias: '@blackbaud/skyux-builder/runtime',
73-
useTemplateUrl: true
74-
}
75-
};
76-
77-
if (skyPagesConfig && skyPagesConfig.skyux && skyPagesConfig.skyux.importPath) {
78-
skyPagesConfigOverrides.runtime.skyuxPathAlias = '../../' + skyPagesConfig.skyux.importPath;
79-
}
80-
81-
const spaPathTempSrc = skyPagesConfigUtil.spaPathTempSrc();
82-
83-
fs.ensureDirSync(spaPathTempSrc);
84-
fs.emptyDirSync(spaPathTempSrc);
85-
86-
merge(skyPagesConfig, skyPagesConfigOverrides);
87-
let skyPagesModuleSource = generator.getSource(skyPagesConfig);
88-
89-
// The Webpack loader that processes referenced asset files will have run and emitted
90-
// the appropriate files, but the AoT compiler will not pick up changes to the contents
91-
// of the sky-pages.module.ts file. Process the file again to do the replacements
92-
// before writing the file to disk.
93-
skyPagesModuleSource = assetsProcessor.processAssets(
94-
skyPagesModuleSource,
95-
assetsProcessor.getAssetsUrl(skyPagesConfig, assetsBaseUrl, assetsRel)
96-
);
97-
98-
fs.copySync(
99-
skyPagesConfigUtil.outPath('src'),
100-
spaPathTempSrc
101-
);
102-
103-
fs.copySync(
104-
skyPagesConfigUtil.spaPath('src'),
105-
spaPathTempSrc
106-
);
107-
108-
fs.writeFileSync(
109-
skyPagesConfigUtil.spaPathTempSrc('app', 'sky-pages.module.ts'),
110-
skyPagesModuleSource,
111-
{
112-
encoding: 'utf8'
113-
}
114-
);
115-
116-
pluginFileProcessor.processFiles(skyPagesConfig);
117-
writeTSConfig();
118-
}
119-
120-
function cleanupAot() {
121-
fs.removeSync(skyPagesConfigUtil.spaPathTemp());
122-
}
123-
124-
function buildServe(argv, skyPagesConfig, webpack, isAot) {
125-
const base = skyPagesConfigUtil.getAppBase(skyPagesConfig);
126-
return server
127-
.start(base)
128-
.then(port => {
129-
argv.assets = argv.assets || `https://localhost:${port}`;
130-
return buildCompiler(argv, skyPagesConfig, webpack, isAot)
131-
.then(stats => {
132-
browser(argv, skyPagesConfig, stats, port);
133-
return stats;
134-
});
135-
});
136-
}
137-
138-
function buildCompiler(argv, skyPagesConfig, webpack, isAot) {
139-
const assetsBaseUrl = argv.assets || '';
140-
const assetsRel = argv.assetsrel;
141-
142-
let buildConfig;
143-
144-
if (isAot) {
145-
stageAot(skyPagesConfig, assetsBaseUrl, assetsRel);
146-
buildConfig = require('../config/webpack/build-aot.webpack.config');
147-
} else {
148-
buildConfig = require('../config/webpack/build.webpack.config');
149-
}
150-
151-
const config = buildConfig.getWebpackConfig(skyPagesConfig, argv);
152-
assetsProcessor.setSkyAssetsLoaderUrl(config, skyPagesConfig, assetsBaseUrl, assetsRel);
153-
154-
return runCompiler(webpack, config, isAot)
155-
.then(stats => {
156-
if (isAot) {
157-
cleanupAot();
158-
}
159-
160-
return stats;
161-
});
162-
}
4+
const logger = require('@blackbaud/skyux-logger');
5+
const runBuild = require('./utils/run-build');
1636

1647
/**
1658
* Executes the build command.
1669
* @name build
16710
* @param {*} skyPagesConfig
16811
* @param {*} webpack
16912
* @param {*} isAot
13+
* @param {*} cancelProcessExit
17014
*/
17115
function build(argv, skyPagesConfig, webpack) {
172-
173-
const lintResult = tsLinter.lintSync();
174-
const isAot = skyPagesConfig &&
175-
skyPagesConfig.skyux &&
176-
skyPagesConfig.skyux.compileMode === 'aot';
177-
178-
if (lintResult.exitCode > 0) {
179-
process.exit(lintResult.exitCode);
180-
} else {
181-
localeAssetsProcessor.prepareLocaleFiles();
182-
const name = argv.serve ? buildServe : buildCompiler;
183-
return name(argv, skyPagesConfig, webpack, isAot);
184-
}
16+
return runBuild(argv, skyPagesConfig, webpack)
17+
.then(() => {
18+
logger.info('Build successfully completed.');
19+
})
20+
.catch(err => {
21+
logger.error(err);
22+
process.exit(1);
23+
});
18524
}
18625

18726
module.exports = build;

cli/e2e.js

+17-24
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const selenium = require('selenium-standalone');
99
const protractorLauncher = require('protractor/built/launcher');
1010
const logger = require('@blackbaud/skyux-logger');
1111

12-
const build = require('./build');
12+
const build = require('./utils/run-build');
1313
const server = require('./utils/server');
1414
const configResolver = require('./utils/config-resolver');
1515

@@ -121,29 +121,22 @@ function spawnSelenium(configPath) {
121121
* Spawns the build process. Captures the config used.
122122
*/
123123
function spawnBuild(argv, skyPagesConfig, webpack) {
124-
return new Promise((resolve, reject) => {
125124

126-
if (argv.build === false) {
127-
logger.info('Skipping build step');
125+
if (argv.build === false) {
126+
logger.info('Skipping build step');
128127

129-
const file = 'dist/metadata.json';
130-
if (!fs.existsSync(file)) {
131-
logger.info(`Unable to skip build step. "${file}" not found.`);
132-
} else {
133-
return resolve({
134-
metadata: fs.readJsonSync(file)
135-
});
136-
}
128+
const file = 'dist/metadata.json';
129+
if (!fs.existsSync(file)) {
130+
logger.info(`Unable to skip build step. "${file}" not found.`);
131+
} else {
132+
return Promise.resolve({
133+
metadata: fs.readJsonSync(file)
134+
});
137135
}
136+
}
138137

139-
logger.info('Running build...');
140-
build(argv, skyPagesConfig, webpack)
141-
.then(stats => {
142-
logger.info('Build complete.');
143-
resolve(stats.toJson().chunks);
144-
})
145-
.catch(reject);
146-
});
138+
return build(argv, skyPagesConfig, webpack)
139+
.then(stats => stats.toJson().chunks);
147140
}
148141

149142
/**
@@ -182,16 +175,16 @@ function e2e(command, argv, skyPagesConfig, webpack) {
182175
spawnSelenium(configPath)
183176
]);
184177
})
185-
.then(values => {
178+
.then(([chunks, port]) => {
186179
spawnProtractor(
187180
configPath,
188-
values[0],
189-
values[1],
181+
chunks,
182+
port,
190183
skyPagesConfig
191184
);
192185
})
193186
.catch(err => {
194-
logger.warn(`ERROR [skyux e2e]: ${err.message}`);
187+
logger.error(err);
195188
killServers(1);
196189
});
197190
}

0 commit comments

Comments
 (0)