Skip to content
Permalink
Browse files

feat: 🎸 功能初始化

  • Loading branch information...
bocheng.zbc
bocheng.zbc committed Sep 2, 2019
0 parents commit d62f017852dd73073df0cbd67d5d5836f51fd2b0
Showing with 1,070 additions and 0 deletions.
  1. +14 −0 .gitignore
  2. +12 −0 .npmignore
  3. +11 −0 .travis.yml
  4. +21 −0 LICENSE
  5. +88 −0 README.md
  6. +13 −0 jest.config.js
  7. +32 −0 jsdoc.json
  8. +65 −0 package.json
  9. +107 −0 rollup.config.production.js
  10. +71 −0 scripts/build.js
  11. +1 −0 src/index.ts
  12. +178 −0 src/mock.ts
  13. +432 −0 test/mock.test.ts
  14. +25 −0 tsconfig.json
@@ -0,0 +1,14 @@
.DS_Store
node_modules
dist
npm-debug.log

coverage/
.happypack
.pagedata.json
.pagedata.json.lock
out/
.vscode

.build.cjs
.build.es
@@ -0,0 +1,12 @@
.DS_Store
node_modules
src
test
npm-debug.log

coverage/
.happypack
.pagedata.json
.pagedata.json.lock
out/
.vscode
@@ -0,0 +1,11 @@
language: node_js
node_js:
- '8'

script: echo "Running tests against $(node -v)..."

jobs:
include:
- stage: Produce Coverage
node_js: node
script: ./node_modules/.bin/jest --coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage
21 LICENSE
@@ -0,0 +1,21 @@
The MIT License

Copyright (c) 2019 boycgit

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
@@ -0,0 +1,88 @@
# mock-from-json-schema

