Commit 4f9a7485 authored by rockyl's avatar rockyl

init

parent bbeb7c0d
import ts from 'typescript'; import ts from 'typescript';
import UglifyJS from 'uglify-js'; import UglifyJS from 'uglify-js';
import { divideCode } from 'zeroing-code-divider'; import { divideCode } from 'zeroing-code-divider';
import { generateLibraryScriptEl, generateJsScriptEl, fillTemplate } from 'zeroing-template-fill'; import { generateLibraryScriptEl, generateJsScriptBodyEl, generateJsScriptEl, fillTemplate } from 'zeroing-template-fill';
/** /**
* Created by rockyl on 2019-11-30. * Created by rockyl on 2019-11-30.
...@@ -55,9 +55,14 @@ async function pack(data, options) { ...@@ -55,9 +55,14 @@ async function pack(data, options) {
} }
} }
function fillTpl(data, params) { function fillTpl(data, params, mix) {
const {options} = data; const {options} = data;
params.scripts = params.scripts.map(item => generateJsScriptEl(item)).join('\n'); if (mix) {
let code = 'var adsComplete=false;ga.showBanner(function(){adsComplete=true},' + params.scripts.map(item => `'${item}'`).join(',') + ');';
params.scripts = generateJsScriptBodyEl(code);
} else {
params.scripts = params.scripts.map(item => generateJsScriptEl(item)).join('\n');
}
let tpl = fillTemplate(options.newTpl, params); let tpl = fillTemplate(options.newTpl, params);
delete options.newTpl; delete options.newTpl;
...@@ -68,7 +73,7 @@ function fillTpl(data, params) { ...@@ -68,7 +73,7 @@ function fillTpl(data, params) {
return tpl; return tpl;
} }
async function packData(data, {debug, packedAssets, getPackages}) { async function packData(data, {debug, mix, packedAssets, getPackages}) {
let newData = {}; let newData = {};
newData.options = data.options; newData.options = data.options;
newData.views = data.views; newData.views = data.views;
...@@ -90,7 +95,7 @@ async function packData(data, {debug, packedAssets, getPackages}) { ...@@ -90,7 +95,7 @@ async function packData(data, {debug, packedAssets, getPackages}) {
if (computed) { if (computed) {
for (let item of computed) { for (let item of computed) {
if (item.script) { if (item.script) {
item.script = (await compile(item.script)).code; item.script = (await compile(item.script)).code;
} }
} }
} }
...@@ -103,6 +108,7 @@ async function packData(data, {debug, packedAssets, getPackages}) { ...@@ -103,6 +108,7 @@ async function packData(data, {debug, packedAssets, getPackages}) {
customScriptContent, customScriptContent,
} = await divideCode(newData, { } = await divideCode(newData, {
debug, debug,
mix,
uglify, compile, uglify, compile,
getPackages, getPackages,
dependencies: data.dependencies, dependencies: data.dependencies,
......
This diff is collapsed.
...@@ -2,19 +2,22 @@ ...@@ -2,19 +2,22 @@
Object.defineProperty(exports, '__esModule', { value: true }); Object.defineProperty(exports, '__esModule', { value: true });
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } var ts = require('typescript');
var UglifyJS = require('uglify-js');
var ts = _interopDefault(require('typescript'));
var UglifyJS = _interopDefault(require('uglify-js'));
var zeroingCodeDivider = require('zeroing-code-divider'); var zeroingCodeDivider = require('zeroing-code-divider');
var zeroingTemplateFill = require('zeroing-template-fill'); var zeroingTemplateFill = require('zeroing-template-fill');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var ts__default = /*#__PURE__*/_interopDefaultLegacy(ts);
var UglifyJS__default = /*#__PURE__*/_interopDefaultLegacy(UglifyJS);
/** /**
* Created by rockyl on 2019-11-30. * Created by rockyl on 2019-11-30.
*/ */
async function compile(source, debug = false) { async function compile(source, debug = false) {
let output = ts.transpileModule(source, { let output = ts__default['default'].transpileModule(source, {
compilerOptions: {} compilerOptions: {}
}); });
...@@ -28,7 +31,7 @@ async function compile(source, debug = false) { ...@@ -28,7 +31,7 @@ async function compile(source, debug = false) {
} }
function uglify(source) { function uglify(source) {
const uglifyResult = UglifyJS.minify(source, {}); const uglifyResult = UglifyJS__default['default'].minify(source, {});
if (uglifyResult.error) { if (uglifyResult.error) {
throw new Error(uglifyResult.error); throw new Error(uglifyResult.error);
} else { } else {
...@@ -61,9 +64,14 @@ async function pack(data, options) { ...@@ -61,9 +64,14 @@ async function pack(data, options) {
} }
} }
function fillTpl(data, params) { function fillTpl(data, params, mix) {
const {options} = data; const {options} = data;
params.scripts = params.scripts.map(item => zeroingTemplateFill.generateJsScriptEl(item)).join('\n'); if (mix) {
let code = 'var adsComplete=false;ga.showBanner(function(){adsComplete=true},' + params.scripts.map(item => `'${item}'`).join(',') + ');';
params.scripts = zeroingTemplateFill.generateJsScriptBodyEl(code);
} else {
params.scripts = params.scripts.map(item => zeroingTemplateFill.generateJsScriptEl(item)).join('\n');
}
let tpl = zeroingTemplateFill.fillTemplate(options.newTpl, params); let tpl = zeroingTemplateFill.fillTemplate(options.newTpl, params);
delete options.newTpl; delete options.newTpl;
...@@ -74,7 +82,7 @@ function fillTpl(data, params) { ...@@ -74,7 +82,7 @@ function fillTpl(data, params) {
return tpl; return tpl;
} }
async function packData(data, {debug, packedAssets, getPackages}) { async function packData(data, {debug, mix, packedAssets, getPackages}) {
let newData = {}; let newData = {};
newData.options = data.options; newData.options = data.options;
newData.views = data.views; newData.views = data.views;
...@@ -96,7 +104,7 @@ async function packData(data, {debug, packedAssets, getPackages}) { ...@@ -96,7 +104,7 @@ async function packData(data, {debug, packedAssets, getPackages}) {
if (computed) { if (computed) {
for (let item of computed) { for (let item of computed) {
if (item.script) { if (item.script) {
item.script = (await compile(item.script)).code; item.script = (await compile(item.script)).code;
} }
} }
} }
...@@ -109,6 +117,7 @@ async function packData(data, {debug, packedAssets, getPackages}) { ...@@ -109,6 +117,7 @@ async function packData(data, {debug, packedAssets, getPackages}) {
customScriptContent, customScriptContent,
} = await zeroingCodeDivider.divideCode(newData, { } = await zeroingCodeDivider.divideCode(newData, {
debug, debug,
mix,
uglify, compile, uglify, compile,
getPackages, getPackages,
dependencies: data.dependencies, dependencies: data.dependencies,
......
This diff is collapsed.
(function (global, factory) { (function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('typescript'), require('uglify-js'), require('zeroing-code-divider'), require('zeroing-template-fill')) : typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('typescript'), require('uglify-js'), require('zeroing-code-divider'), require('zeroing-template-fill')) :
typeof define === 'function' && define.amd ? define(['exports', 'typescript', 'uglify-js', 'zeroing-code-divider', 'zeroing-template-fill'], factory) : typeof define === 'function' && define.amd ? define(['exports', 'typescript', 'uglify-js', 'zeroing-code-divider', 'zeroing-template-fill'], factory) :
(global = global || self, factory(global['zeroing-pack'] = {}, global.ts, global.UglifyJS, global.zeroingCodeDivider, global.zeroingTemplateFill)); (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global['zeroing-pack'] = {}, global.ts, global.UglifyJS, global.zeroingCodeDivider, global.zeroingTemplateFill));
}(this, function (exports, ts, UglifyJS, zeroingCodeDivider, zeroingTemplateFill) { 'use strict'; }(this, (function (exports, ts, UglifyJS, zeroingCodeDivider, zeroingTemplateFill) { 'use strict';
ts = ts && ts.hasOwnProperty('default') ? ts['default'] : ts; function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
UglifyJS = UglifyJS && UglifyJS.hasOwnProperty('default') ? UglifyJS['default'] : UglifyJS;
var ts__default = /*#__PURE__*/_interopDefaultLegacy(ts);
var UglifyJS__default = /*#__PURE__*/_interopDefaultLegacy(UglifyJS);
/** /**
* Created by rockyl on 2019-11-30. * Created by rockyl on 2019-11-30.
*/ */
async function compile(source, debug = false) { async function compile(source, debug = false) {
let output = ts.transpileModule(source, { let output = ts__default['default'].transpileModule(source, {
compilerOptions: {} compilerOptions: {}
}); });
...@@ -26,7 +28,7 @@ ...@@ -26,7 +28,7 @@
} }
function uglify(source) { function uglify(source) {
const uglifyResult = UglifyJS.minify(source, {}); const uglifyResult = UglifyJS__default['default'].minify(source, {});
if (uglifyResult.error) { if (uglifyResult.error) {
throw new Error(uglifyResult.error); throw new Error(uglifyResult.error);
} else { } else {
...@@ -59,9 +61,14 @@ ...@@ -59,9 +61,14 @@
} }
} }
function fillTpl(data, params) { function fillTpl(data, params, mix) {
const {options} = data; const {options} = data;
params.scripts = params.scripts.map(item => zeroingTemplateFill.generateJsScriptEl(item)).join('\n'); if (mix) {
let code = 'var adsComplete=false;ga.showBanner(function(){adsComplete=true},' + params.scripts.map(item => `'${item}'`).join(',') + ');';
params.scripts = zeroingTemplateFill.generateJsScriptBodyEl(code);
} else {
params.scripts = params.scripts.map(item => zeroingTemplateFill.generateJsScriptEl(item)).join('\n');
}
let tpl = zeroingTemplateFill.fillTemplate(options.newTpl, params); let tpl = zeroingTemplateFill.fillTemplate(options.newTpl, params);
delete options.newTpl; delete options.newTpl;
...@@ -72,7 +79,7 @@ ...@@ -72,7 +79,7 @@
return tpl; return tpl;
} }
async function packData(data, {debug, packedAssets, getPackages}) { async function packData(data, {debug, mix, packedAssets, getPackages}) {
let newData = {}; let newData = {};
newData.options = data.options; newData.options = data.options;
newData.views = data.views; newData.views = data.views;
...@@ -94,7 +101,7 @@ ...@@ -94,7 +101,7 @@
if (computed) { if (computed) {
for (let item of computed) { for (let item of computed) {
if (item.script) { if (item.script) {
item.script = (await compile(item.script)).code; item.script = (await compile(item.script)).code;
} }
} }
} }
...@@ -107,6 +114,7 @@ ...@@ -107,6 +114,7 @@
customScriptContent, customScriptContent,
} = await zeroingCodeDivider.divideCode(newData, { } = await zeroingCodeDivider.divideCode(newData, {
debug, debug,
mix,
uglify, compile, uglify, compile,
getPackages, getPackages,
dependencies: data.dependencies, dependencies: data.dependencies,
...@@ -157,5 +165,5 @@ ...@@ -157,5 +165,5 @@
Object.defineProperty(exports, '__esModule', { value: true }); Object.defineProperty(exports, '__esModule', { value: true });
})); })));
//# sourceMappingURL=index.umd.js.map //# sourceMappingURL=index.umd.js.map
This diff is collapsed.
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
import {uglify, compile} from "./code-process"; import {uglify, compile} from "./code-process";
import {divideCode} from 'zeroing-code-divider'; import {divideCode} from 'zeroing-code-divider';
import {generateLibraryScriptEl, fillTemplate, generateJsScriptEl} from 'zeroing-template-fill'; import {generateLibraryScriptEl, fillTemplate, generateJsScriptEl, generateJsScriptBodyEl} from 'zeroing-template-fill';
const replaceFields = ['pageTitle', 'containerId']; const replaceFields = ['pageTitle', 'containerId'];
const TAG = 'zeroing-pack'; const TAG = 'zeroing-pack';
...@@ -27,9 +27,14 @@ export async function pack(data, options) { ...@@ -27,9 +27,14 @@ export async function pack(data, options) {
} }
} }
export function fillTpl(data, params) { export function fillTpl(data, params, mix) {
const {options} = data; const {options} = data;
params.scripts = params.scripts.map(item => generateJsScriptEl(item)).join('\n'); if (mix) {
let code = 'var adsComplete=false;ga.showBanner(function(){adsComplete=true},' + params.scripts.map(item => `'${item}'`).join(',') + ');';
params.scripts = generateJsScriptBodyEl(code);
} else {
params.scripts = params.scripts.map(item => generateJsScriptEl(item)).join('\n')
}
let tpl = fillTemplate(options.newTpl, params); let tpl = fillTemplate(options.newTpl, params);
delete options.newTpl; delete options.newTpl;
...@@ -40,7 +45,7 @@ export function fillTpl(data, params) { ...@@ -40,7 +45,7 @@ export function fillTpl(data, params) {
return tpl; return tpl;
} }
async function packData(data, {debug, packedAssets, getPackages}) { async function packData(data, {debug, mix, packedAssets, getPackages}) {
let newData = {}; let newData = {};
newData.options = data.options; newData.options = data.options;
newData.views = data.views; newData.views = data.views;
...@@ -62,7 +67,7 @@ async function packData(data, {debug, packedAssets, getPackages}) { ...@@ -62,7 +67,7 @@ async function packData(data, {debug, packedAssets, getPackages}) {
if (computed) { if (computed) {
for (let item of computed) { for (let item of computed) {
if (item.script) { if (item.script) {
item.script = (await compile(item.script)).code; item.script = (await compile(item.script)).code;
} }
} }
} }
...@@ -75,6 +80,7 @@ async function packData(data, {debug, packedAssets, getPackages}) { ...@@ -75,6 +80,7 @@ async function packData(data, {debug, packedAssets, getPackages}) {
customScriptContent, customScriptContent,
} = await divideCode(newData, { } = await divideCode(newData, {
debug, debug,
mix,
uglify, compile, uglify, compile,
getPackages, getPackages,
dependencies: data.dependencies, dependencies: data.dependencies,
......
...@@ -4,8 +4,12 @@ ...@@ -4,8 +4,12 @@
camelcase@^5.3.1: camelcase@^5.3.1:
version "5.3.1" version "5.3.1"
resolved "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz#e3c9b31569e106811df242f715725a1f4c494320" resolved "https://registry.npm.taobao.org/camelcase/download/camelcase-5.3.1.tgz#e3c9b31569e106811df242f715725a1f4c494320"
integrity sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg== integrity sha1-48mzFWnhBoEd8kL3FXJaH0xJQyA=
"code-mix@http://gitlab2.dui88.com/laoqifeng/code-mix.git":
version "1.0.0"
resolved "http://gitlab2.dui88.com/laoqifeng/code-mix.git#b39b10d6dbe8796b7bb8ad0b0303dda5bd470166"
commander@~2.20.3: commander@~2.20.3:
version "2.20.3" version "2.20.3"
...@@ -14,7 +18,7 @@ commander@~2.20.3: ...@@ -14,7 +18,7 @@ commander@~2.20.3:
"props-compute@http://gitlab2.dui88.com/laoqifeng/props-compute.git": "props-compute@http://gitlab2.dui88.com/laoqifeng/props-compute.git":
version "1.0.0" version "1.0.0"
resolved "http://gitlab2.dui88.com/laoqifeng/props-compute.git#8ef14521dd1ed4148999b23871e93000a9d4fc88" resolved "http://gitlab2.dui88.com/laoqifeng/props-compute.git#e293595fc82a9e38f989297bf549aafd1ab9b404"
source-map@~0.6.1: source-map@~0.6.1:
version "0.6.1" version "0.6.1"
...@@ -36,12 +40,13 @@ uglify-js@^3.7.1: ...@@ -36,12 +40,13 @@ uglify-js@^3.7.1:
"zeroing-code-divider@http://gitlab2.dui88.com/laoqifeng/zeroing-code-divider.git": "zeroing-code-divider@http://gitlab2.dui88.com/laoqifeng/zeroing-code-divider.git":
version "1.0.1" version "1.0.1"
resolved "http://gitlab2.dui88.com/laoqifeng/zeroing-code-divider.git#2ab6ba47c6657c5f5fca63f99df09cafc80de6cd" resolved "http://gitlab2.dui88.com/laoqifeng/zeroing-code-divider.git#33c2aa582d99010039d0f45cd19c9b3c4b591da6"
dependencies: dependencies:
code-mix "http://gitlab2.dui88.com/laoqifeng/code-mix.git"
props-compute "http://gitlab2.dui88.com/laoqifeng/props-compute.git" props-compute "http://gitlab2.dui88.com/laoqifeng/props-compute.git"
"zeroing-template-fill@http://gitlab2.dui88.com/laoqifeng/zeroing-template-fill.git": "zeroing-template-fill@http://gitlab2.dui88.com/laoqifeng/zeroing-template-fill.git":
version "1.0.0" version "1.0.0"
resolved "http://gitlab2.dui88.com/laoqifeng/zeroing-template-fill.git#2191ce9acc9d2ecdc7ab6510c6ca6c68339f47db" resolved "http://gitlab2.dui88.com/laoqifeng/zeroing-template-fill.git#143e862639493dee94ab5973ab9895d116bdc7c5"
dependencies: dependencies:
camelcase "^5.3.1" camelcase "^5.3.1"
...@@ -2,7 +2,10 @@ ...@@ -2,7 +2,10 @@
<module type="WEB_MODULE" version="4"> <module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true"> <component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$/../zeroing-pack" /> <content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/dist" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
</module> </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