Commit e6891b70 authored by rockyl's avatar rockyl

增加zeroing-template-fill

parent fef8a31c
import decamelize from 'decamelize';
import babel from '@babel/core';
import { divideCode } from 'zeroing-code-divider';
import { generateLibraryScriptEl, generateJsScriptEl, fillTemplate } from 'zeroing-template-fill';
/**
* Created by rockyl on 2019-11-30.
......@@ -44,8 +44,13 @@ const replaceFields = ['pageTitle', 'containerId'];
const TAG = 'zeroing-pack';
async function pack(data, options) {
let dependencies = data.dependencies;
let getPackages = options.getPackages;
const {libraryScriptElMap, analyseResult} = await generateLibraryScriptEl(data.options.tpl, dependencies, getPackages, '//yun.duiba.com.cn/editor/zeroing/libs/');
let version = Date.now() + Math.floor(Math.random() * 1000);
pageTemplate(data, data.options, version);
pageTemplate(data, data.options, version, analyseResult, libraryScriptElMap);
const newData = await packData(data, options);
return {
......@@ -56,7 +61,8 @@ async function pack(data, options) {
function fillTpl(data, params) {
const {options} = data;
fillTemplate(options.newTpl, options, params);
params.scripts = params.scripts.map(item => generateJsScriptEl(item)).join('\n');
options.newTpl = fillTemplate(options.newTpl, params);
const newTpl = options.newTpl;
delete options.newTpl;
......@@ -85,6 +91,7 @@ async function packData(data, {debug, packedAssets, getPackages}) {
debug,
uglify, compile,
getPackages,
dependencies: data.dependencies,
});
return {
......@@ -115,23 +122,16 @@ function deleteUnusedData(processes) {
}
}
function pageTemplate(tpl, options, version) {
function pageTemplate(tpl, options, version, analyseResult, libraryScriptElMap) {
const params = {
version,
libraries: libraryScriptElMap,
};
for (let field of replaceFields) {
params[field] = options[field];
}
fillTemplate(options.tpl, options, params);
}
function fillTemplate(tpl, options, params) {
for (let field in params) {
const pattern = decamelize(field).toUpperCase();
tpl = tpl.replace(new RegExp(`\\$${pattern}\\$`, 'g'), params[field]);
}
options.newTpl = tpl;
options.newTpl = fillTemplate(options.tpl, params, analyseResult);
}
export { fillTpl, pack };
......
This diff is collapsed.
......@@ -4,9 +4,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var decamelize = _interopDefault(require('decamelize'));
var babel = _interopDefault(require('@babel/core'));
var zeroingCodeDivider = require('zeroing-code-divider');
var zeroingTemplateFill = require('zeroing-template-fill');
/**
* Created by rockyl on 2019-11-30.
......@@ -50,8 +50,13 @@ const replaceFields = ['pageTitle', 'containerId'];
const TAG = 'zeroing-pack';
async function pack(data, options) {
let dependencies = data.dependencies;
let getPackages = options.getPackages;
const {libraryScriptElMap, analyseResult} = await zeroingTemplateFill.generateLibraryScriptEl(data.options.tpl, dependencies, getPackages, '//yun.duiba.com.cn/editor/zeroing/libs/');
let version = Date.now() + Math.floor(Math.random() * 1000);
pageTemplate(data, data.options, version);
pageTemplate(data, data.options, version, analyseResult, libraryScriptElMap);
const newData = await packData(data, options);
return {
......@@ -62,7 +67,8 @@ async function pack(data, options) {
function fillTpl(data, params) {
const {options} = data;
fillTemplate(options.newTpl, options, params);
params.scripts = params.scripts.map(item => zeroingTemplateFill.generateJsScriptEl(item)).join('\n');
options.newTpl = zeroingTemplateFill.fillTemplate(options.newTpl, params);
const newTpl = options.newTpl;
delete options.newTpl;
......@@ -91,6 +97,7 @@ async function packData(data, {debug, packedAssets, getPackages}) {
debug,
uglify, compile,
getPackages,
dependencies: data.dependencies,
});
return {
......@@ -121,23 +128,16 @@ function deleteUnusedData(processes) {
}
}
function pageTemplate(tpl, options, version) {
function pageTemplate(tpl, options, version, analyseResult, libraryScriptElMap) {
const params = {
version,
libraries: libraryScriptElMap,
};
for (let field of replaceFields) {
params[field] = options[field];
}
fillTemplate(options.tpl, options, params);
}
function fillTemplate(tpl, options, params) {
for (let field in params) {
const pattern = decamelize(field).toUpperCase();
tpl = tpl.replace(new RegExp(`\\$${pattern}\\$`, 'g'), params[field]);
}
options.newTpl = tpl;
options.newTpl = zeroingTemplateFill.fillTemplate(options.tpl, params, analyseResult);
}
exports.fillTpl = fillTpl;
......
This diff is collapsed.
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('decamelize'), require('@babel/core'), require('zeroing-code-divider')) :
typeof define === 'function' && define.amd ? define(['exports', 'decamelize', '@babel/core', 'zeroing-code-divider'], factory) :
(global = global || self, factory(global['zeroing-pack'] = {}, global.decamelize, global.babel, global.zeroingCodeDivider));
}(this, function (exports, decamelize, babel, zeroingCodeDivider) { 'use strict';
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@babel/core'), require('zeroing-code-divider'), require('zeroing-template-fill')) :
typeof define === 'function' && define.amd ? define(['exports', '@babel/core', 'zeroing-code-divider', 'zeroing-template-fill'], factory) :
(global = global || self, factory(global['zeroing-pack'] = {}, global.babel, global.zeroingCodeDivider, global.zeroingTemplateFill));
}(this, function (exports, babel, zeroingCodeDivider, zeroingTemplateFill) { 'use strict';
decamelize = decamelize && decamelize.hasOwnProperty('default') ? decamelize['default'] : decamelize;
babel = babel && babel.hasOwnProperty('default') ? babel['default'] : babel;
/**
......@@ -49,8 +48,13 @@
const TAG = 'zeroing-pack';
async function pack(data, options) {
let dependencies = data.dependencies;
let getPackages = options.getPackages;
const {libraryScriptElMap, analyseResult} = await zeroingTemplateFill.generateLibraryScriptEl(data.options.tpl, dependencies, getPackages, '//yun.duiba.com.cn/editor/zeroing/libs/');
let version = Date.now() + Math.floor(Math.random() * 1000);
pageTemplate(data, data.options, version);
pageTemplate(data, data.options, version, analyseResult, libraryScriptElMap);
const newData = await packData(data, options);
return {
......@@ -61,7 +65,8 @@
function fillTpl(data, params) {
const {options} = data;
fillTemplate(options.newTpl, options, params);
params.scripts = params.scripts.map(item => zeroingTemplateFill.generateJsScriptEl(item)).join('\n');
options.newTpl = zeroingTemplateFill.fillTemplate(options.newTpl, params);
const newTpl = options.newTpl;
delete options.newTpl;
......@@ -90,6 +95,7 @@
debug,
uglify, compile,
getPackages,
dependencies: data.dependencies,
});
return {
......@@ -120,23 +126,16 @@
}
}
function pageTemplate(tpl, options, version) {
function pageTemplate(tpl, options, version, analyseResult, libraryScriptElMap) {
const params = {
version,
libraries: libraryScriptElMap,
};
for (let field of replaceFields) {
params[field] = options[field];
}
fillTemplate(options.tpl, options, params);
}
function fillTemplate(tpl, options, params) {
for (let field in params) {
const pattern = decamelize(field).toUpperCase();
tpl = tpl.replace(new RegExp(`\\$${pattern}\\$`, 'g'), params[field]);
}
options.newTpl = tpl;
options.newTpl = zeroingTemplateFill.fillTemplate(options.tpl, params, analyseResult);
}
exports.fillTpl = fillTpl;
......
This diff is collapsed.
......@@ -6,11 +6,12 @@
"dependencies": {
"@babel/core": "^7.7.4",
"@babel/preset-env": "^7.7.4",
"decamelize": "^3.2.0",
"gensync": "^1.0.0-beta.1",
"uglify-js": "^3.7.1",
"zeroing-code-divider": "http://gitlab2.dui88.com/laoqifeng/zeroing-code-divider.git"
},
"scripts": {
"dev": "rollup -c -w",
"build": "rollup -c"
}
}
......@@ -4,16 +4,21 @@
* 项目打包
*/
import decamelize from 'decamelize'
import {uglify, compile} from "./code-process";
import {divideCode} from 'zeroing-code-divider';
import {generateLibraryScriptEl, fillTemplate, generateJsScriptEl} from 'zeroing-template-fill';
const replaceFields = ['pageTitle', 'containerId'];
const TAG = 'zeroing-pack';
export async function pack(data, options) {
let dependencies = data.dependencies;
let getPackages = options.getPackages;
const {libraryScriptElMap, analyseResult} = await generateLibraryScriptEl(data.options.tpl, dependencies, getPackages, '//yun.duiba.com.cn/editor/zeroing/libs/');
let version = Date.now() + Math.floor(Math.random() * 1000);
pageTemplate(data, data.options, version);
pageTemplate(data, data.options, version, analyseResult, libraryScriptElMap);
const newData = await packData(data, options);
return {
......@@ -24,7 +29,8 @@ export async function pack(data, options) {
export function fillTpl(data, params) {
const {options} = data;
fillTemplate(options.newTpl, options, params);
params.scripts = params.scripts.map(item => generateJsScriptEl(item)).join('\n');
options.newTpl = fillTemplate(options.newTpl, params);
const newTpl = options.newTpl;
delete options.newTpl;
......@@ -53,6 +59,7 @@ async function packData(data, {debug, packedAssets, getPackages}) {
debug,
uglify, compile,
getPackages,
dependencies: data.dependencies,
});
return {
......@@ -83,21 +90,14 @@ function deleteUnusedData(processes) {
}
}
function pageTemplate(tpl, options, version) {
function pageTemplate(tpl, options, version, analyseResult, libraryScriptElMap) {
const params = {
version,
libraries: libraryScriptElMap,
};
for (let field of replaceFields) {
params[field] = options[field];
}
fillTemplate(options.tpl, options, params);
}
function fillTemplate(tpl, options, params) {
for (let field in params) {
const pattern = decamelize(field).toUpperCase();
tpl = tpl.replace(new RegExp(`\\$${pattern}\\$`, 'g'), params[field]);
}
options.newTpl = tpl;
options.newTpl = fillTemplate(options.tpl, params, analyseResult);
}
This diff is collapsed.
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