cascade-extend 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # cascadeExtend
@@ -0,0 +1,13 @@
1
+ module.exports = {
2
+ presets: [
3
+ [
4
+ '@babel/preset-env',
5
+ {
6
+ modules: false,
7
+ useBuiltIns: false,
8
+ },
9
+ ],
10
+ ],
11
+ plugins: ['@babel/plugin-syntax-dynamic-import'],
12
+ comments: false,
13
+ };
@@ -0,0 +1,4 @@
1
+ module.exports = {
2
+ productionSourceMap: true,
3
+ uglify: false,
4
+ };
@@ -0,0 +1,41 @@
1
+ process.env.NODE_ENV = 'production';
2
+
3
+ const ora = require('ora');
4
+ const rm = require('rimraf');
5
+ const path = require('path');
6
+ const chalk = require('chalk');
7
+ const webpack = require('webpack');
8
+ const config = require('./config.js');
9
+ const webpackConfig = require('./webpack.prod.conf');
10
+
11
+ const spinner = ora('building for production...');
12
+ spinner.start();
13
+
14
+ rm(path.join(config.build.assetsRoot, 'index.*'), err => {
15
+ if (err) throw err;
16
+
17
+ rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
18
+ if (err) throw err;
19
+ webpack(webpackConfig, function (err, stats) {
20
+ spinner.stop();
21
+ if (err) throw err;
22
+ process.stdout.write(
23
+ stats.toString({
24
+ colors: true,
25
+ modules: false,
26
+ children: false,
27
+ chunks: false,
28
+ chunkModules: false,
29
+ }) + '\n\n'
30
+ );
31
+
32
+ console.log(chalk.cyan(' Build complete.\n'));
33
+ console.log(
34
+ chalk.yellow(
35
+ ' Tip: built files are meant to be served over an HTTP server.\n' +
36
+ " Opening index.html over file:// won't work.\n"
37
+ )
38
+ );
39
+ });
40
+ });
41
+ });
@@ -0,0 +1,19 @@
1
+ const path = require('path');
2
+ const { merge } = require('webpack-merge');
3
+ const config = require('../config.js');
4
+
5
+ module.exports = merge(
6
+ {
7
+ build: {
8
+ env: {
9
+ NODE_ENV: '"production"',
10
+ },
11
+ assetsRoot: path.resolve(__dirname, '../../dist'),
12
+ assetsSubDirectory: 'static',
13
+ assetsPublicPath: '',
14
+ productionSourceMap: true,
15
+ uglify: false,
16
+ },
17
+ },
18
+ { build: config }
19
+ );
@@ -0,0 +1,64 @@
1
+ const path = require('path');
2
+ const config = require('./config.js');
3
+ const MiniCssExtractPlugin = require('mini-css-extract-plugin');
4
+
5
+ exports.assetsPath = function (_path) {
6
+ return path.join(config.build.assetsSubDirectory, _path);
7
+ };
8
+
9
+ exports.cssLoaders = function (options) {
10
+ options = options || {};
11
+
12
+ const cssLoader = {
13
+ loader: 'css-loader',
14
+ options: {
15
+ minimize: process.env.NODE_ENV === 'production',
16
+ sourceMap: options.sourceMap,
17
+ },
18
+ };
19
+
20
+ // generate loader string to be used with extract text plugin
21
+ function generateLoaders(loader, loaderOptions) {
22
+ const loaders = [cssLoader];
23
+ if (loader) {
24
+ loaders.push({
25
+ loader: loader + '-loader',
26
+ options: Object.assign({}, loaderOptions, {
27
+ sourceMap: options.sourceMap,
28
+ }),
29
+ });
30
+ }
31
+
32
+ // Extract CSS when that option is specified
33
+ // (which is the case during production build)
34
+ if (options.extract) {
35
+ return [MiniCssExtractPlugin.loader].concat(loaders);
36
+ }
37
+ return ['vue-style-loader'].concat(loaders);
38
+ }
39
+
40
+ // http://vuejs.github.io/vue-loader/en/configurations/extract-css.html
41
+ return {
42
+ css: generateLoaders(),
43
+ postcss: generateLoaders(),
44
+ less: generateLoaders('less'),
45
+ sass: generateLoaders('sass', { indentedSyntax: true }),
46
+ scss: generateLoaders('sass'),
47
+ stylus: generateLoaders('stylus'),
48
+ styl: generateLoaders('stylus'),
49
+ };
50
+ };
51
+
52
+ // Generate loaders for standalone style files (outside of .vue)
53
+ exports.styleLoaders = function (options) {
54
+ const output = [];
55
+ const loaders = exports.cssLoaders(options);
56
+ for (const extension in loaders) {
57
+ const loader = loaders[extension];
58
+ output.push({
59
+ test: new RegExp('\\.' + extension + '$'),
60
+ use: loader,
61
+ });
62
+ }
63
+ return output;
64
+ };
@@ -0,0 +1,69 @@
1
+ const path = require('path');
2
+ const utils = require('./utils');
3
+ const config = require('./config.js');
4
+
5
+ function resolve(dir) {
6
+ return path.join(__dirname, '../..', dir);
7
+ }
8
+
9
+ module.exports = {
10
+ entry: {
11
+ index: resolve('src/main.js'),
12
+ },
13
+ output: {
14
+ path: config.build.assetsRoot,
15
+ filename: '[name].js',
16
+ publicPath: config.build.assetsPublicPath,
17
+ libraryTarget: 'commonjs2',
18
+ },
19
+ externals: {
20
+ vue: 'vue',
21
+ },
22
+ resolve: {
23
+ extensions: ['.js', '.vue', '.json'],
24
+ alias: {
25
+ '@': resolve('src'),
26
+ },
27
+ },
28
+ module: {
29
+ rules: [
30
+ {
31
+ test: /\.vue$/,
32
+ loader: 'vue-loader',
33
+ },
34
+ {
35
+ test: /\.esm\.js$/,
36
+ loader: 'babel-loader',
37
+ },
38
+ {
39
+ test: /\.esm\.bundle\.js$/,
40
+ loader: 'babel-loader',
41
+ },
42
+ {
43
+ test: /\.module\.js$/,
44
+ loader: 'babel-loader',
45
+ },
46
+ {
47
+ test: /\.js$/,
48
+ loader: 'babel-loader',
49
+ include: [resolve('src')],
50
+ },
51
+ {
52
+ test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
53
+ loader: 'url-loader',
54
+ options: {
55
+ limit: 10000,
56
+ name: utils.assetsPath('img/[name].[hash].[ext]'),
57
+ },
58
+ },
59
+ {
60
+ test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
61
+ loader: 'url-loader',
62
+ options: {
63
+ limit: 10000,
64
+ name: utils.assetsPath('fonts/[name].[hash].[ext]'),
65
+ },
66
+ },
67
+ ],
68
+ },
69
+ };
@@ -0,0 +1,36 @@
1
+ const utils = require('./utils');
2
+ const webpack = require('webpack');
3
+ const config = require('./config.js');
4
+ const { merge } = require('webpack-merge');
5
+ const baseWebpackConfig = require('./webpack.base.conf');
6
+ const { VueLoaderPlugin } = require('vue-loader');
7
+ const MiniCssExtractPlugin = require('mini-css-extract-plugin');
8
+
9
+ const env = config.build.env;
10
+
11
+ const plugins = [
12
+ new webpack.DefinePlugin({
13
+ 'process.env': env,
14
+ }),
15
+ new VueLoaderPlugin(),
16
+ new MiniCssExtractPlugin({
17
+ filename: utils.assetsPath('[name].css'),
18
+ }),
19
+ ];
20
+
21
+ const webpackConfig = merge(baseWebpackConfig, {
22
+ mode: 'production',
23
+ module: {
24
+ rules: utils.styleLoaders({
25
+ sourceMap: config.build.productionSourceMap,
26
+ extract: true,
27
+ }),
28
+ },
29
+ devtool: config.build.productionSourceMap ? 'source-map' : false,
30
+ plugins,
31
+ optimization: {
32
+ minimize: config.build.uglify,
33
+ },
34
+ });
35
+
36
+ module.exports = webpackConfig;
package/dist/index.js ADDED
@@ -0,0 +1,83 @@
1
+ /******/ (() => { // webpackBootstrap
2
+ /******/ "use strict";
3
+ /******/ // The require scope
4
+ /******/ var __webpack_require__ = {};
5
+ /******/
6
+ /************************************************************************/
7
+ /******/ /* webpack/runtime/define property getters */
8
+ /******/ (() => {
9
+ /******/ // define getter functions for harmony exports
10
+ /******/ __webpack_require__.d = (exports, definition) => {
11
+ /******/ for(var key in definition) {
12
+ /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
13
+ /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
14
+ /******/ }
15
+ /******/ }
16
+ /******/ };
17
+ /******/ })();
18
+ /******/
19
+ /******/ /* webpack/runtime/hasOwnProperty shorthand */
20
+ /******/ (() => {
21
+ /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
22
+ /******/ })();
23
+ /******/
24
+ /******/ /* webpack/runtime/make namespace object */
25
+ /******/ (() => {
26
+ /******/ // define __esModule on exports
27
+ /******/ __webpack_require__.r = (exports) => {
28
+ /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
29
+ /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
30
+ /******/ }
31
+ /******/ Object.defineProperty(exports, '__esModule', { value: true });
32
+ /******/ };
33
+ /******/ })();
34
+ /******/
35
+ /************************************************************************/
36
+ var __webpack_exports__ = {};
37
+ __webpack_require__.r(__webpack_exports__);
38
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
39
+ /* harmony export */ "default": () => (/* binding */ cascadeExtend)
40
+ /* harmony export */ });
41
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
42
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
43
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
44
+ function cascadeExtend(_ref) {
45
+ var scope = _ref.scope,
46
+ source = _ref.source,
47
+ name = _ref.name;
48
+ if (!source || !name) return null;
49
+ var keys = Object.keys(source).filter(function (key) {
50
+ return key === name || key.indexOf(name + '_') === 0;
51
+ });
52
+ if (keys.length === 0) return null;
53
+ if (keys.length === 1 && keys[0] === name) return source[keys[0]];
54
+ var result = {};
55
+ var nameLength = name.length;
56
+ var _iterator = _createForOfIteratorHelper(keys),
57
+ _step;
58
+ try {
59
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
60
+ var key = _step.value;
61
+ if (key === name) {
62
+ extend(true, result, source[key]);
63
+ } else {
64
+ var parts = key.substring(nameLength + 1).split('_');
65
+ var test = parts.every(function (part) {
66
+ return !!scope[part];
67
+ });
68
+ if (test) {
69
+ extend(true, result, source[key]);
70
+ }
71
+ }
72
+ }
73
+ } catch (err) {
74
+ _iterator.e(err);
75
+ } finally {
76
+ _iterator.f();
77
+ }
78
+ return result;
79
+ }
80
+ module.exports = __webpack_exports__;
81
+ /******/ })()
82
+ ;
83
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","mappings":";;UAAA;UACA;;;;;WCDA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA;;;;;WCPA;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D;;;;;;;;;;;;ACNe,SAASA,aAAaA,CAAAC,IAAA,EAA0B;EAAA,IAAvBC,KAAK,GAAAD,IAAA,CAALC,KAAK;IAAEC,MAAM,GAAAF,IAAA,CAANE,MAAM;IAAEC,IAAI,GAAAH,IAAA,CAAJG,IAAI;EACzD,IAAI,CAACD,MAAM,IAAI,CAACC,IAAI,EAAE,OAAO,IAAI;EACjC,IAAMC,IAAI,GAAGC,MAAM,CAACD,IAAI,CAACF,MAAM,CAAC,CAACI,MAAM,CAAC,UAAAC,GAAG,EAAI;IAC7C,OAAOA,GAAG,KAAKJ,IAAI,IAAII,GAAG,CAACC,OAAO,CAACL,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC;EACtD,CAAC,CAAC;EACF,IAAIC,IAAI,CAACK,MAAM,KAAK,CAAC,EAAE,OAAO,IAAI;EAClC,IAAIL,IAAI,CAACK,MAAM,KAAK,CAAC,IAAIL,IAAI,CAAC,CAAC,CAAC,KAAKD,IAAI,EAAE,OAAOD,MAAM,CAACE,IAAI,CAAC,CAAC,CAAC,CAAC;EACjE,IAAMM,MAAM,GAAG,CAAC,CAAC;EACjB,IAAMC,UAAU,GAAGR,IAAI,CAACM,MAAM;EAAC,IAAAG,SAAA,GAAAC,0BAAA,CACbT,IAAI;IAAAU,KAAA;EAAA;IAAtB,KAAAF,SAAA,CAAAG,CAAA,MAAAD,KAAA,GAAAF,SAAA,CAAAI,CAAA,IAAAC,IAAA,GAAwB;MAAA,IAAbV,GAAG,GAAAO,KAAA,CAAAI,KAAA;MACZ,IAAIX,GAAG,KAAKJ,IAAI,EAAE;QAChBgB,MAAM,CAAC,IAAI,EAAET,MAAM,EAAER,MAAM,CAACK,GAAG,CAAC,CAAC;MACnC,CAAC,MAAM;QACL,IAAMa,KAAK,GAAGb,GAAG,CAACc,SAAS,CAACV,UAAU,GAAG,CAAC,CAAC,CAACW,KAAK,CAAC,GAAG,CAAC;QACtD,IAAMC,IAAI,GAAGH,KAAK,CAACI,KAAK,CAAC,UAAAC,IAAI;UAAA,OAAI,CAAC,CAACxB,KAAK,CAACwB,IAAI,CAAC;QAAA,EAAC;QAC/C,IAAIF,IAAI,EAAE;UACRJ,MAAM,CAAC,IAAI,EAAET,MAAM,EAAER,MAAM,CAACK,GAAG,CAAC,CAAC;QACnC;MACF;IACF;EAAC,SAAAmB,GAAA;IAAAd,SAAA,CAAAe,CAAA,CAAAD,GAAA;EAAA;IAAAd,SAAA,CAAAgB,CAAA;EAAA;EACD,OAAOlB,MAAM;AACf,C","sources":["webpack://cascade-extend/webpack/bootstrap","webpack://cascade-extend/webpack/runtime/define property getters","webpack://cascade-extend/webpack/runtime/hasOwnProperty shorthand","webpack://cascade-extend/webpack/runtime/make namespace object","webpack://cascade-extend/./src/main.js"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","export default function cascadeExtend({ scope, source, name }) {\n if (!source || !name) return null;\n const keys = Object.keys(source).filter(key => {\n return key === name || key.indexOf(name + '_') === 0\n });\n if (keys.length === 0) return null;\n if (keys.length === 1 && keys[0] === name) return source[keys[0]];\n const result = {};\n const nameLength = name.length;\n for (const key of keys) {\n if (key === name) {\n extend(true, result, source[key]);\n } else {\n const parts = key.substring(nameLength + 1).split('_');\n const test = parts.every(part => !!scope[part]);\n if (test) {\n extend(true, result, source[key]);\n }\n }\n }\n return result;\n}"],"names":["cascadeExtend","_ref","scope","source","name","keys","Object","filter","key","indexOf","length","result","nameLength","_iterator","_createForOfIteratorHelper","_step","s","n","done","value","extend","parts","substring","split","test","every","part","err","e","f"],"sourceRoot":""}
package/package.json ADDED
@@ -0,0 +1,91 @@
1
+ {
2
+ "name": "cascade-extend",
3
+ "version": "1.0.0",
4
+ "description": "cascade-extend",
5
+ "main": "dist/index.js",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "scripts": {
10
+ "build": "node build/front/build.js",
11
+ "preversion": "npm run build && git add ."
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/zhennann/cascade-extend.git"
16
+ },
17
+ "keywords": [
18
+ "egg",
19
+ "egg-born",
20
+ "cabloy",
21
+ "cascade-extend"
22
+ ],
23
+ "author": "zhennann",
24
+ "license": "MIT",
25
+ "bugs": {
26
+ "url": "https://github.com/zhennann/cascade-extend/issues"
27
+ },
28
+ "homepage": "https://github.com/zhennann/cascade-extend#readme",
29
+ "devDependencies": {
30
+ "@babel/core": "^7.12.10",
31
+ "@babel/eslint-parser": "^7.13.10",
32
+ "@babel/plugin-syntax-dynamic-import": "^7.8.3",
33
+ "@babel/plugin-transform-runtime": "^7.8.3",
34
+ "@babel/preset-env": "^7.8.4",
35
+ "@babel/register": "^7.8.3",
36
+ "@vue/babel-helper-vue-jsx-merge-props": "^1.0.0",
37
+ "@vue/babel-preset-jsx": "^1.1.2",
38
+ "@zhennann/babel-generator": "^7.17.3",
39
+ "@zhennann/babel-helper-wrap-function": "^7.16.8",
40
+ "@zhennann/babel-plugin-transform-async-to-generator": "^7.16.8",
41
+ "@zhennann/extend":"^3.0.2",
42
+ "autoprefixer": "^9.7.4",
43
+ "babel-eslint": "^10.1.0",
44
+ "babel-loader": "^8.2.2",
45
+ "babel-plugin-jsx-v-model": "^2.0.3",
46
+ "babel-plugin-syntax-jsx": "^6.18.0",
47
+ "bluebird": "^3.7.2",
48
+ "chalk": "^3.0.0",
49
+ "connect-history-api-fallback": "^1.6.0",
50
+ "copy-webpack-plugin": "^7.0.0",
51
+ "css-loader": "^5.0.1",
52
+ "egg-born-mglob": "^3.0.1",
53
+ "egg-born-mparse": "^2.1.5",
54
+ "eslint": "^7.21.0",
55
+ "eslint-config-egg-born": "^1.1.2",
56
+ "eslint-config-prettier": "^8.3.0",
57
+ "eslint-plugin-jsdoc": "^37.9.1",
58
+ "eslint-plugin-node": "^11.1.0",
59
+ "eslint-plugin-prettier": "^3.4.0",
60
+ "eslint-plugin-vue": "^7.17.0",
61
+ "eventsource-polyfill": "^0.9.6",
62
+ "express": "^4.15.4",
63
+ "extend2": "^1.0.1",
64
+ "file-loader": "^6.2.0",
65
+ "fs-extra": "^10.1.0",
66
+ "function-bind": "^1.1.1",
67
+ "globby": "^11.0.0",
68
+ "html-webpack-plugin": "^5.3.1",
69
+ "http-proxy-middleware": "^1.0.6",
70
+ "is-type-of": "^1.2.0",
71
+ "less": "^3.13.0",
72
+ "less-loader": "^7.1.0",
73
+ "mini-css-extract-plugin": "^1.3.3",
74
+ "module-alias": "^2.2.2",
75
+ "open": "^7.0.2",
76
+ "ora": "^4.0.3",
77
+ "prettier": "2.3.2",
78
+ "rimraf": "^3.0.2",
79
+ "semver": "^7.3.7",
80
+ "url-loader": "^4.1.1",
81
+ "vue-eslint-parser": "^7.10.0",
82
+ "vue-loader": "^15.9.5",
83
+ "vue-style-loader": "^4.1.2",
84
+ "vue-template-compiler": "^2.6.14",
85
+ "webpack": "^5.61.0",
86
+ "webpack-bundle-analyzer": "^4.2.0",
87
+ "webpack-dev-middleware": "^4.0.2",
88
+ "webpack-hot-middleware": "^2.25.0",
89
+ "webpack-merge": "^5.7.0"
90
+ }
91
+ }
package/src/main.js ADDED
@@ -0,0 +1,22 @@
1
+ export default function cascadeExtend({ scope, source, name }) {
2
+ if (!source || !name) return null;
3
+ const keys = Object.keys(source).filter(key => {
4
+ return key === name || key.indexOf(name + '_') === 0
5
+ });
6
+ if (keys.length === 0) return null;
7
+ if (keys.length === 1 && keys[0] === name) return source[keys[0]];
8
+ const result = {};
9
+ const nameLength = name.length;
10
+ for (const key of keys) {
11
+ if (key === name) {
12
+ extend(true, result, source[key]);
13
+ } else {
14
+ const parts = key.substring(nameLength + 1).split('_');
15
+ const test = parts.every(part => !!scope[part]);
16
+ if (test) {
17
+ extend(true, result, source[key]);
18
+ }
19
+ }
20
+ }
21
+ return result;
22
+ }