@@ -5,6 +5,7 @@ const path = require('path');
5
5
const rimraf = require ( 'rimraf' ) ;
6
6
const sortKeys = require ( 'sort-keys' ) ;
7
7
8
+ const { soyExists, } = require ( './soy' ) ;
8
9
const generateSoyDependencies = require ( '../utils/generate-soy-dependencies' ) ;
9
10
const getMergedConfig = require ( '../utils/get-merged-config' ) ;
10
11
const spawnSync = require ( '../utils/spawnSync' ) ;
@@ -20,13 +21,13 @@ const scriptsDependencies = require(path.join(__dirname, '../../package.json'))
20
21
21
22
/**
22
23
* Helper for generating the npm `build` script
23
- * @param {Object } flags Flags included via CLI
24
+ * @param {Object } config Options derived from file structure
24
25
* @returns {string }
25
26
*/
26
- function generateBuildScript ( flags ) {
27
+ function generateBuildScript ( config ) {
27
28
let retStr = '' ;
28
29
29
- if ( flags . soy ) {
30
+ if ( config . soy ) {
30
31
retStr += `metalsoy --soyDeps \"${ generateSoyDependencies (
31
32
NPM_SCRIPTS_CONFIG . build . dependencies
32
33
) } \" && `;
@@ -36,15 +37,13 @@ function generateBuildScript(flags) {
36
37
NPM_SCRIPTS_CONFIG . build . output
37
38
} ${ NPM_SCRIPTS_CONFIG . build . input } `;
38
39
39
- if ( flags . bundler ) {
40
- retStr += ' && liferay-npm-bundler' ;
41
- }
40
+ retStr += ' && liferay-npm-bundler' ;
42
41
43
- if ( flags . bridge ) {
42
+ if ( config . bridge ) {
44
43
retStr += ' && liferay-npm-bridge-generator' ;
45
44
}
46
45
47
- if ( flags . soy ) {
46
+ if ( config . soy ) {
48
47
retStr += '&& npm run cleanSoy' ;
49
48
}
50
49
@@ -55,9 +54,10 @@ function generateBuildScript(flags) {
55
54
* Main function for ejecting configuration to package.json and configuration
56
55
*/
57
56
module . exports = function ( ) {
58
- const flags = projectPackage . scripts . build
59
- . match ( / (?< = - - ) (?: \w + ) / g)
60
- . reduce ( ( prev , cur ) => ( { ...prev , [ cur ] : true , } ) , { } ) ;
57
+ const config = {
58
+ bridge : fs . existsSync ( path . join ( CWD , '.npmbridgerc' ) ) ,
59
+ soy : soyExists ( ) ,
60
+ } ;
61
61
62
62
// Write config for babel
63
63
if ( ! projectPackage . babel ) {
@@ -80,16 +80,14 @@ module.exports = function() {
80
80
}
81
81
82
82
// Write config file for bundler
83
- if ( flags . bundler ) {
84
- fs . writeFileSync (
85
- path . join ( CWD , '.npmbundlerrc' ) ,
86
- JSON . stringify ( BUNDLER_CONFIG , null , '\t' )
87
- ) ;
88
- }
83
+ fs . writeFileSync (
84
+ path . join ( CWD , '.npmbundlerrc' ) ,
85
+ JSON . stringify ( BUNDLER_CONFIG , null , '\t' )
86
+ ) ;
89
87
90
88
// Set initial npm scripts
91
89
projectPackage . scripts = {
92
- build : generateBuildScript ( flags ) ,
90
+ build : generateBuildScript ( ) ,
93
91
format : `csf ${ NPM_SCRIPTS_CONFIG . format . join ( ' ' ) } --inline-edit` ,
94
92
lint : `csf ${ NPM_SCRIPTS_CONFIG . lint . join ( ' ' ) } ` ,
95
93
test : 'jest' ,
@@ -105,27 +103,22 @@ module.exports = function() {
105
103
jest : scriptsDependencies [ 'jest' ] ,
106
104
'liferay-jest-junit-reporter' :
107
105
scriptsDependencies [ 'liferay-jest-junit-reporter' ] ,
106
+ 'liferay-npm-bundler' : scriptsDependencies [ 'liferay-npm-bundler' ] ,
107
+ 'liferay-npm-bundler-preset-liferay-dev' :
108
+ scriptsDependencies [ 'liferay-npm-bundler-preset-liferay-dev' ] ,
108
109
} ;
109
110
110
- // Additional if -- soy flag is included
111
- if ( flags . soy ) {
111
+ // Additional if soy is used
112
+ if ( config . soy ) {
112
113
newDevDependencies [ 'metal-tools-soy' ] =
113
114
scriptsDependencies [ 'metal-tools-soy' ] ;
114
115
newDevDependencies [ 'rimraf' ] = scriptsDependencies [ 'rimraf' ] ;
115
116
116
117
projectPackage . scripts . cleanSoy = 'rimraf src/**/*.soy.js' ;
117
118
}
118
119
119
- // Additional if --bundler flag is included
120
- if ( flags . bundler ) {
121
- newDevDependencies [ 'liferay-npm-bundler' ] =
122
- scriptsDependencies [ 'liferay-npm-bundler' ] ;
123
- newDevDependencies [ 'liferay-npm-bundler-preset-liferay-dev' ] =
124
- scriptsDependencies [ 'liferay-npm-bundler-preset-liferay-dev' ] ;
125
- }
126
-
127
- // Additional if --bridge flag is included
128
- if ( flags . bridge ) {
120
+ // Additional if bridge is used
121
+ if ( config . bridge ) {
129
122
newDevDependencies [ 'liferay-npm-bridge-generator' ] =
130
123
scriptsDependencies [ 'liferay-npm-bridge-generator' ] ;
131
124
}
0 commit comments