[![Build Status](https://travis-ci.org/boycgit/mock-from-json-schema.svg?branch=master)](https://travis-ci.org/boycgit/mock-from-json-schema) [![Coverage Status](https://coveralls.io/repos/github/boycgit/mock-from-json-schema/badge.svg?branch=master)](https://coveralls.io/github/boycgit/mock-from-json-schema?branch=master) [![MIT Licence](https://badges.frapsoft.com/os/mit/mit.svg?v=103)](https://opensource.org/licenses/mit-license.php) [![npm version](https://badge.fury.io/js/mock-from-json-schema.svg)](https://badge.fury.io/js/mock-from-json-schema)

Simple utility to mock example objects based on JSON schema definitions. Copy from [mock-json-schema](https://github.com/anttiviljami/mock-json-schema), but not use lodash (less bundle size)


## Installation

### Node.js / Browserify

```bash
npm install mock-from-json-schema --save
```

```javascript
import mock from "mock-from-json-schema";
var schema = {
"title": "配置",
"description": "",
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "商品名称",
"title": "name"
},
"list": {
"type": "array",
"title": "list",
"description": "列表",
"items": {
"title": "",
"description": "",
"type": "object",
"properties": {
"itemName": {
"type": "string",
"description": "子项名称",
"title": "itemName"
}
},
"required": [
"itemName"
]
}
}
},
"required": [
"name"
]
};
console.log(555, mock(schema));
// 输出:
// {
// "name": "string",
// "list": [
// {
// "itemName": "string"
// }
// ]
// }
```


## Build & test

```bash
npm run build
```

```bash
npm test
```

```bash
npm run doc
```

then open the generated `out/index.html` file in your browser.

## License

[MIT](LICENSE).
@@ -0,0 +1,13 @@
module.exports = {
transform: {
'^.+\\.tsx?$': 'ts-jest'
},
// verbose: true,
collectCoverage: true,
coverageDirectory: '<rootDir>/coverage/',
collectCoverageFrom: ['<rootDir>/src/**'],
roots: ['<rootDir>/test/'],
testMatch: ['<rootDir>/test/**/*.(test|base).(js|ts)'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
transformIgnorePatterns: [], // 不能忽略
};
@@ -0,0 +1,32 @@
{
"tags": {
"allowUnknownTags": true,
"dictionaries": [
"jsdoc",
"closure"
]
},
"source": {
"include": [
"./src"
],
"includePattern": ".+\\.(ts|js)(doc)?$",
"excludePattern": "(^|\\/|\\\\)_"
},
"opts": {
"template": "templates/default",
"encoding": "utf8",
"destination": "./out/",
"recurse": true
},
"plugins": [
"plugins/markdown"
],
"markdown": {
"idInHeadings": true
},
"templates": {
"cleverLinks": false,
"monospaceLinks": false
}
}
@@ -0,0 +1,65 @@
{
"name": "mock-from-json-schema",
"version": "0.1.0",
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"jsnext:main": "dist/index.esm.js",
"browser": "dist/index.umd.js",
"typings": "dist/index.d.ts",
"author": "boycgit",
"repository": {
"type": "git",
"url": "git+https://github.com/boycgit/mock-from-json-schema.git"
},
"size-limit": [
{
"limit": "9 KB",
"path": "dist/index.cjs.js"
}
],
"scripts": {
"size": "./node_modules/.bin/size-limit",
"version": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0 && git add CHANGELOG.md",
"quick-build": "tsc --pretty",
"small-build": "node scripts/build.js && npm run rollup",
"build": "npm run quick-build && npm run small-build",
"rollup": "./node_modules/.bin/rollup --config rollup.config.production.js",
"watch": "tsc -w",
"test": "./node_modules/.bin/jest && npm run size",
"doc": "./node_modules/.bin/typedoc --out ./out --target ES5",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -w -r 0",
"release": "standard-version"
},
"dependencies": {
"openapi-types": "^1.3.2"
},
"devDependencies": {
"@types/chance": "^1.0.1",
"@types/jest": "^23.3.1",
"babel-core": "^6.26.3",
"babel-jest": "^23.4.0",
"babel-plugin-external-helpers": "^6.22.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-preset-env": "^1.7.0",
"chance": "^1.0.16",
"coveralls": "^3.0.2",
"envify": "^4.1.0",
"jest": "^24.8.0",
"jsdoc": "^3.5.5",
"rollup": "^0.60.0",
"rollup-plugin-babel": "^3.0.7",
"rollup-plugin-commonjs": "^9.1.0",
"rollup-plugin-filesize": "^4.0.1",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-plugin-terser": "^1.0.1",
"rollup-plugin-uglify": "^4.0.0",
"size-limit": "^0.18.5",
"ts-jest": "^24.0.2",
"typedoc": "^0.11.1",
"typescript": "^3.5.3",
"uglify-js": "^3.4.6"
},
"files": [
"dist"
]
}
@@ -0,0 +1,107 @@
var resolve = require('rollup-plugin-node-resolve');
var uglify = require('rollup-plugin-uglify').uglify;
var terser = require('rollup-plugin-terser').terser;
var path = require('path');
var pkg = require('./package.json');
var deps = Object.keys(pkg.dependencies || {});

const targetName = 'index';
const umdName = 'GlobalEvent';

// 根据配置生成所需要的插件列表
const getPlugin = function({ shouldMinified, isES6 }) {
let plugins = [resolve()];
if (shouldMinified) {
plugins.push(isES6 ? terser() : uglify());
}
return plugins;
};

// 根据这些配置项生成具体的 rollup 配置项
const compileConfig = function({
fromDir,
outputFileName,
shouldMinified,
format,
external
}) {
let outputFileArr = [outputFileName, 'js'];
//
if (shouldMinified) {
outputFileArr.splice(1, 0, 'min');
}
return Object.assign(external ? { external: external } : {}, {
input: path.resolve(fromDir, `${targetName}.js`),
output: Object.assign(
{
exports: 'named' // 这个很关键,统一 cmd 的引用方式
},
format === 'umd'
? {
name: umdName
}
: {},
{
file: path.join(__dirname, 'dist', outputFileArr.join('.')),
format
}
),
plugins: getPlugin({ shouldMinified, isES6: format === 'es' })
});
};

module.exports = [
// browser-friendly UMD build
compileConfig({
fromDir: '.build.cjs',
outputFileName: path.parse(pkg.browser).name,
shouldMinified: false,
format: 'umd'
}),
// browser-friendly UMD build, minified
compileConfig({
fromDir: '.build.cjs',
outputFileName: path.parse(pkg.browser).name,
shouldMinified: true,
format: 'umd'
}),

// CommonJS (for Node) and ES module (for bundlers) build.
// (We could have three entries in the configuration array
// instead of two, but it's quicker to generate multiple
// builds from a single configuration where possible, using
// an array for the `output` option, where we can specify
// `file` and `format` for each target)
compileConfig({
fromDir: '.build.cjs',
external: deps,
outputFileName: path.parse(pkg.main).name,
shouldMinified: false,
format: 'cjs'
}),
// minified
compileConfig({
fromDir: '.build.cjs',
external: deps,
outputFileName: path.parse(pkg.main).name,
shouldMinified: true,
format: 'cjs'
}),

// es
compileConfig({
fromDir: '.build.es',
external: deps,
outputFileName: path.parse(pkg.module).name,
shouldMinified: false,
format: 'es'
}),
// es, minified
compileConfig({
fromDir: '.build.es',
external: deps,
outputFileName: path.parse(pkg.module).name,
shouldMinified: true,
format: 'es'
})
];

0 comments on commit d62f017

Please sign in to comment.
You can’t perform that action at this time.