merge-umi-mock-data
Advanced tools
Comparing version 1.0.5 to 2.0.6
@@ -5,2 +5,12 @@ # Change Log | ||
<a name="2.0.6"></a> | ||
## [2.0.6](https://github.com/chenshuai2144/merge-umi-mock-data/compare/v1.0.4...v2.0.6) (2019-05-24) | ||
### Bug Fixes | ||
* **core:** add backward slashes for win separators ([ce6ce67](https://github.com/chenshuai2144/merge-umi-mock-data/commit/ce6ce67)) | ||
<a name="1.0.4"></a> | ||
@@ -7,0 +17,0 @@ ## [1.0.4](https://github.com/chenshuai2144/merge-umi-mock-data/compare/v1.0.3...v1.0.4) (2019-01-08) |
66
index.js
@@ -5,9 +5,26 @@ const rollup = require("rollup"); | ||
const babel = require("rollup-plugin-babel"); | ||
const builtins = require("rollup-plugin-node-builtins"); | ||
const glob = require("glob"); | ||
const path = require("path"); | ||
const fs = require("fs"); | ||
const slash = require("slash2"); | ||
const allMock = path.join(__dirname, "./allMock.js"); | ||
const extensions = [".js", ".jsx", ".ts", ".tsx"]; | ||
const firstUpperCase = pathString => { | ||
return pathString | ||
.replace(".", "") | ||
.split(/\/|\-/) | ||
.map(s => s.toLowerCase().replace(/( |^)[a-z]/g, L => L.toUpperCase())) | ||
.filter(s => s) | ||
.join(""); | ||
}; | ||
const getArrayLastTwo = fileNameArray => { | ||
const nameArray = []; | ||
nameArray.push(fileNameArray.pop()); | ||
nameArray.push(fileNameArray.pop()); | ||
return firstUpperCase(nameArray.join("/")); | ||
}; | ||
const allMock = path.join(__dirname, "./allMock.ts"); | ||
const inputOptions = { | ||
@@ -17,3 +34,2 @@ input: allMock, | ||
plugins: [ | ||
builtins(), | ||
json({ | ||
@@ -24,15 +40,5 @@ preferConst: true, // Default: false | ||
babel({ | ||
extensions, | ||
babelrc: false, | ||
runtimeHelpers: true, | ||
presets: [ | ||
[ | ||
"@babel/env", | ||
{ | ||
targets: { | ||
node: "6.11.5" | ||
}, | ||
modules: false | ||
} | ||
] | ||
] | ||
presets: ["@babel/env", "@babel/preset-typescript"] | ||
}) | ||
@@ -50,5 +56,12 @@ ] | ||
mockFiles.forEach(filePath => { | ||
const fileName = filePath.replace(".js", ""); | ||
const fileName = getArrayLastTwo( | ||
filePath | ||
.replace(".ts", "") | ||
.replace("_", "") | ||
.split("/") | ||
); | ||
importString.push( | ||
`import ${fileName} from "${path.join(mockPath, filePath).replace(/\\/g,'\\\\')}";` | ||
`import ${fileName} from "${slash( | ||
path.join(mockPath, filePath.replace(".ts", "")) | ||
)}";` | ||
); | ||
@@ -58,14 +71,20 @@ dataString.push(`...${fileName}`); | ||
return ` | ||
${importString.join("\n")} | ||
${importString.join("\n")} | ||
const data = {${dataString.join(",")}}; | ||
const data = {${dataString.join(",")}}; | ||
export default data; | ||
`; | ||
export default data; | ||
`; | ||
}; | ||
async function build(mockPath, outputfile) { | ||
const mockFiles = glob.sync("**/*.js", { | ||
let mockFiles = glob.sync("**/*.ts", { | ||
cwd: mockPath | ||
}); | ||
mockFiles = mockFiles.concat( | ||
glob.sync("../src/**/**/_mock.ts", { | ||
cwd: mockPath, | ||
ignore: "* node_modules" | ||
}) | ||
); | ||
console.log("get files: " + chalk.green(mockFiles.join(", "))); | ||
@@ -82,5 +101,4 @@ const allMockText = importMockFiles(mockFiles, mockPath); | ||
console.log(chalk.yellow("-".repeat(80))); | ||
console.log(chalk.blue("finsh merge file")); | ||
console.log(chalk.blue("finish merge file")); | ||
} | ||
module.exports = build; |
{ | ||
"name": "merge-umi-mock-data", | ||
"version": "1.0.5", | ||
"version": "2.0.6", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"release": "standard-version", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"homepage": "https://github.com/chenshuai2144/merge-umi-mock-data#readme", | ||
"bugs": { | ||
"url": "https://github.com/chenshuai2144/merge-umi-mock-data/issues" | ||
}, | ||
@@ -14,20 +13,17 @@ "repository": { | ||
}, | ||
"license": "ISC", | ||
"author": "chenshuai", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/chenshuai2144/merge-umi-mock-data/issues" | ||
"main": "index.js", | ||
"scripts": { | ||
"release": "standard-version", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"homepage": "https://github.com/chenshuai2144/merge-umi-mock-data#readme", | ||
"dependencies": { | ||
"@babel/core": "^7.0.0-rc.2", | ||
"@babel/plugin-transform-modules-commonjs": "^7.0.0-rc.2", | ||
"@babel/core": "^7.4.0", | ||
"@babel/preset-env": "^7.2.3", | ||
"@babel/register": "^7.0.0-rc.2", | ||
"@babel/runtime": "^7.0.0-rc.2", | ||
"babel-plugin-add-module-exports": "^1.0.0", | ||
"babel-plugin-dynamic-import-node-sync": "^2.0.1", | ||
"@babel/preset-typescript": "^7.3.3", | ||
"chalk": "^2.4.2", | ||
"mockjs": "^1.0.1-beta3", | ||
"moment": "^2.22.2", | ||
"rollup": "^1.0.2", | ||
"rollup": "^1.12.2", | ||
"rollup-plugin-babel": "^4.2.0", | ||
@@ -40,4 +36,6 @@ "rollup-plugin-commonjs": "^9.2.0", | ||
"rollup-plugin-replace": "^2.0.0", | ||
"slash2": "^2.0.0", | ||
"standard-version": "^4.4.0" | ||
} | ||
}, | ||
"devDependencies": {} | ||
} |
4542
16
91
+ Addedslash2@^2.0.0
+ Added@babel/plugin-syntax-jsx@7.24.1(transitive)
+ Added@babel/plugin-syntax-typescript@7.24.1(transitive)
+ Added@babel/plugin-transform-typescript@7.24.4(transitive)
+ Added@babel/preset-typescript@7.24.1(transitive)
+ Addedelectron-to-chromium@1.4.748(transitive)
+ Addedslash2@2.0.0(transitive)
- Removed@babel/plugin-transform-modules-commonjs@^7.0.0-rc.2
- Removed@babel/register@^7.0.0-rc.2
- Removed@babel/runtime@^7.0.0-rc.2
- Removed@babel/register@7.23.7(transitive)
- Removedbabel-plugin-add-module-exports@1.0.4(transitive)
- Removedbabel-plugin-dynamic-import-node-sync@2.0.1(transitive)
- Removedclone-deep@4.0.1(transitive)
- Removedcommondir@1.0.1(transitive)
- Removedelectron-to-chromium@1.4.749(transitive)
- Removedfind-cache-dir@2.1.0(transitive)
- Removedfind-up@3.0.0(transitive)
- Removedis-plain-object@2.0.4(transitive)
- Removedisobject@3.0.1(transitive)
- Removedkind-of@6.0.3(transitive)
- Removedlocate-path@3.0.0(transitive)
- Removedmake-dir@2.1.0(transitive)
- Removedp-limit@2.3.0(transitive)
- Removedp-locate@3.0.0(transitive)
- Removedp-try@2.2.0(transitive)
- Removedpify@4.0.1(transitive)
- Removedpirates@4.0.6(transitive)
- Removedpkg-dir@3.0.0(transitive)
- Removedshallow-clone@3.0.1(transitive)
- Removedsource-map-support@0.5.21(transitive)
Updated@babel/core@^7.4.0
Updatedrollup@^1.12.2