Commit 574fc720 authored by rockyl's avatar rockyl

增加zeroing-template-fill

parents
Pipeline #214261 failed with stages
in 0 seconds
# Created by .ignore support plugin (hsz.mobi)
### Node template
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
# next.js build output
.next
# nuxt.js build output
.nuxt
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
import camelcase from 'camelcase';
/**
* Created by rockyl on 2019-11-13.
*
* 模板填充
*/
const dynamicValueReg = /\$[\w|(\.)]+\$/g;
function analyseTemplate(tpl) {
let result = [];
let matchResult = tpl.match(dynamicValueReg);
for (let matchItem of matchResult) {
let hint = matchItem.substr(1, matchItem.length - 2);
let arr = hint.split('.');
let field = camelcase(arr[0]);
let item = {
source: matchItem,
field,
};
if (arr[1] !== undefined) {
item.subField = arr[1];
}
result.push(item);
}
return result;
}
function fillTemplate(tpl, params, analyseResult) {
analyseResult = analyseResult || analyseTemplate(tpl);
for (let item of analyseResult) {
let fieldData = params[item.field];
if (fieldData && item.subField) {
fieldData = fieldData[item.subField];
}
if (fieldData) {
tpl = tpl.replace(item.source, fieldData);
}
}
return tpl;
}
async function generateLibraryScriptEl(tpl, dependencies, getPackages, libraryPath) {
let analyseResult = analyseTemplate(tpl);
let librariesHint = analyseResult.filter(item => item.field === 'libraries').map(item => item.subField);
let schema = {};
for (let libName of librariesHint) {
if (dependencies[libName]) {
schema[libName] = dependencies[libName];
}
}
let libraryScriptElMap = {};
(await getPackages(schema, 0)).forEach(item => {
let itemObj = typeof item.data === 'string' ? JSON.parse(item.data) : item.data;
libraryScriptElMap[itemObj.id] = generateJsScriptEl(itemObj.url, libraryPath);
});
return {
libraryScriptElMap,
analyseResult,
}
}
function generateJsScriptEl(file, path) {
let url = (path || '') + file;
return `<script crossorigin="anonymous" src="${url}"></script>`;
}
export { analyseTemplate, fillTemplate, generateJsScriptEl, generateLibraryScriptEl };
//# sourceMappingURL=index.es.js.map
{"version":3,"file":"index.es.js","sources":["../src/index.js"],"sourcesContent":["/**\n * Created by rockyl on 2019-11-13.\n *\n * 模板填充\n */\n\nimport camelcase from 'camelcase'\n\nconst TAG = 'zeroing-template-fill';\n\nconst dynamicValueReg = /\\$[\\w|(\\.)]+\\$/g;\n\nexport function analyseTemplate(tpl) {\n\tlet result = [];\n\tlet matchResult = tpl.match(dynamicValueReg);\n\tfor (let matchItem of matchResult) {\n\t\tlet hint = matchItem.substr(1, matchItem.length - 2);\n\t\tlet arr = hint.split('.');\n\t\tlet field = camelcase(arr[0]);\n\n\t\tlet item = {\n\t\t\tsource: matchItem,\n\t\t\tfield,\n\t\t};\n\t\tif (arr[1] !== undefined) {\n\t\t\titem.subField = arr[1];\n\t\t}\n\t\tresult.push(item)\n\t}\n\treturn result;\n}\n\nexport function fillTemplate(tpl, params, analyseResult) {\n\tanalyseResult = analyseResult || analyseTemplate(tpl);\n\tfor (let item of analyseResult) {\n\t\tlet fieldData = params[item.field];\n\t\tif (fieldData && item.subField) {\n\t\t\tfieldData = fieldData[item.subField];\n\t\t}\n\t\tif (fieldData) {\n\t\t\ttpl = tpl.replace(item.source, fieldData);\n\t\t}\n\t}\n\n\treturn tpl;\n}\n\nexport async function generateLibraryScriptEl(tpl, dependencies, getPackages, libraryPath) {\n\tlet analyseResult = analyseTemplate(tpl);\n\tlet librariesHint = analyseResult.filter(item => item.field === 'libraries').map(item => item.subField);\n\tlet schema = {};\n\tfor (let libName of librariesHint) {\n\t\tif (dependencies[libName]) {\n\t\t\tschema[libName] = dependencies[libName];\n\t\t}\n\t}\n\n\tlet libraryScriptElMap = {};\n\t(await getPackages(schema, 0)).forEach(item => {\n\t\tlet itemObj = typeof item.data === 'string' ? JSON.parse(item.data) : item.data;\n\t\tlibraryScriptElMap[itemObj.id] = generateJsScriptEl(itemObj.url, libraryPath);\n\t});\n\n\treturn {\n\t\tlibraryScriptElMap,\n\t\tanalyseResult,\n\t}\n}\n\nexport function generateJsScriptEl(file, path) {\n\tlet url = (path || '') + file;\n\treturn `<script crossorigin=\"anonymous\" src=\"${url}\"></script>`;\n}\n"],"names":[],"mappings":";;AAAA;;;;;AAKA,AAIA;AACA,MAAM,eAAe,GAAG,iBAAiB,CAAC;;AAE1C,AAAO,SAAS,eAAe,CAAC,GAAG,EAAE;CACpC,IAAI,MAAM,GAAG,EAAE,CAAC;CAChB,IAAI,WAAW,GAAG,GAAG,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;CAC7C,KAAK,IAAI,SAAS,IAAI,WAAW,EAAE;EAClC,IAAI,IAAI,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;EACrD,IAAI,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;EAC1B,IAAI,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;;EAE9B,IAAI,IAAI,GAAG;GACV,MAAM,EAAE,SAAS;GACjB,KAAK;GACL,CAAC;EACF,IAAI,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M,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,IAAI,IAAI;EAC9C,IAAI,OAAO,GAAG,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC;EAChF,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,kBAAkB,CAAC,OAAO,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;EAC9E,CAAC,CAAC;;CAEH,OAAO;EACN,kBAAkB;EAClB,aAAa;EACb;CACD;;AAED,AAAO,SAAS,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE;CAC9C,IAAI,GAAG,GAAG,CAAC,IAAI,IAAI,EAAE,IAAI,IAAI,CAAC;CAC9B,OAAO,CAAC,qCAAqC,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;CAChE;;;;"}
\ No newline at end of file
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var camelcase = _interopDefault(require('camelcase'));
/**
* Created by rockyl on 2019-11-13.
*
* 模板填充
*/
const dynamicValueReg = /\$[\w|(\.)]+\$/g;
function analyseTemplate(tpl) {
let result = [];
let matchResult = tpl.match(dynamicValueReg);
for (let matchItem of matchResult) {
let hint = matchItem.substr(1, matchItem.length - 2);
let arr = hint.split('.');
let field = camelcase(arr[0]);
let item = {
source: matchItem,
field,
};
if (arr[1] !== undefined) {
item.subField = arr[1];
}
result.push(item);
}
return result;
}
function fillTemplate(tpl, params, analyseResult) {
analyseResult = analyseResult || analyseTemplate(tpl);
for (let item of analyseResult) {
let fieldData = params[item.field];
if (fieldData && item.subField) {
fieldData = fieldData[item.subField];
}
if (fieldData) {
tpl = tpl.replace(item.source, fieldData);
}
}
return tpl;
}
async function generateLibraryScriptEl(tpl, dependencies, getPackages, libraryPath) {
let analyseResult = analyseTemplate(tpl);
let librariesHint = analyseResult.filter(item => item.field === 'libraries').map(item => item.subField);
let schema = {};
for (let libName of librariesHint) {
if (dependencies[libName]) {
schema[libName] = dependencies[libName];
}
}
let libraryScriptElMap = {};
(await getPackages(schema, 0)).forEach(item => {
let itemObj = typeof item.data === 'string' ? JSON.parse(item.data) : item.data;
libraryScriptElMap[itemObj.id] = generateJsScriptEl(itemObj.url, libraryPath);
});
return {
libraryScriptElMap,
analyseResult,
}
}
function generateJsScriptEl(file, path) {
let url = (path || '') + file;
return `<script crossorigin="anonymous" src="${url}"></script>`;
}
exports.analyseTemplate = analyseTemplate;
exports.fillTemplate = fillTemplate;
exports.generateJsScriptEl = generateJsScriptEl;
exports.generateLibraryScriptEl = generateLibraryScriptEl;
//# sourceMappingURL=index.js.map
{"version":3,"file":"index.js","sources":["../src/index.js"],"sourcesContent":["/**\n * Created by rockyl on 2019-11-13.\n *\n * 模板填充\n */\n\nimport camelcase from 'camelcase'\n\nconst TAG = 'zeroing-template-fill';\n\nconst dynamicValueReg = /\\$[\\w|(\\.)]+\\$/g;\n\nexport function analyseTemplate(tpl) {\n\tlet result = [];\n\tlet matchResult = tpl.match(dynamicValueReg);\n\tfor (let matchItem of matchResult) {\n\t\tlet hint = matchItem.substr(1, matchItem.length - 2);\n\t\tlet arr = hint.split('.');\n\t\tlet field = camelcase(arr[0]);\n\n\t\tlet item = {\n\t\t\tsource: matchItem,\n\t\t\tfield,\n\t\t};\n\t\tif (arr[1] !== undefined) {\n\t\t\titem.subField = arr[1];\n\t\t}\n\t\tresult.push(item)\n\t}\n\treturn result;\n}\n\nexport function fillTemplate(tpl, params, analyseResult) {\n\tanalyseResult = analyseResult || analyseTemplate(tpl);\n\tfor (let item of analyseResult) {\n\t\tlet fieldData = params[item.field];\n\t\tif (fieldData && item.subField) {\n\t\t\tfieldData = fieldData[item.subField];\n\t\t}\n\t\tif (fieldData) {\n\t\t\ttpl = tpl.replace(item.source, fieldData);\n\t\t}\n\t}\n\n\treturn tpl;\n}\n\nexport async function generateLibraryScriptEl(tpl, dependencies, getPackages, libraryPath) {\n\tlet analyseResult = analyseTemplate(tpl);\n\tlet librariesHint = analyseResult.filter(item => item.field === 'libraries').map(item => item.subField);\n\tlet schema = {};\n\tfor (let libName of librariesHint) {\n\t\tif (dependencies[libName]) {\n\t\t\tschema[libName] = dependencies[libName];\n\t\t}\n\t}\n\n\tlet libraryScriptElMap = {};\n\t(await getPackages(schema, 0)).forEach(item => {\n\t\tlet itemObj = typeof item.data === 'string' ? JSON.parse(item.data) : item.data;\n\t\tlibraryScriptElMap[itemObj.id] = generateJsScriptEl(itemObj.url, libraryPath);\n\t});\n\n\treturn {\n\t\tlibraryScriptElMap,\n\t\tanalyseResult,\n\t}\n}\n\nexport function generateJsScriptEl(file, path) {\n\tlet url = (path || '') + file;\n\treturn `<script crossorigin=\"anonymous\" src=\"${url}\"></script>`;\n}\n"],"names":[],"mappings":";;;;;;;;AAAA;;;;;AAKA,AAIA;AACA,MAAM,eAAe,GAAG,iBAAiB,CAAC;;AAE1C,AAAO,SAAS,eAAe,CAAC,GAAG,EAAE;CACpC,IAAI,MAAM,GAAG,EAAE,CAAC;CAChB,IAAI,WAAW,GAAG,GAAG,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;CAC7C,KAAK,IAAI,SAAS,IAAI,WAAW,EAAE;EAClC,IAAI,IAAI,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;EACrD,IAAI,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;EAC1B,IAAI,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;;EAE9B,IAAI,IAAI,GAAG;GACV,MAAM,EAAE,SAAS;GACjB,KAAK;GACL,CAAC;EACF,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE;GACzB,IAAI,CAAC,QAAQ,G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EAC9C,IAAI,OAAO,GAAG,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC;EAChF,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,kBAAkB,CAAC,OAAO,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;EAC9E,CAAC,CAAC;;CAEH,OAAO;EACN,kBAAkB;EAClB,aAAa;EACb;CACD;;AAED,AAAO,SAAS,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE;CAC9C,IAAI,GAAG,GAAG,CAAC,IAAI,IAAI,EAAE,IAAI,IAAI,CAAC;CAC9B,OAAO,CAAC,qCAAqC,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;CAChE;;;;;;;"}
\ No newline at end of file
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('camelcase')) :
typeof define === 'function' && define.amd ? define(['exports', 'camelcase'], factory) :
(global = global || self, factory(global['zeroing-pack'] = {}, global.camelcase));
}(this, function (exports, camelcase) { 'use strict';
camelcase = camelcase && camelcase.hasOwnProperty('default') ? camelcase['default'] : camelcase;
/**
* Created by rockyl on 2019-11-13.
*
* 模板填充
*/
const dynamicValueReg = /\$[\w|(\.)]+\$/g;
function analyseTemplate(tpl) {
let result = [];
let matchResult = tpl.match(dynamicValueReg);
for (let matchItem of matchResult) {
let hint = matchItem.substr(1, matchItem.length - 2);
let arr = hint.split('.');
let field = camelcase(arr[0]);
let item = {
source: matchItem,
field,
};
if (arr[1] !== undefined) {
item.subField = arr[1];
}
result.push(item);
}
return result;
}
function fillTemplate(tpl, params, analyseResult) {
analyseResult = analyseResult || analyseTemplate(tpl);
for (let item of analyseResult) {
let fieldData = params[item.field];
if (fieldData && item.subField) {
fieldData = fieldData[item.subField];
}
if (fieldData) {
tpl = tpl.replace(item.source, fieldData);
}
}
return tpl;
}
async function generateLibraryScriptEl(tpl, dependencies, getPackages, libraryPath) {
let analyseResult = analyseTemplate(tpl);
let librariesHint = analyseResult.filter(item => item.field === 'libraries').map(item => item.subField);
let schema = {};
for (let libName of librariesHint) {
if (dependencies[libName]) {
schema[libName] = dependencies[libName];
}
}
let libraryScriptElMap = {};
(await getPackages(schema, 0)).forEach(item => {
let itemObj = typeof item.data === 'string' ? JSON.parse(item.data) : item.data;
libraryScriptElMap[itemObj.id] = generateJsScriptEl(itemObj.url, libraryPath);
});
return {
libraryScriptElMap,
analyseResult,
}
}
function generateJsScriptEl(file, path) {
let url = (path || '') + file;
return `<script crossorigin="anonymous" src="${url}"></script>`;
}
exports.analyseTemplate = analyseTemplate;
exports.fillTemplate = fillTemplate;
exports.generateJsScriptEl = generateJsScriptEl;
exports.generateLibraryScriptEl = generateLibraryScriptEl;
Object.defineProperty(exports, '__esModule', { value: true });
}));
//# sourceMappingURL=index.umd.js.map
{"version":3,"file":"index.umd.js","sources":["../src/index.js"],"sourcesContent":["/**\n * Created by rockyl on 2019-11-13.\n *\n * 模板填充\n */\n\nimport camelcase from 'camelcase'\n\nconst TAG = 'zeroing-template-fill';\n\nconst dynamicValueReg = /\\$[\\w|(\\.)]+\\$/g;\n\nexport function analyseTemplate(tpl) {\n\tlet result = [];\n\tlet matchResult = tpl.match(dynamicValueReg);\n\tfor (let matchItem of matchResult) {\n\t\tlet hint = matchItem.substr(1, matchItem.length - 2);\n\t\tlet arr = hint.split('.');\n\t\tlet field = camelcase(arr[0]);\n\n\t\tlet item = {\n\t\t\tsource: matchItem,\n\t\t\tfield,\n\t\t};\n\t\tif (arr[1] !== undefined) {\n\t\t\titem.subField = arr[1];\n\t\t}\n\t\tresult.push(item)\n\t}\n\treturn result;\n}\n\nexport function fillTemplate(tpl, params, analyseResult) {\n\tanalyseResult = analyseResult || analyseTemplate(tpl);\n\tfor (let item of analyseResult) {\n\t\tlet fieldData = params[item.field];\n\t\tif (fieldData && item.subField) {\n\t\t\tfieldData = fieldData[item.subField];\n\t\t}\n\t\tif (fieldData) {\n\t\t\ttpl = tpl.replace(item.source, fieldData);\n\t\t}\n\t}\n\n\treturn tpl;\n}\n\nexport async function generateLibraryScriptEl(tpl, dependencies, getPackages, libraryPath) {\n\tlet analyseResult = analyseTemplate(tpl);\n\tlet librariesHint = analyseResult.filter(item => item.field === 'libraries').map(item => item.subField);\n\tlet schema = {};\n\tfor (let libName of librariesHint) {\n\t\tif (dependencies[libName]) {\n\t\t\tschema[libName] = dependencies[libName];\n\t\t}\n\t}\n\n\tlet libraryScriptElMap = {};\n\t(await getPackages(schema, 0)).forEach(item => {\n\t\tlet itemObj = typeof item.data === 'string' ? JSON.parse(item.data) : item.data;\n\t\tlibraryScriptElMap[itemObj.id] = generateJsScriptEl(itemObj.url, libraryPath);\n\t});\n\n\treturn {\n\t\tlibraryScriptElMap,\n\t\tanalyseResult,\n\t}\n}\n\nexport function generateJsScriptEl(file, path) {\n\tlet url = (path || '') + file;\n\treturn `<script crossorigin=\"anonymous\" src=\"${url}\"></script>`;\n}\n"],"names":[],"mappings":";;;;;;;;CAAA;CACA;CACA;CACA;CACA;AACA,AAIA;CACA,MAAM,eAAe,GAAG,iBAAiB,CAAC;;AAE1C,CAAO,SAAS,eAAe,CAAC,GAAG,EAAE;CACrC,CAAC,IAAI,MAAM,GAAG,EAAE,CAAC;CACjB,CAAC,IAAI,WAAW,GAAG,GAAG,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;CAC9C,CAAC,KAAK,IAAI,SAAS,IAAI,WAAW,EAAE;CACpC,EAAE,IAAI,IAAI,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;CACvD,EAAE,IAAI,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;CAC5B,EAAE,IAAI,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;;CAEhC,EAAE,IAAI,IAAI,GAA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jB,CAAC,KAAK,IAAI,OAAO,IAAI,aAAa,EAAE;CACpC,EAAE,IAAI,YAAY,CAAC,OAAO,CAAC,EAAE;CAC7B,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;CAC3C,GAAG;CACH,EAAE;;CAEF,CAAC,IAAI,kBAAkB,GAAG,EAAE,CAAC;CAC7B,CAAC,CAAC,MAAM,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,IAAI,IAAI;CAChD,EAAE,IAAI,OAAO,GAAG,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC;CAClF,EAAE,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,kBAAkB,CAAC,OAAO,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;CAChF,EAAE,CAAC,CAAC;;CAEJ,CAAC,OAAO;CACR,EAAE,kBAAkB;CACpB,EAAE,aAAa;CACf,EAAE;CACF,CAAC;;AAED,CAAO,SAAS,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE;CAC/C,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,IAAI,EAAE,IAAI,IAAI,CAAC;CAC/B,CAAC,OAAO,CAAC,qCAAqC,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;CACjE,CAAC;;;;;;;;;;;;;;;"}
\ No newline at end of file
{
"name": "zeroing-template-fill",
"version": "1.0.0",
"main": "dist/index.js",
"module": "dist/index.es.js",
"license": "MIT",
"scripts": {
"dev": "rollup -c -w",
"build": "rollup -c"
},
"dependencies": {
"camelcase": "^5.3.1"
}
}
/**
* Created by rockyl on 2018/11/16.
*/
const name = 'zeroing-pack';
export default {
input: 'src/index.js',
output: [
{
file: `dist/index.js`,
format: 'cjs',
sourcemap: true,
},
{
file: `dist/index.es.js`,
format: 'es',
sourcemap: true,
},
{
file: `dist/index.umd.js`,
format: 'umd',
sourcemap: true,
name,
}
],
plugins: [
]
};
/**
* Created by rockyl on 2019-11-13.
*
* 模板填充
*/
import camelcase from 'camelcase'
const TAG = 'zeroing-template-fill';
const dynamicValueReg = /\$[\w|(\.)]+\$/g;
export function analyseTemplate(tpl) {
let result = [];
let matchResult = tpl.match(dynamicValueReg);
for (let matchItem of matchResult) {
let hint = matchItem.substr(1, matchItem.length - 2);
let arr = hint.split('.');
let field = camelcase(arr[0]);
let item = {
source: matchItem,
field,
};
if (arr[1] !== undefined) {
item.subField = arr[1];
}
result.push(item)
}
return result;
}
export function fillTemplate(tpl, params, analyseResult) {
analyseResult = analyseResult || analyseTemplate(tpl);
for (let item of analyseResult) {
let fieldData = params[item.field];
if (fieldData && item.subField) {
fieldData = fieldData[item.subField];
}
if (fieldData) {
tpl = tpl.replace(item.source, fieldData);
}
}
return tpl;
}
export async function generateLibraryScriptEl(tpl, dependencies, getPackages, libraryPath) {
let analyseResult = analyseTemplate(tpl);
let librariesHint = analyseResult.filter(item => item.field === 'libraries').map(item => item.subField);
let schema = {};
for (let libName of librariesHint) {
if (dependencies[libName]) {
schema[libName] = dependencies[libName];
}
}
let libraryScriptElMap = {};
(await getPackages(schema, 0)).forEach(item => {
let itemObj = typeof item.data === 'string' ? JSON.parse(item.data) : item.data;
libraryScriptElMap[itemObj.id] = generateJsScriptEl(itemObj.url, libraryPath);
});
return {
libraryScriptElMap,
analyseResult,
}
}
export function generateJsScriptEl(file, path) {
let url = (path || '') + file;
return `<script crossorigin="anonymous" src="${url}"></script>`;
}
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
camelcase@^5.3.1:
version "5.3.1"
resolved "https://registry.npm.taobao.org/camelcase/download/camelcase-5.3.1.tgz#e3c9b31569e106811df242f715725a1f4c494320"
integrity sha1-48mzFWnhBoEd8kL3FXJaH0xJQyA=
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment