@@ -22,6 +22,33 @@ async function readJSON( filename ) {
22
22
return JSON . parse ( await read ( filename ) ) ;
23
23
}
24
24
25
+ async function getOutputRollupOptions ( {
26
+ esm = false
27
+ } = { } ) {
28
+ const wrapperFilePath = path . join ( "src" , `wrapper${
29
+ esm ? "-esm" : ""
30
+ } .js` ) ;
31
+
32
+ const wrapperSource = await read ( wrapperFilePath ) ;
33
+
34
+ // Catch `// @CODE` and subsequent comment lines event if they don't start
35
+ // in the first column.
36
+ const wrapper = wrapperSource . split (
37
+ / [ \x20 \t ] * \/ \/ @ C O D E \n (?: [ \x20 \t ] * \/ \/ [ ^ \n ] + \n ) * /
38
+ ) ;
39
+
40
+ return {
41
+
42
+ // The ESM format is not actually used as we strip it during the
43
+ // build, inserting our own wrappers; it's just that it doesn't
44
+ // generate any extra wrappers so there's nothing for us to remove.
45
+ format : "esm" ,
46
+
47
+ intro : wrapper [ 0 ] . replace ( / \n * $ / , "" ) ,
48
+ outro : wrapper [ 1 ] . replace ( / ^ \n * / , "" )
49
+ } ;
50
+ }
51
+
25
52
async function writeCompiled ( { code, dir, filename, version } ) {
26
53
const compiledContents = code
27
54
@@ -34,12 +61,12 @@ async function writeCompiled( { code, dir, filename, version } ) {
34
61
35
62
await writeFile ( path . join ( dir , filename ) , compiledContents ) ;
36
63
console . log ( `[${ getTimestamp ( ) } ] ${ filename } v${ version } created.` ) ;
37
- await minify ( { dir, filename, version } ) ;
38
64
}
39
65
40
66
export async function build ( {
41
67
dir = "dist" ,
42
68
filename = "jquery-migrate.js" ,
69
+ esm = false ,
43
70
watch = false ,
44
71
version
45
72
} = { } ) {
@@ -59,24 +86,8 @@ export async function build( {
59
86
} `;
60
87
}
61
88
62
- // Catch `// @CODE` and subsequent comment lines event if they don't start
63
- // in the first column.
64
- const wrapperSrc = await read ( "src/wrapper.js" ) ;
65
- const wrapper = wrapperSrc . split (
66
- / [ \x20 \t ] * \/ \/ @ C O D E \n (?: [ \x20 \t ] * \/ \/ [ ^ \n ] + \n ) * /
67
- ) ;
68
-
69
89
const inputRollupOptions = { } ;
70
- const outputRollupOptions = {
71
-
72
- // The ESM format is not actually used as we strip it during
73
- // the build; it's just that it doesn't generate any extra
74
- // wrappers so there's nothing for us to remove.
75
- format : "esm" ,
76
-
77
- intro : wrapper [ 0 ] . replace ( / \n * $ / , "" ) ,
78
- outro : wrapper [ 1 ] . replace ( / ^ \n * / , "" )
79
- } ;
90
+ const outputRollupOptions = await getOutputRollupOptions ( { esm } ) ;
80
91
const src = "src/migrate.js" ;
81
92
82
93
inputRollupOptions . input = path . resolve ( src ) ;
@@ -122,9 +133,33 @@ export async function build( {
122
133
} = await bundle . generate ( outputRollupOptions ) ;
123
134
124
135
await writeCompiled ( { code, dir, filename, version } ) ;
136
+ await minify ( { dir, filename, version } ) ;
137
+ }
138
+ }
125
139
140
+ export async function buildDefaultFiles ( {
141
+ version = process . env . VERSION ,
142
+ watch
143
+ } = { } ) {
144
+ await Promise . all ( [
145
+ build ( { version, watch } ) ,
146
+ build ( {
147
+ dir : "dist-module" ,
148
+ filename : "jquery-migrate.module.js" ,
149
+ esm : true ,
150
+ version,
151
+ watch
152
+ } )
153
+ ] ) ;
154
+
155
+ if ( watch ) {
156
+ console . log ( "Watching files..." ) ;
157
+ } else {
126
158
return compareSize ( {
127
- files : [ "dist/jquery-migrate.min.js" ]
159
+ files : [
160
+ "dist/jquery-migrate.min.js" ,
161
+ "dist-module/jquery-migrate.module.min.js"
162
+ ]
128
163
} ) ;
129
164
}
130
165
}
0 commit comments