1
1
/*jshint node: true*/
2
2
'use strict' ;
3
3
4
+ const spawn = require ( 'cross-spawn' ) ;
4
5
const fs = require ( 'fs-extra' ) ;
5
6
const rimraf = require ( 'rimraf' ) ;
6
7
const logger = require ( '@blackbaud/skyux-logger' ) ;
7
8
8
9
const stageTypeScriptFiles = require ( './utils/stage-library-ts' ) ;
9
10
const preparePackage = require ( './utils/prepare-library-package' ) ;
10
- const webpackConfig = require ( '../config/webpack/build-public-library.webpack.config.js' ) ;
11
11
const skyPagesConfigUtil = require ( '../config/sky-pages/sky-pages.config' ) ;
12
12
const runCompiler = require ( './utils/run-compiler' ) ;
13
13
const tsLinter = require ( './utils/ts-linter' ) ;
@@ -81,9 +81,14 @@ function writeTSConfig() {
81
81
fs . writeJSONSync ( skyPagesConfigUtil . spaPathTemp ( 'tsconfig.json' ) , config ) ;
82
82
}
83
83
84
+ /**
85
+ * Create a "placeholder" module for Angular AoT compiler.
86
+ * This is needed to avoid breaking changes; in the future,
87
+ * we should require a module name be provided by the consumer.
88
+ */
84
89
function writePlaceholderModule ( ) {
85
90
const content = `import { NgModule } from '@angular/core';
86
- import './index';
91
+ export * from './index';
87
92
@NgModule({})
88
93
export class SkyLibPlaceholderModule {}
89
94
` ;
@@ -93,11 +98,42 @@ export class SkyLibPlaceholderModule {}
93
98
} ) ;
94
99
}
95
100
96
- function transpile ( skyPagesConfig , webpack ) {
101
+ /**
102
+ * Creates a UMD JavaScript bundle.
103
+ * @param {* } skyPagesConfig
104
+ * @param {* } webpack
105
+ */
106
+ function createBundle ( skyPagesConfig , webpack ) {
107
+ const webpackConfig = require ( '../config/webpack/build-public-library.webpack.config' ) ;
97
108
const config = webpackConfig . getWebpackConfig ( skyPagesConfig ) ;
98
109
return runCompiler ( webpack , config ) ;
99
110
}
100
111
112
+ /**
113
+ * Transpiles TypeScript files into JavaScript files
114
+ * to be included with the NPM package.
115
+ */
116
+ function transpile ( ) {
117
+ return new Promise ( ( resolve , reject ) => {
118
+ const result = spawn . sync (
119
+ 'node' ,
120
+ [
121
+ skyPagesConfigUtil . spaPath ( 'node_modules' , '.bin' , 'ngc' ) ,
122
+ '--project' ,
123
+ skyPagesConfigUtil . spaPathTemp ( 'tsconfig.json' )
124
+ ] ,
125
+ { stdio : 'inherit' }
126
+ ) ;
127
+
128
+ if ( result . err ) {
129
+ reject ( result . err ) ;
130
+ return ;
131
+ }
132
+
133
+ resolve ( ) ;
134
+ } ) ;
135
+ }
136
+
101
137
module . exports = ( skyPagesConfig , webpack ) => {
102
138
runLinter ( ) ;
103
139
cleanAll ( ) ;
@@ -106,7 +142,8 @@ module.exports = (skyPagesConfig, webpack) => {
106
142
writePlaceholderModule ( ) ;
107
143
copyRuntime ( ) ;
108
144
109
- return transpile ( skyPagesConfig , webpack )
145
+ return createBundle ( skyPagesConfig , webpack )
146
+ . then ( ( ) => transpile ( ) )
110
147
. then ( ( ) => {
111
148
cleanRuntime ( ) ;
112
149
preparePackage ( ) ;
0 commit comments