Commit f13ae869 authored by rockyl's avatar rockyl

压缩代码抛出错误

parent 4d6d677e
...@@ -8,9 +8,9 @@ import { generateLibraryScriptEl, generateJsScriptEl, fillTemplate } from 'zeroi ...@@ -8,9 +8,9 @@ import { generateLibraryScriptEl, generateJsScriptEl, fillTemplate } from 'zeroi
*/ */
async function compile(source, debug = false) { async function compile(source, debug = false) {
let output = ts.transpileModule(source, {compilerOptions: { let output = ts.transpileModule(source, {
compilerOptions: {}
}}); });
const result = { const result = {
code: output.outputText, code: output.outputText,
...@@ -23,7 +23,9 @@ async function compile(source, debug = false) { ...@@ -23,7 +23,9 @@ async function compile(source, debug = false) {
function uglify(source) { function uglify(source) {
const uglifyResult = UglifyJS.minify(source, {}); const uglifyResult = UglifyJS.minify(source, {});
if (!uglifyResult.error) { if (uglifyResult.error) {
throw new Error(uglifyResult.error);
} else {
return uglifyResult.code; return uglifyResult.code;
} }
} }
......
{"version":3,"file":"index.es.js","sources":["../src/code-process.js","../src/index.js"],"sourcesContent":["/**\n * Created by rockyl on 2019-11-30.\n */\n\nimport ts from 'typescript';\nimport UglifyJS from 'uglify-js';\n\nexport async function compile(source, debug = false) {\n\tlet output = ts.transpileModule(source, {compilerOptions: {\n\n\t\t}});\n\n\tconst result = {\n\t\tcode: output.outputText,\n\t};\n\t/*if (map) {\n\t\tresult.sourcemap = map.mappings;\n\t}*/\n\treturn result;\n}\n\nexport function uglify(source) {\n\tconst uglifyResult = UglifyJS.minify(source, {});\n\tif (!uglifyResult.error) {\n\t\treturn uglifyResult.code;\n\t}\n}","/**\n * Created by rockyl on 2019-11-13.\n *\n * 项目打包\n */\n\nimport {uglify, compile} from \"./code-process\";\nimport {divideCode} from 'zeroing-code-divider';\nimport {generateLibraryScriptEl, fillTemplate, generateJsScriptEl} from 'zeroing-template-fill';\n\nconst replaceFields = ['pageTitle', 'containerId'];\nconst TAG = 'zeroing-pack';\n\nexport async function pack(data, options) {\n\tlet dependencies = data.dependencies;\n\tlet getPackages = options.getPackages;\n\n\tconst {libraryScriptElMap, analyseResult} = await generateLibraryScriptEl(data.options.tpl, dependencies, getPackages, '//yun.duiba.com.cn/editor/zeroing/libs/');\n\n\tlet version = Date.now() + Math.floor(Math.random() * 1000);\n\tpageTemplate(data, data.options, version, analyseResult, libraryScriptElMap);\n\tconst newData = await packData(data, options);\n\n\treturn {\n\t\tversion,\n\t\tdata: newData,\n\t}\n}\n\nexport function fillTpl(data, params) {\n\tconst {options} = data;\n\tparams.scripts = params.scripts.map(item => generateJsScriptEl(item)).join('\\n');\n\tlet tpl = fillTemplate(options.newTpl, params);\n\n\tdelete options.newTpl;\n\tdelete options.tpl;\n\tdelete options.projectxConfig;\n\tdelete options.pxEnv;\n\n\treturn tpl;\n}\n\nasync function packData(data, {debug, packedAssets, getPackages}) {\n\tlet newData = {};\n\tnewData.options = data.options;\n\tnewData.views = data.views;\n\tnewData.assets = packedAssets || data.assets;\n\tnewData.dataMapping = data.dataMapping;\n\tnewData.processes = data.processes;\n\tnewData.customs = data.customs;\n\n\tdeleteUnusedData(newData.processes);\n\n\tconsole.log(TAG, 'start');\n\n\tfor (let view of newData.views) {\n\t\tif (view.store) {\n\t\t\tlet {exp, computed} = view.store;\n\t\t\tif (exp) {\n\t\t\t\tview.store.exp = (await compile(exp)).code;\n\t\t\t}\n\t\t\tif (computed) {\n\t\t\t\tfor (let item of computed) {\n\t\t\t\t\tif (item.script) {\n\t\t\t\t\t\titem.script = (await compile(item.script)).code;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tconst {\n\t\tprocessScriptContent,\n\t\tscriptsContent,\n\t\tcustomScriptContent,\n\t} = await divideCode(newData, {\n\t\tdebug,\n\t\tuglify, compile,\n\t\tgetPackages,\n\t\tdependencies: data.dependencies,\n\t});\n\n\treturn {\n\t\tdata: newData,\n\t\tprocessScriptContent,\n\t\tscriptsContent,\n\t\tcustomScriptContent,\n\t};\n}\n\nconst unusedFields = ['design'];\n\nfunction deleteUnusedData(processes) {\n\tfor (let process of processes) {\n\t\tif (process.sub) {\n\t\t\tfor (let uuid in process.sub) {\n\t\t\t\tlet subProcess = process.sub[uuid];\n\t\t\t\tfor (let field of unusedFields) {\n\t\t\t\t\tif (subProcess.hasOwnProperty(field)) {\n\t\t\t\t\t\tdelete subProcess[field];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (process.metas && process.metas.length > 0) {\n\t\t\tdeleteUnusedData(process.metas);\n\t\t}\n\t}\n}\n\nfunction pageTemplate(tpl, options, version, analyseResult, libraryScriptElMap) {\n\tconst params = {\n\t\tversion,\n\t\tlibraries: libraryScriptElMap,\n\t};\n\tfor (let field of replaceFields) {\n\t\tparams[field] = options[field];\n\t}\n\n\toptions.newTpl = fillTemplate(options.tpl, params, analyseResult);\n}\n"],"names":[],"mappings":";;;;;AAAA;;;AAGA,AAGA;AACA,AAAO,eAAe,OAAO,CAAC,MAAM,EAAE,KAAK,GAAG,KAAK,EAAE;CACpD,IAAI,MAAM,GAAG,EAAE,CAAC,eAAe,CAAC,MAAM,EAAE,CAAC,eAAe,EAAE;;GAExD,CAAC,CAAC,CAAC;;CAEL,MAAM,MAAM,GAAG;EACd,IAAI,EAAE,MAAM,CAAC,UAAU;EACvB,CAAC;;;;CAIF,OAAO,MAAM,CAAC;CACd;;AAED,AAAO,SAAS,MAAM,CAAC,MAAM,EAAE;CAC9B,MAAM,YAAY,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;CACjD,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE;EACxB,OAAO,YAAY,CAAC,IAAI,CAAC;EACzB;;;ACzBF;;;;;AAKA,AAIA;AACA,MAAM,aAAa,GAAG,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;AACnD,MAAM,GAAG,GAAG,cAAc,CAAC;;AAE3B,AAAO,eAAe,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE;CACzC,IAAI,YAAY,GAAG,IAA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ACF;;AAED,MAAM,YAAY,GAAG,CAAC,QAAQ,CAAC,CAAC;;AAEhC,SAAS,gBAAgB,CAAC,SAAS,EAAE;CACpC,KAAK,IAAI,OAAO,IAAI,SAAS,EAAE;EAC9B,IAAI,OAAO,CAAC,GAAG,EAAE;GAChB,KAAK,IAAI,IAAI,IAAI,OAAO,CAAC,GAAG,EAAE;IAC7B,IAAI,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACnC,KAAK,IAAI,KAAK,IAAI,YAAY,EAAE;KAC/B,IAAI,UAAU,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE;MACrC,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC;MACzB;KACD;IACD;GACD;EACD,IAAI,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;GAC9C,gBAAgB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;GAChC;EACD;CACD;;AAED,SAAS,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE;CAC/E,MAAM,MAAM,GAAG;EACd,OAAO;EACP,SAAS,EAAE,kBAAkB;EAC7B,CAAC;CACF,KAAK,IAAI,KAAK,IAAI,aAAa,EAAE;EAChC,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;EAC/B;;CAED,OAAO,CAAC,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC;CAClE;;;;"} {"version":3,"file":"index.es.js","sources":["../src/code-process.js","../src/index.js"],"sourcesContent":["/**\n * Created by rockyl on 2019-11-30.\n */\n\nimport ts from 'typescript';\nimport UglifyJS from 'uglify-js';\n\nexport async function compile(source, debug = false) {\n\tlet output = ts.transpileModule(source, {\n\t\tcompilerOptions: {}\n\t});\n\n\tconst result = {\n\t\tcode: output.outputText,\n\t};\n\t/*if (map) {\n\t\tresult.sourcemap = map.mappings;\n\t}*/\n\treturn result;\n}\n\nexport function uglify(source) {\n\tconst uglifyResult = UglifyJS.minify(source, {});\n\tif (uglifyResult.error) {\n\t\tthrow new Error(uglifyResult.error);\n\t} else {\n\t\treturn uglifyResult.code;\n\t}\n}","/**\n * Created by rockyl on 2019-11-13.\n *\n * 项目打包\n */\n\nimport {uglify, compile} from \"./code-process\";\nimport {divideCode} from 'zeroing-code-divider';\nimport {generateLibraryScriptEl, fillTemplate, generateJsScriptEl} from 'zeroing-template-fill';\n\nconst replaceFields = ['pageTitle', 'containerId'];\nconst TAG = 'zeroing-pack';\n\nexport async function pack(data, options) {\n\tlet dependencies = data.dependencies;\n\tlet getPackages = options.getPackages;\n\n\tconst {libraryScriptElMap, analyseResult} = await generateLibraryScriptEl(data.options.tpl, dependencies, getPackages, '//yun.duiba.com.cn/editor/zeroing/libs/');\n\n\tlet version = Date.now() + Math.floor(Math.random() * 1000);\n\tpageTemplate(data, data.options, version, analyseResult, libraryScriptElMap);\n\tconst newData = await packData(data, options);\n\n\treturn {\n\t\tversion,\n\t\tdata: newData,\n\t}\n}\n\nexport function fillTpl(data, params) {\n\tconst {options} = data;\n\tparams.scripts = params.scripts.map(item => generateJsScriptEl(item)).join('\\n');\n\tlet tpl = fillTemplate(options.newTpl, params);\n\n\tdelete options.newTpl;\n\tdelete options.tpl;\n\tdelete options.projectxConfig;\n\tdelete options.pxEnv;\n\n\treturn tpl;\n}\n\nasync function packData(data, {debug, packedAssets, getPackages}) {\n\tlet newData = {};\n\tnewData.options = data.options;\n\tnewData.views = data.views;\n\tnewData.assets = packedAssets || data.assets;\n\tnewData.dataMapping = data.dataMapping;\n\tnewData.processes = data.processes;\n\tnewData.customs = data.customs;\n\n\tdeleteUnusedData(newData.processes);\n\n\tconsole.log(TAG, 'start');\n\n\tfor (let view of newData.views) {\n\t\tif (view.store) {\n\t\t\tlet {exp, computed} = view.store;\n\t\t\tif (exp) {\n\t\t\t\tview.store.exp = (await compile(exp)).code;\n\t\t\t}\n\t\t\tif (computed) {\n\t\t\t\tfor (let item of computed) {\n\t\t\t\t\tif (item.script) {\n\t\t\t\t\t\titem.script = (await compile(item.script)).code;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tconst {\n\t\tprocessScriptContent,\n\t\tscriptsContent,\n\t\tcustomScriptContent,\n\t} = await divideCode(newData, {\n\t\tdebug,\n\t\tuglify, compile,\n\t\tgetPackages,\n\t\tdependencies: data.dependencies,\n\t});\n\n\treturn {\n\t\tdata: newData,\n\t\tprocessScriptContent,\n\t\tscriptsContent,\n\t\tcustomScriptContent,\n\t};\n}\n\nconst unusedFields = ['design'];\n\nfunction deleteUnusedData(processes) {\n\tfor (let process of processes) {\n\t\tif (process.sub) {\n\t\t\tfor (let uuid in process.sub) {\n\t\t\t\tlet subProcess = process.sub[uuid];\n\t\t\t\tfor (let field of unusedFields) {\n\t\t\t\t\tif (subProcess.hasOwnProperty(field)) {\n\t\t\t\t\t\tdelete subProcess[field];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (process.metas && process.metas.length > 0) {\n\t\t\tdeleteUnusedData(process.metas);\n\t\t}\n\t}\n}\n\nfunction pageTemplate(tpl, options, version, analyseResult, libraryScriptElMap) {\n\tconst params = {\n\t\tversion,\n\t\tlibraries: libraryScriptElMap,\n\t};\n\tfor (let field of replaceFields) {\n\t\tparams[field] = options[field];\n\t}\n\n\toptions.newTpl = fillTemplate(options.tpl, params, analyseResult);\n}\n"],"names":[],"mappings":";;;;;AAAA;;;AAGA,AAGA;AACA,AAAO,eAAe,OAAO,CAAC,MAAM,EAAE,KAAK,GAAG,KAAK,EAAE;CACpD,IAAI,MAAM,GAAG,EAAE,CAAC,eAAe,CAAC,MAAM,EAAE;EACvC,eAAe,EAAE,EAAE;EACnB,CAAC,CAAC;;CAEH,MAAM,MAAM,GAAG;EACd,IAAI,EAAE,MAAM,CAAC,UAA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AM,GAAG;EACd,OAAO;EACP,SAAS,EAAE,kBAAkB;EAC7B,CAAC;CACF,KAAK,IAAI,KAAK,IAAI,aAAa,EAAE;EAChC,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;EAC/B;;CAED,OAAO,CAAC,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC;CAClE;;;;"}
\ No newline at end of file \ No newline at end of file
...@@ -14,9 +14,9 @@ var zeroingTemplateFill = require('zeroing-template-fill'); ...@@ -14,9 +14,9 @@ var zeroingTemplateFill = require('zeroing-template-fill');
*/ */
async function compile(source, debug = false) { async function compile(source, debug = false) {
let output = ts.transpileModule(source, {compilerOptions: { let output = ts.transpileModule(source, {
compilerOptions: {}
}}); });
const result = { const result = {
code: output.outputText, code: output.outputText,
...@@ -29,7 +29,9 @@ async function compile(source, debug = false) { ...@@ -29,7 +29,9 @@ async function compile(source, debug = false) {
function uglify(source) { function uglify(source) {
const uglifyResult = UglifyJS.minify(source, {}); const uglifyResult = UglifyJS.minify(source, {});
if (!uglifyResult.error) { if (uglifyResult.error) {
throw new Error(uglifyResult.error);
} else {
return uglifyResult.code; return uglifyResult.code;
} }
} }
......
{"version":3,"file":"index.js","sources":["../src/code-process.js","../src/index.js"],"sourcesContent":["/**\n * Created by rockyl on 2019-11-30.\n */\n\nimport ts from 'typescript';\nimport UglifyJS from 'uglify-js';\n\nexport async function compile(source, debug = false) {\n\tlet output = ts.transpileModule(source, {compilerOptions: {\n\n\t\t}});\n\n\tconst result = {\n\t\tcode: output.outputText,\n\t};\n\t/*if (map) {\n\t\tresult.sourcemap = map.mappings;\n\t}*/\n\treturn result;\n}\n\nexport function uglify(source) {\n\tconst uglifyResult = UglifyJS.minify(source, {});\n\tif (!uglifyResult.error) {\n\t\treturn uglifyResult.code;\n\t}\n}","/**\n * Created by rockyl on 2019-11-13.\n *\n * 项目打包\n */\n\nimport {uglify, compile} from \"./code-process\";\nimport {divideCode} from 'zeroing-code-divider';\nimport {generateLibraryScriptEl, fillTemplate, generateJsScriptEl} from 'zeroing-template-fill';\n\nconst replaceFields = ['pageTitle', 'containerId'];\nconst TAG = 'zeroing-pack';\n\nexport async function pack(data, options) {\n\tlet dependencies = data.dependencies;\n\tlet getPackages = options.getPackages;\n\n\tconst {libraryScriptElMap, analyseResult} = await generateLibraryScriptEl(data.options.tpl, dependencies, getPackages, '//yun.duiba.com.cn/editor/zeroing/libs/');\n\n\tlet version = Date.now() + Math.floor(Math.random() * 1000);\n\tpageTemplate(data, data.options, version, analyseResult, libraryScriptElMap);\n\tconst newData = await packData(data, options);\n\n\treturn {\n\t\tversion,\n\t\tdata: newData,\n\t}\n}\n\nexport function fillTpl(data, params) {\n\tconst {options} = data;\n\tparams.scripts = params.scripts.map(item => generateJsScriptEl(item)).join('\\n');\n\tlet tpl = fillTemplate(options.newTpl, params);\n\n\tdelete options.newTpl;\n\tdelete options.tpl;\n\tdelete options.projectxConfig;\n\tdelete options.pxEnv;\n\n\treturn tpl;\n}\n\nasync function packData(data, {debug, packedAssets, getPackages}) {\n\tlet newData = {};\n\tnewData.options = data.options;\n\tnewData.views = data.views;\n\tnewData.assets = packedAssets || data.assets;\n\tnewData.dataMapping = data.dataMapping;\n\tnewData.processes = data.processes;\n\tnewData.customs = data.customs;\n\n\tdeleteUnusedData(newData.processes);\n\n\tconsole.log(TAG, 'start');\n\n\tfor (let view of newData.views) {\n\t\tif (view.store) {\n\t\t\tlet {exp, computed} = view.store;\n\t\t\tif (exp) {\n\t\t\t\tview.store.exp = (await compile(exp)).code;\n\t\t\t}\n\t\t\tif (computed) {\n\t\t\t\tfor (let item of computed) {\n\t\t\t\t\tif (item.script) {\n\t\t\t\t\t\titem.script = (await compile(item.script)).code;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tconst {\n\t\tprocessScriptContent,\n\t\tscriptsContent,\n\t\tcustomScriptContent,\n\t} = await divideCode(newData, {\n\t\tdebug,\n\t\tuglify, compile,\n\t\tgetPackages,\n\t\tdependencies: data.dependencies,\n\t});\n\n\treturn {\n\t\tdata: newData,\n\t\tprocessScriptContent,\n\t\tscriptsContent,\n\t\tcustomScriptContent,\n\t};\n}\n\nconst unusedFields = ['design'];\n\nfunction deleteUnusedData(processes) {\n\tfor (let process of processes) {\n\t\tif (process.sub) {\n\t\t\tfor (let uuid in process.sub) {\n\t\t\t\tlet subProcess = process.sub[uuid];\n\t\t\t\tfor (let field of unusedFields) {\n\t\t\t\t\tif (subProcess.hasOwnProperty(field)) {\n\t\t\t\t\t\tdelete subProcess[field];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (process.metas && process.metas.length > 0) {\n\t\t\tdeleteUnusedData(process.metas);\n\t\t}\n\t}\n}\n\nfunction pageTemplate(tpl, options, version, analyseResult, libraryScriptElMap) {\n\tconst params = {\n\t\tversion,\n\t\tlibraries: libraryScriptElMap,\n\t};\n\tfor (let field of replaceFields) {\n\t\tparams[field] = options[field];\n\t}\n\n\toptions.newTpl = fillTemplate(options.tpl, params, analyseResult);\n}\n"],"names":["generateLibraryScriptEl","generateJsScriptEl","fillTemplate","divideCode"],"mappings":";;;;;;;;;;;AAAA;;;AAGA,AAGA;AACA,AAAO,eAAe,OAAO,CAAC,MAAM,EAAE,KAAK,GAAG,KAAK,EAAE;CACpD,IAAI,MAAM,GAAG,EAAE,CAAC,eAAe,CAAC,MAAM,EAAE,CAAC,eAAe,EAAE;;GAExD,CAAC,CAAC,CAAC;;CAEL,MAAM,MAAM,GAAG;EACd,IAAI,EAAE,MAAM,CAAC,UAAU;EACvB,CAAC;;;;CAIF,OAAO,MAAM,CAAC;CACd;;AAED,AAAO,SAAS,MAAM,CAAC,MAAM,EAAE;CAC9B,MAAM,YAAY,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;CACjD,IAAI,CAAC,YAAY,CA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aAAa,CAAC,CAAC;CAClE;;;;;"} {"version":3,"file":"index.js","sources":["../src/code-process.js","../src/index.js"],"sourcesContent":["/**\n * Created by rockyl on 2019-11-30.\n */\n\nimport ts from 'typescript';\nimport UglifyJS from 'uglify-js';\n\nexport async function compile(source, debug = false) {\n\tlet output = ts.transpileModule(source, {\n\t\tcompilerOptions: {}\n\t});\n\n\tconst result = {\n\t\tcode: output.outputText,\n\t};\n\t/*if (map) {\n\t\tresult.sourcemap = map.mappings;\n\t}*/\n\treturn result;\n}\n\nexport function uglify(source) {\n\tconst uglifyResult = UglifyJS.minify(source, {});\n\tif (uglifyResult.error) {\n\t\tthrow new Error(uglifyResult.error);\n\t} else {\n\t\treturn uglifyResult.code;\n\t}\n}","/**\n * Created by rockyl on 2019-11-13.\n *\n * 项目打包\n */\n\nimport {uglify, compile} from \"./code-process\";\nimport {divideCode} from 'zeroing-code-divider';\nimport {generateLibraryScriptEl, fillTemplate, generateJsScriptEl} from 'zeroing-template-fill';\n\nconst replaceFields = ['pageTitle', 'containerId'];\nconst TAG = 'zeroing-pack';\n\nexport async function pack(data, options) {\n\tlet dependencies = data.dependencies;\n\tlet getPackages = options.getPackages;\n\n\tconst {libraryScriptElMap, analyseResult} = await generateLibraryScriptEl(data.options.tpl, dependencies, getPackages, '//yun.duiba.com.cn/editor/zeroing/libs/');\n\n\tlet version = Date.now() + Math.floor(Math.random() * 1000);\n\tpageTemplate(data, data.options, version, analyseResult, libraryScriptElMap);\n\tconst newData = await packData(data, options);\n\n\treturn {\n\t\tversion,\n\t\tdata: newData,\n\t}\n}\n\nexport function fillTpl(data, params) {\n\tconst {options} = data;\n\tparams.scripts = params.scripts.map(item => generateJsScriptEl(item)).join('\\n');\n\tlet tpl = fillTemplate(options.newTpl, params);\n\n\tdelete options.newTpl;\n\tdelete options.tpl;\n\tdelete options.projectxConfig;\n\tdelete options.pxEnv;\n\n\treturn tpl;\n}\n\nasync function packData(data, {debug, packedAssets, getPackages}) {\n\tlet newData = {};\n\tnewData.options = data.options;\n\tnewData.views = data.views;\n\tnewData.assets = packedAssets || data.assets;\n\tnewData.dataMapping = data.dataMapping;\n\tnewData.processes = data.processes;\n\tnewData.customs = data.customs;\n\n\tdeleteUnusedData(newData.processes);\n\n\tconsole.log(TAG, 'start');\n\n\tfor (let view of newData.views) {\n\t\tif (view.store) {\n\t\t\tlet {exp, computed} = view.store;\n\t\t\tif (exp) {\n\t\t\t\tview.store.exp = (await compile(exp)).code;\n\t\t\t}\n\t\t\tif (computed) {\n\t\t\t\tfor (let item of computed) {\n\t\t\t\t\tif (item.script) {\n\t\t\t\t\t\titem.script = (await compile(item.script)).code;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tconst {\n\t\tprocessScriptContent,\n\t\tscriptsContent,\n\t\tcustomScriptContent,\n\t} = await divideCode(newData, {\n\t\tdebug,\n\t\tuglify, compile,\n\t\tgetPackages,\n\t\tdependencies: data.dependencies,\n\t});\n\n\treturn {\n\t\tdata: newData,\n\t\tprocessScriptContent,\n\t\tscriptsContent,\n\t\tcustomScriptContent,\n\t};\n}\n\nconst unusedFields = ['design'];\n\nfunction deleteUnusedData(processes) {\n\tfor (let process of processes) {\n\t\tif (process.sub) {\n\t\t\tfor (let uuid in process.sub) {\n\t\t\t\tlet subProcess = process.sub[uuid];\n\t\t\t\tfor (let field of unusedFields) {\n\t\t\t\t\tif (subProcess.hasOwnProperty(field)) {\n\t\t\t\t\t\tdelete subProcess[field];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (process.metas && process.metas.length > 0) {\n\t\t\tdeleteUnusedData(process.metas);\n\t\t}\n\t}\n}\n\nfunction pageTemplate(tpl, options, version, analyseResult, libraryScriptElMap) {\n\tconst params = {\n\t\tversion,\n\t\tlibraries: libraryScriptElMap,\n\t};\n\tfor (let field of replaceFields) {\n\t\tparams[field] = options[field];\n\t}\n\n\toptions.newTpl = fillTemplate(options.tpl, params, analyseResult);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CAAC,EAAE;MACrC,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC;MACzB;KACD;IACD;GACD;EACD,IAAI,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;GAC9C,gBAAgB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;GAChC;EACD;CACD;;AAED,SAAS,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE;CAC/E,MAAM,MAAM,GAAG;EACd,OAAO;EACP,SAAS,EAAE,kBAAkB;EAC7B,CAAC;CACF,KAAK,IAAI,KAAK,IAAI,aAAa,EAAE;EAChC,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;EAC/B;;CAED,OAAO,CAAC,MAAM,GAAGD,gCAAY,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC;CAClE;;;;;"}
\ No newline at end of file \ No newline at end of file
...@@ -12,9 +12,9 @@ ...@@ -12,9 +12,9 @@
*/ */
async function compile(source, debug = false) { async function compile(source, debug = false) {
let output = ts.transpileModule(source, {compilerOptions: { let output = ts.transpileModule(source, {
compilerOptions: {}
}}); });
const result = { const result = {
code: output.outputText, code: output.outputText,
...@@ -27,7 +27,9 @@ ...@@ -27,7 +27,9 @@
function uglify(source) { function uglify(source) {
const uglifyResult = UglifyJS.minify(source, {}); const uglifyResult = UglifyJS.minify(source, {});
if (!uglifyResult.error) { if (uglifyResult.error) {
throw new Error(uglifyResult.error);
} else {
return uglifyResult.code; return uglifyResult.code;
} }
} }
......
{"version":3,"file":"index.umd.js","sources":["../src/code-process.js","../src/index.js"],"sourcesContent":["/**\n * Created by rockyl on 2019-11-30.\n */\n\nimport ts from 'typescript';\nimport UglifyJS from 'uglify-js';\n\nexport async function compile(source, debug = false) {\n\tlet output = ts.transpileModule(source, {compilerOptions: {\n\n\t\t}});\n\n\tconst result = {\n\t\tcode: output.outputText,\n\t};\n\t/*if (map) {\n\t\tresult.sourcemap = map.mappings;\n\t}*/\n\treturn result;\n}\n\nexport function uglify(source) {\n\tconst uglifyResult = UglifyJS.minify(source, {});\n\tif (!uglifyResult.error) {\n\t\treturn uglifyResult.code;\n\t}\n}","/**\n * Created by rockyl on 2019-11-13.\n *\n * 项目打包\n */\n\nimport {uglify, compile} from \"./code-process\";\nimport {divideCode} from 'zeroing-code-divider';\nimport {generateLibraryScriptEl, fillTemplate, generateJsScriptEl} from 'zeroing-template-fill';\n\nconst replaceFields = ['pageTitle', 'containerId'];\nconst TAG = 'zeroing-pack';\n\nexport async function pack(data, options) {\n\tlet dependencies = data.dependencies;\n\tlet getPackages = options.getPackages;\n\n\tconst {libraryScriptElMap, analyseResult} = await generateLibraryScriptEl(data.options.tpl, dependencies, getPackages, '//yun.duiba.com.cn/editor/zeroing/libs/');\n\n\tlet version = Date.now() + Math.floor(Math.random() * 1000);\n\tpageTemplate(data, data.options, version, analyseResult, libraryScriptElMap);\n\tconst newData = await packData(data, options);\n\n\treturn {\n\t\tversion,\n\t\tdata: newData,\n\t}\n}\n\nexport function fillTpl(data, params) {\n\tconst {options} = data;\n\tparams.scripts = params.scripts.map(item => generateJsScriptEl(item)).join('\\n');\n\tlet tpl = fillTemplate(options.newTpl, params);\n\n\tdelete options.newTpl;\n\tdelete options.tpl;\n\tdelete options.projectxConfig;\n\tdelete options.pxEnv;\n\n\treturn tpl;\n}\n\nasync function packData(data, {debug, packedAssets, getPackages}) {\n\tlet newData = {};\n\tnewData.options = data.options;\n\tnewData.views = data.views;\n\tnewData.assets = packedAssets || data.assets;\n\tnewData.dataMapping = data.dataMapping;\n\tnewData.processes = data.processes;\n\tnewData.customs = data.customs;\n\n\tdeleteUnusedData(newData.processes);\n\n\tconsole.log(TAG, 'start');\n\n\tfor (let view of newData.views) {\n\t\tif (view.store) {\n\t\t\tlet {exp, computed} = view.store;\n\t\t\tif (exp) {\n\t\t\t\tview.store.exp = (await compile(exp)).code;\n\t\t\t}\n\t\t\tif (computed) {\n\t\t\t\tfor (let item of computed) {\n\t\t\t\t\tif (item.script) {\n\t\t\t\t\t\titem.script = (await compile(item.script)).code;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tconst {\n\t\tprocessScriptContent,\n\t\tscriptsContent,\n\t\tcustomScriptContent,\n\t} = await divideCode(newData, {\n\t\tdebug,\n\t\tuglify, compile,\n\t\tgetPackages,\n\t\tdependencies: data.dependencies,\n\t});\n\n\treturn {\n\t\tdata: newData,\n\t\tprocessScriptContent,\n\t\tscriptsContent,\n\t\tcustomScriptContent,\n\t};\n}\n\nconst unusedFields = ['design'];\n\nfunction deleteUnusedData(processes) {\n\tfor (let process of processes) {\n\t\tif (process.sub) {\n\t\t\tfor (let uuid in process.sub) {\n\t\t\t\tlet subProcess = process.sub[uuid];\n\t\t\t\tfor (let field of unusedFields) {\n\t\t\t\t\tif (subProcess.hasOwnProperty(field)) {\n\t\t\t\t\t\tdelete subProcess[field];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (process.metas && process.metas.length > 0) {\n\t\t\tdeleteUnusedData(process.metas);\n\t\t}\n\t}\n}\n\nfunction pageTemplate(tpl, options, version, analyseResult, libraryScriptElMap) {\n\tconst params = {\n\t\tversion,\n\t\tlibraries: libraryScriptElMap,\n\t};\n\tfor (let field of replaceFields) {\n\t\tparams[field] = options[field];\n\t}\n\n\toptions.newTpl = fillTemplate(options.tpl, params, analyseResult);\n}\n"],"names":["generateLibraryScriptEl","generateJsScriptEl","fillTemplate","divideCode"],"mappings":";;;;;;;;;CAAA;CACA;CACA;AACA,AAGA;AACA,CAAO,eAAe,OAAO,CAAC,MAAM,EAAE,KAAK,GAAG,KAAK,EAAE;CACrD,CAAC,IAAI,MAAM,GAAG,EAAE,CAAC,eAAe,CAAC,MAAM,EAAE,CAAC,eAAe,EAAE;;CAE3D,GAAG,CAAC,CAAC,C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AAE;CACjC,IAAI,IAAI,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;CACvC,IAAI,KAAK,IAAI,KAAK,IAAI,YAAY,EAAE;CACpC,KAAK,IAAI,UAAU,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE;CAC3C,MAAM,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC;CAC/B,MAAM;CACN,KAAK;CACL,IAAI;CACJ,GAAG;CACH,EAAE,IAAI,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;CACjD,GAAG,gBAAgB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;CACnC,GAAG;CACH,EAAE;CACF,CAAC;;CAED,SAAS,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE;CAChF,CAAC,MAAM,MAAM,GAAG;CAChB,EAAE,OAAO;CACT,EAAE,SAAS,EAAE,kBAAkB;CAC/B,EAAE,CAAC;CACH,CAAC,KAAK,IAAI,KAAK,IAAI,aAAa,EAAE;CAClC,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;CACjC,EAAE;;CAEF,CAAC,OAAO,CAAC,MAAM,GAAGD,gCAAY,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC;CACnE,CAAC;;;;;;;;;;;;;"} {"version":3,"file":"index.umd.js","sources":["../src/code-process.js","../src/index.js"],"sourcesContent":["/**\n * Created by rockyl on 2019-11-30.\n */\n\nimport ts from 'typescript';\nimport UglifyJS from 'uglify-js';\n\nexport async function compile(source, debug = false) {\n\tlet output = ts.transpileModule(source, {\n\t\tcompilerOptions: {}\n\t});\n\n\tconst result = {\n\t\tcode: output.outputText,\n\t};\n\t/*if (map) {\n\t\tresult.sourcemap = map.mappings;\n\t}*/\n\treturn result;\n}\n\nexport function uglify(source) {\n\tconst uglifyResult = UglifyJS.minify(source, {});\n\tif (uglifyResult.error) {\n\t\tthrow new Error(uglifyResult.error);\n\t} else {\n\t\treturn uglifyResult.code;\n\t}\n}","/**\n * Created by rockyl on 2019-11-13.\n *\n * 项目打包\n */\n\nimport {uglify, compile} from \"./code-process\";\nimport {divideCode} from 'zeroing-code-divider';\nimport {generateLibraryScriptEl, fillTemplate, generateJsScriptEl} from 'zeroing-template-fill';\n\nconst replaceFields = ['pageTitle', 'containerId'];\nconst TAG = 'zeroing-pack';\n\nexport async function pack(data, options) {\n\tlet dependencies = data.dependencies;\n\tlet getPackages = options.getPackages;\n\n\tconst {libraryScriptElMap, analyseResult} = await generateLibraryScriptEl(data.options.tpl, dependencies, getPackages, '//yun.duiba.com.cn/editor/zeroing/libs/');\n\n\tlet version = Date.now() + Math.floor(Math.random() * 1000);\n\tpageTemplate(data, data.options, version, analyseResult, libraryScriptElMap);\n\tconst newData = await packData(data, options);\n\n\treturn {\n\t\tversion,\n\t\tdata: newData,\n\t}\n}\n\nexport function fillTpl(data, params) {\n\tconst {options} = data;\n\tparams.scripts = params.scripts.map(item => generateJsScriptEl(item)).join('\\n');\n\tlet tpl = fillTemplate(options.newTpl, params);\n\n\tdelete options.newTpl;\n\tdelete options.tpl;\n\tdelete options.projectxConfig;\n\tdelete options.pxEnv;\n\n\treturn tpl;\n}\n\nasync function packData(data, {debug, packedAssets, getPackages}) {\n\tlet newData = {};\n\tnewData.options = data.options;\n\tnewData.views = data.views;\n\tnewData.assets = packedAssets || data.assets;\n\tnewData.dataMapping = data.dataMapping;\n\tnewData.processes = data.processes;\n\tnewData.customs = data.customs;\n\n\tdeleteUnusedData(newData.processes);\n\n\tconsole.log(TAG, 'start');\n\n\tfor (let view of newData.views) {\n\t\tif (view.store) {\n\t\t\tlet {exp, computed} = view.store;\n\t\t\tif (exp) {\n\t\t\t\tview.store.exp = (await compile(exp)).code;\n\t\t\t}\n\t\t\tif (computed) {\n\t\t\t\tfor (let item of computed) {\n\t\t\t\t\tif (item.script) {\n\t\t\t\t\t\titem.script = (await compile(item.script)).code;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tconst {\n\t\tprocessScriptContent,\n\t\tscriptsContent,\n\t\tcustomScriptContent,\n\t} = await divideCode(newData, {\n\t\tdebug,\n\t\tuglify, compile,\n\t\tgetPackages,\n\t\tdependencies: data.dependencies,\n\t});\n\n\treturn {\n\t\tdata: newData,\n\t\tprocessScriptContent,\n\t\tscriptsContent,\n\t\tcustomScriptContent,\n\t};\n}\n\nconst unusedFields = ['design'];\n\nfunction deleteUnusedData(processes) {\n\tfor (let process of processes) {\n\t\tif (process.sub) {\n\t\t\tfor (let uuid in process.sub) {\n\t\t\t\tlet subProcess = process.sub[uuid];\n\t\t\t\tfor (let field of unusedFields) {\n\t\t\t\t\tif (subProcess.hasOwnProperty(field)) {\n\t\t\t\t\t\tdelete subProcess[field];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (process.metas && process.metas.length > 0) {\n\t\t\tdeleteUnusedData(process.metas);\n\t\t}\n\t}\n}\n\nfunction pageTemplate(tpl, options, version, analyseResult, libraryScriptElMap) {\n\tconst params = {\n\t\tversion,\n\t\tlibraries: libraryScriptElMap,\n\t};\n\tfor (let field of replaceFields) {\n\t\tparams[field] = options[field];\n\t}\n\n\toptions.newTpl = fillTemplate(options.tpl, params, analyseResult);\n}\n"],"names":["generateLibraryScriptEl","generateJsScriptEl","fillTemplate","divideCode"],"mappings":";;;;;;;;;CAAA;CACA;CACA;AACA,AAGA;AACA,CAAO,eAAe,OAAO,CAAC,MAAM,EAAE,KAAK,GAAG,KAAK,EAAE;CACrD,CAAC,IAAI,MAAM,GAAG,EAAE,CAAC,eAAe,CAAC,MAAM,EAAE;CACzC,EAAE,eAAe,EAAE,EAAE;CACrB,EAAE,CAAC,CAAC;;CAEJ,CAAC,MAAM,MAAM,GAAG;CAChB,EAAE,IAAI,EAAE,MAAM,C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,GAAG,EAAE;CACjC,IAAI,IAAI,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;CACvC,IAAI,KAAK,IAAI,KAAK,IAAI,YAAY,EAAE;CACpC,KAAK,IAAI,UAAU,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE;CAC3C,MAAM,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC;CAC/B,MAAM;CACN,KAAK;CACL,IAAI;CACJ,GAAG;CACH,EAAE,IAAI,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;CACjD,GAAG,gBAAgB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;CACnC,GAAG;CACH,EAAE;CACF,CAAC;;CAED,SAAS,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE;CAChF,CAAC,MAAM,MAAM,GAAG;CAChB,EAAE,OAAO;CACT,EAAE,SAAS,EAAE,kBAAkB;CAC/B,EAAE,CAAC;CACH,CAAC,KAAK,IAAI,KAAK,IAAI,aAAa,EAAE;CAClC,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;CACjC,EAAE;;CAEF,CAAC,OAAO,CAAC,MAAM,GAAGD,gCAAY,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC;CACnE,CAAC;;;;;;;;;;;;;"}
\ No newline at end of file \ No newline at end of file
...@@ -6,9 +6,9 @@ import ts from 'typescript'; ...@@ -6,9 +6,9 @@ import ts from 'typescript';
import UglifyJS from 'uglify-js'; import UglifyJS from 'uglify-js';
export async function compile(source, debug = false) { export async function compile(source, debug = false) {
let output = ts.transpileModule(source, {compilerOptions: { let output = ts.transpileModule(source, {
compilerOptions: {}
}}); });
const result = { const result = {
code: output.outputText, code: output.outputText,
...@@ -21,7 +21,9 @@ export async function compile(source, debug = false) { ...@@ -21,7 +21,9 @@ export async function compile(source, debug = false) {
export function uglify(source) { export function uglify(source) {
const uglifyResult = UglifyJS.minify(source, {}); const uglifyResult = UglifyJS.minify(source, {});
if (!uglifyResult.error) { if (uglifyResult.error) {
throw new Error(uglifyResult.error);
} else {
return uglifyResult.code; return uglifyResult.code;
} }
} }
\ 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