@@ -6,8 +6,8 @@ const webpack = require('webpack')
66const nodeExternals = require ( 'webpack-node-externals' )
77
88const isCoverage = process . env . NODE_ENV === 'coverage'
9- const isProd = process . argv . includes ( '--prod ' )
10- const isTest = isCoverage || process . argv . includes ( '-- test' )
9+ const isProd = process . argv . includes ( 'production ' )
10+ const isTest = isCoverage || process . argv . includes ( 'test' )
1111const subDir = isProd ? 'output/prod' : isTest ? 'output/test' : 'output/dev'
1212const outputPath = path . join ( __dirname , subDir )
1313const srcPath = path . join ( __dirname , 'src' )
@@ -48,58 +48,58 @@ const getCopyFile = (database) => {
4848 ]
4949}
5050
51- const getDbFile = ( ) => [ 'bigquery' , 'db2' , 'hive' , 'mariadb' , 'mysql' , 'sqlite' , 'postgresql' , 'transactsql' , 'flinksql' ] . map ( getCopyFile ) . reduce ( ( prev , curr ) => [ ...prev , ...curr ] , [ ] )
52-
5351const getSrcFile = ( ) => fs . readdirSync ( srcPath ) . filter ( name => name !== 'parser.all.js' || name !== 'parser.single.js' ) . map ( name => ( { source : `${ outputPath } /${ name } ` , destination : `${ outputPath } /lib/${ name } ` } ) )
5452
55- const getPlugins = ( parserName , target , plugins ) => [
56- new webpack . DefinePlugin ( {
57- PARSER_NAME : parserName ? JSON . stringify ( parserName ) : 'null' ,
58- } ) ,
59- ...( plugins || [ ] ) ,
60- ...( isProd
61- ? [
62- new CopyPlugin ( {
63- patterns : [
64- 'LICENSE' ,
65- 'lib' ,
66- 'README.md' ,
67- 'package.json' ,
68- 'types.d.ts' ,
69- 'ast/**' ,
70- {
71- from : 'index.d.ts' ,
72- to : ( parserName || 'index' ) + ( target === 'web' ? '.umd' : '' ) + '.d.ts' ,
73- }
74- ] ,
75- } ) ,
76- new FileManagerPlugin ( {
77- onEnd : {
78- mkdir : [
79- `${ outputPath } /umd` ,
80- `${ outputPath } /build` ,
81- `${ outputPath } /lib` ,
82- ] ,
83- copy : [
84- { source : `${ outputPath } /*.umd.d.ts` , destination : `${ outputPath } /umd` } ,
85- { source : `${ outputPath } /*.umd.js` , destination : `${ outputPath } /umd` } ,
86- { source : `${ outputPath } /*.umd.js.map` , destination : `${ outputPath } /umd` } ,
87- ] ,
88- move : [
89- ...getDbFile ( ) ,
90- ...getSrcFile ( ) ,
91- ] ,
92- // delete: [
93- // `${outputPath}/*.umd.d.ts`,
94- // `${outputPath}/*.umd.js`,
95- // `${outputPath}/*.umd.js.map`,
96- // `${outputPath}/index.d.ts`
97- // ]
98- }
99- } )
100- ] : [
101- ] )
102- ]
53+ const getPlugins = ( parserName , target , plugins = [ ] ) => {
54+ const pluginList = [ new webpack . DefinePlugin ( { PARSER_NAME : parserName ? JSON . stringify ( parserName ) : 'null' } ) , ...plugins ]
55+ if ( isProd ) {
56+ const tsFileName = ( parserName || 'index' ) + ( target === 'web' ? '.umd' : '' ) + '.d.ts'
57+ pluginList . push (
58+ new CopyPlugin ( {
59+ patterns : [
60+ 'LICENSE' ,
61+ 'lib' ,
62+ 'README.md' ,
63+ 'package.json' ,
64+ 'types.d.ts' ,
65+ 'ast/**' ,
66+ {
67+ from : 'index.d.ts' ,
68+ to : tsFileName ,
69+ }
70+ ] ,
71+ } ) ,
72+ )
73+ const fileConfig = {
74+ events : { onEnd : { } } ,
75+ runTasksInSeries : true ,
76+ }
77+ if ( parserName === null ) {
78+ if ( target === 'web' ) {
79+ fileConfig . events . onEnd . mkdir = [
80+ `${ outputPath } /umd` ,
81+ `${ outputPath } /build` ,
82+ `${ outputPath } /lib` ,
83+ ]
84+ fileConfig . events . onEnd . move = [
85+ { source : `${ outputPath } /index.umd.js` , destination : `${ outputPath } /umd/index.umd.js` } ,
86+ { source : `${ outputPath } /index.umd.d.ts` , destination : `${ outputPath } /umd/index.umd.d.ts` } ,
87+ { source : `${ outputPath } /index.umd.js.map` , destination : `${ outputPath } /umd/index.umd.js.map` } ,
88+ ]
89+ }
90+ if ( target === 'node' ) fileConfig . events . onEnd . move = getSrcFile ( )
91+ } else {
92+ if ( target === 'node' ) fileConfig . events . onEnd . move = getCopyFile ( parserName )
93+ if ( target === 'web' ) fileConfig . events . onEnd . move = [
94+ { source : `${ outputPath } /${ parserName } .umd.d.ts` , destination : `${ outputPath } /umd/${ parserName } .umd.d.ts` } ,
95+ { source : `${ outputPath } /${ parserName } .umd.js` , destination : `${ outputPath } /umd/${ parserName } .umd.js` } ,
96+ { source : `${ outputPath } /${ parserName } .umd.js.map` , destination : `${ outputPath } /umd/${ parserName } .umd.js.map` } ,
97+ ]
98+ }
99+ pluginList . push ( new FileManagerPlugin ( fileConfig ) )
100+ }
101+ return pluginList
102+ }
103103const getOutput = ( target ) => ( {
104104 path : outputPath ,
105105 library : '' ,
0 commit comments