Skip to content

Commit

Permalink
refactor: update prepublish issue
Browse files Browse the repository at this point in the history
  • Loading branch information
taozhi8833998 committed Jul 27, 2022
1 parent ae36197 commit 9de356b
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 61 deletions.
2 changes: 1 addition & 1 deletion ast/postgresql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ export type with_clause = cte_definition[] | [cte_definition & {recursive: true;

export type cte_definition = { name: { type: 'default'; value: string; }; stmt: crud_stmt; columns?: cte_column_definition; };

export type cte_column_definition = column[];
export type cte_column_definition = column_ref_list;

export type distinct_on = {type: string; columns: column_ref_list;} | { type: string | undefined; };

Expand Down
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from '../types';
export * from './types';
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"version": "4.4.0",
"description": "simple node sql parser",
"main": "index.js",
"types": "types.d.ts",
"types": "index.d.ts",
"scripts": {
"start": "webpack --config webpack.config.js",
"build": "npm run lint && npm run compile && webpack --config webpack.config.js --prod",
"build": "npm run lint && npm run compile && webpack --config webpack.config.js --mode production",
"test": "npm run lint && mochapack \"test/**/*.spec.js\"",
"lint": "eslint src",
"compile": "babel src -d lib",
Expand Down Expand Up @@ -36,14 +36,14 @@
"ast/",
"build",
"lib",
"index.js",
"umd/",
"index.d.ts",
"index.js",
"index.js.map",
"umd/",
"README.md",
"LICENSE",
"package.json",
"types.d.ts",
"LICENSE"
"README.md",
"types.d.ts"
],
"license": "GPLv2",
"bugs": {
Expand Down
104 changes: 52 additions & 52 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const webpack = require('webpack')
const nodeExternals = require('webpack-node-externals')

const isCoverage = process.env.NODE_ENV === 'coverage'
const isProd = process.argv.includes('--prod')
const isTest = isCoverage || process.argv.includes('--test')
const isProd = process.argv.includes('production')
const isTest = isCoverage || process.argv.includes('test')
const subDir = isProd ? 'output/prod' : isTest ? 'output/test' : 'output/dev'
const outputPath = path.join(__dirname, subDir)
const srcPath = path.join(__dirname, 'src')
Expand Down Expand Up @@ -48,58 +48,58 @@ const getCopyFile = (database) => {
]
}

const getDbFile = () => ['bigquery', 'db2', 'hive', 'mariadb', 'mysql', 'sqlite', 'postgresql', 'transactsql', 'flinksql'].map(getCopyFile).reduce((prev, curr) => [...prev, ...curr], [])

const getSrcFile = () => fs.readdirSync(srcPath).filter(name => name !== 'parser.all.js' || name !== 'parser.single.js').map(name => ({ source: `${outputPath}/${name}`, destination: `${outputPath}/lib/${name}` }))

const getPlugins = (parserName, target, plugins) => [
new webpack.DefinePlugin({
PARSER_NAME: parserName ? JSON.stringify(parserName) : 'null',
}),
...(plugins || []),
...(isProd
? [
new CopyPlugin({
patterns: [
'LICENSE',
'lib',
'README.md',
'package.json',
'types.d.ts',
'ast/**',
{
from: 'index.d.ts',
to: (parserName || 'index') + (target === 'web' ? '.umd' : '') + '.d.ts',
}
],
}),
new FileManagerPlugin({
onEnd: {
mkdir: [
`${outputPath}/umd`,
`${outputPath}/build`,
`${outputPath}/lib`,
],
copy: [
{ source: `${outputPath}/*.umd.d.ts`, destination: `${outputPath}/umd` },
{ source: `${outputPath}/*.umd.js`, destination: `${outputPath}/umd` },
{ source: `${outputPath}/*.umd.js.map`, destination: `${outputPath}/umd` },
],
move: [
...getDbFile(),
...getSrcFile(),
],
// delete: [
// `${outputPath}/*.umd.d.ts`,
// `${outputPath}/*.umd.js`,
// `${outputPath}/*.umd.js.map`,
// `${outputPath}/index.d.ts`
// ]
}
})
] : [
])
]
const getPlugins = (parserName, target, plugins = []) => {
const pluginList = [new webpack.DefinePlugin({ PARSER_NAME: parserName ? JSON.stringify(parserName) : 'null' }), ...plugins]
if (isProd) {
const tsFileName = (parserName || 'index') + (target === 'web' ? '.umd' : '') + '.d.ts'
pluginList.push(
new CopyPlugin({
patterns: [
'LICENSE',
'lib',
'README.md',
'package.json',
'types.d.ts',
'ast/**',
{
from: 'index.d.ts',
to: tsFileName,
}
],
}),
)
const fileConfig = {
events: { onEnd: {} },
runTasksInSeries: true,
}
if (parserName === null) {
if (target === 'web') {
fileConfig.events.onEnd.mkdir = [
`${outputPath}/umd`,
`${outputPath}/build`,
`${outputPath}/lib`,
]
fileConfig.events.onEnd.move = [
{ source: `${outputPath}/index.umd.js`, destination: `${outputPath}/umd/index.umd.js` },
{ source: `${outputPath}/index.umd.d.ts`, destination: `${outputPath}/umd/index.umd.d.ts` },
{ source: `${outputPath}/index.umd.js.map`, destination: `${outputPath}/umd/index.umd.js.map` },
]
}
if (target === 'node') fileConfig.events.onEnd.move = getSrcFile()
} else {
if (target === 'node') fileConfig.events.onEnd.move = getCopyFile(parserName)
if (target === 'web') fileConfig.events.onEnd.move = [
{ source: `${outputPath}/${parserName}.umd.d.ts`, destination: `${outputPath}/umd/${parserName}.umd.d.ts` },
{ source: `${outputPath}/${parserName}.umd.js`, destination: `${outputPath}/umd/${parserName}.umd.js` },
{ source: `${outputPath}/${parserName}.umd.js.map`, destination: `${outputPath}/umd/${parserName}.umd.js.map` },
]
}
pluginList.push(new FileManagerPlugin(fileConfig))
}
return pluginList
}
const getOutput = (target) => ({
path: outputPath,
library: '',
Expand Down

0 comments on commit 9de356b

Please sign in to comment.