Skip to content

Commit

Permalink
update file
Browse files Browse the repository at this point in the history
  • Loading branch information
taozhi8833998 committed Jul 21, 2020
1 parent 589eb3b commit 527cea5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ console.log(ast);
const opt = {
database: 'MySQL' // MySQL is the default database
}
const { Parser } = require('node-sql-parser/mysql');
const { Parser } = require('node-sql-parser/build/mysql');
const parser = new Parser()
// opt is optional
const ast = parser.astify('SELECT * FROM t', opt);
Expand All @@ -145,7 +145,7 @@ console.log(sql); // SELECT * FROM `t`
const opt = {
database: 'MariaDB' // MySQL is the default database
}
const { Parser } = require('node-sql-parser/mariadb');
const { Parser } = require('node-sql-parser/build/mariadb');
const parser = new Parser()
// opt is optional
const { tableList, columnList, ast } = parser.parse('SELECT * FROM t', opt);
Expand All @@ -160,7 +160,7 @@ const { tableList, columnList, ast } = parser.parse('SELECT * FROM t', opt);
const opt = {
database: 'MySQL'
}
const { Parser } = require('node-sql-parser/mysql');
const { Parser } = require('node-sql-parser/build/mysql');
const parser = new Parser();
// opt is optional
const tableList = parser.tableList('SELECT * FROM t', opt);
Expand All @@ -178,7 +178,7 @@ console.log(tableList); // ["select::null::t"]
const opt = {
database: 'MySQL'
}
const { Parser } = require('node-sql-parser/mysql');
const { Parser } = require('node-sql-parser/build/mysql');
const parser = new Parser();
// opt is optional
const columnList = parser.columnList('SELECT t.id FROM t', opt);
Expand Down
17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"name": "node-sql-parser",
"version": "3.0.0",
"version": "3.0.1",
"description": "simple node sql parser",
"main": "index.js",
"types": "index.d.ts",
"scripts": {
"start": "webpack --config webpack.config.js",
"build": "webpack --config webpack.config.js --prod",
"test": "mochapack \"test/**/*.spec.js\"",
"prepublishOnly": "npm run lint && npm run build",
"build": "npm run lint && npm run compile && webpack --config webpack.config.js --prod",
"test": "npm run lint && mochapack \"test/**/*.spec.js\"",
"lint": "eslint src",
"compile": "babel src -d lib",
"coverLocal": "cross-env NODE_ENV=coverage nyc --reporter=lcov --reporter=text npm run test",
"cover:run": "cross-env NODE_ENV=coverage nyc --reporter=text-lcov npm run test",
"cover": "npm run cover:run && nyc report --reporter=text-lcov | coveralls",
"release": "npm publish output/prod"
"release": "npm run build && npm publish output/prod"
},
"repository": {
"type": "git",
Expand All @@ -34,12 +34,15 @@
"author": "taozhi8833998 <[email protected]>",
"files": [
"ast/",
"build",
"lib",
"index.js",
"lib/",
"index.d.ts",
"build/",
"index.js.map",
"umd/",
"README.md",
"package.json",
"types.d.ts",
"LICENSE"
],
"license": "GPLv2",
Expand Down
21 changes: 20 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const isProd = process.argv.includes('--prod')
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')
require('rimraf').sync(outputPath)

if (isProd) require('./typegen')
Expand Down Expand Up @@ -39,6 +40,18 @@ const moduleCfg = {
],
}

const getCopyFile = (database) => {
return [
{ source: `${outputPath}/${database}.js`, destination: `${outputPath}/build/${database}.js` },
{ source: `${outputPath}/${database}.js.map`, destination: `${outputPath}/build/${database}.js.map` },
{ source: `${outputPath}/${database}.d.ts`, destination: `${outputPath}/build/${database}.d.ts` },
]
}

const getDbFile = () => ['bigquery', 'db2', 'hive', 'mariadb', 'mysql', 'postgresql', 'transactsql'].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',
Expand All @@ -63,13 +76,19 @@ const getPlugins = (parserName, target, plugins) => [
new FileManagerPlugin({
onEnd: {
mkdir: [
`${outputPath}/umd`
`${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`,
Expand Down

0 comments on commit 527cea5

Please sign in to comment.