Commit 2ab6ba47 authored by rockyl's avatar rockyl

增加zeroing-template-fill

parent 0cb1266f
......@@ -188,12 +188,23 @@ ${scripts}
* Created by rockyl on 2019-12-20.
*/
async function divideCode(data, {debug, compile, uglify, getPackages}) {
async function divideCode(data, {debug, compile, uglify, getPackages, dependencies}) {
const processManager = new ProcessManager();
const scriptManager = new ScriptManager();
const customManager = new CustomManager();
const dependencies = data.dependencies;
async function getPackagesTrans(schema, type) {
let packages = await getPackages(schema, type);
let packageDatas = [];
for (let packageItem of packages) {
let data = packageItem.data;
if (typeof packageItem.data === 'string') {
data = JSON.parse(data);
}
packageDatas.push(data);
}
return packageDatas;
}
/*=====START process =====*/
//console.log(TAG, 'start process');
......@@ -203,7 +214,7 @@ async function divideCode(data, {debug, compile, uglify, getPackages}) {
let bProcessIDs = processIDs;
while (true) {
let newPids = await addBuiltinProcesses(builtinProcesses, bProcessIDs, getPackages, dependencies);
let newPids = await addBuiltinProcesses(builtinProcesses, bProcessIDs, getPackagesTrans, dependencies);
bProcessIDs = [];
for (let id of newPids) {
if (!processIDs.includes(id)) {
......@@ -257,7 +268,8 @@ async function divideCode(data, {debug, compile, uglify, getPackages}) {
//let scriptsContainer = data.scripts = {};
//let scriptsCode = '';
if (scriptIDs.length > 0) {
const scripts = await getPackages(scriptIDs);
let schema = idsToSchema(scriptIDs, dependencies);
const scripts = await getPackagesTrans(schema, 2);
for (let scriptData of scripts) {
let script = typeof scriptData === 'string' ? JSON.parse(scriptData) : scriptData;
//scriptsContainer[id] = code;
......@@ -278,7 +290,8 @@ async function divideCode(data, {debug, compile, uglify, getPackages}) {
//data.customs = [];
const customs = data.customs;
if (customs && customs.length > 0) {
let customMetas = await getPackages(customs.map(item => item.id));
let schema = idsToSchema(customs.map(item => item.id), dependencies);
let customMetas = await getPackagesTrans(schema, 3);
data.customs = customMetas.map(item => {
const custom = typeof item === 'string' ? JSON.parse(item) : item;
customManager.deal(custom);
......@@ -339,14 +352,11 @@ function findDepPidsBat(list, processes) {
}
}
async function addBuiltinProcesses(list, ids, getPackages, dependencies) {
async function addBuiltinProcesses(list, ids, getPackagesTrans, dependencies) {
let newPids = [];
let schema = {};
if (ids.length > 0) {
for(let id of ids){
schema[id] = dependencies[id];
}
let processes = await getPackages(schema);
let schema = idsToSchema(ids, dependencies);
let processes = await getPackagesTrans(schema, 1);
for (let processData of processes) {
let process = typeof processData === 'string' ? JSON.parse(processData) : processData;
list.push(process);
......@@ -365,5 +375,17 @@ function traverseNode(root, callback) {
}
}
function idsToSchema(ids, dependencies){
if(ids.length > 0){
let schema = {};
for (let id of ids) {
if(dependencies[id]){
schema[id] = dependencies[id];
}
}
return schema;
}
}
export { divideCode };
//# sourceMappingURL=index.es.js.map
{"version":3,"file":"index.es.js","sources":["../src/ProcessManager.js","../src/ScriptManager.js","../src/CustomManager.js","../src/main.js"],"sourcesContent":["/**\n * Created by rockyl on 2019-11-29.\n */\n\nimport crypto from 'crypto'\n\nfunction md5(source) {\n\tconst hash = crypto.createHash('md5');\n\treturn hash.update(source).digest('hex');\n}\n\nexport default class ProcessManager {\n\tconstructor() {\n\t\tthis.pool = {};\n\t\tthis.scripts = '';\n\t}\n\n\tdeal(process) {\n\t\tlet hash = this.put(process);\n\t\tif (hash) {\n\t\t\tprocess.script = 'link://' + hash;\n\t\t}\n\t\tif (process.metas) {\n\t\t\tfor (let subProcess of process.metas) {\n\t\t\t\tthis.deal(subProcess);\n\t\t\t}\n\t\t}\n\t}\n\n\tput(process) {\n\t\tconst {id, name, script} = process;\n\t\tif (script) {\n\t\t\tlet hash = md5(script);\n\t\t\tif (!this.pool.hasOwnProperty(hash)) {\n\t\t\t\tthis.pool[hash] = {\n\t\t\t\t\tscript,\n\t\t\t\t\tids: [],\n\t\t\t\t};\n\t\t\t}\n\t\t\tthis.pool[hash].ids.push(`${id} - ${name}`);\n\t\t\treturn hash;\n\t\t}\n\t}\n\n\tgenerateCurrent() {\n\t\tlet scripts = '';\n\t\tfor (let hash in this.pool) {\n\t\t\tlet {script, ids} = this.pool[hash];\n\t\t\tlet idsComment = ids.map(id => {\n\t\t\t\treturn `/*== ${id} ==*/`\n\t\t\t}).join('\\n');\n\t\t\tscripts += `\n\texports['${hash}'] = function(args, props, target, global, vm, scope){\n\t\treturn new Promise(function(resolve, reject){\n\n${idsComment}\n${script}\n\n\t\tfunction next(type, payload){resolve({type: type, payload: payload})}\n\t\t});\n\t};\n`;\n\t\t}\n\t\tthis.scripts += scripts;\n\t\tthis.pool = {};\n\n\t\treturn scripts;\n\t}\n\n\tcoverScripts(scripts) {\n\t\tthis.scripts = scripts;\n\t}\n\n\tgenerate() {\n\t\tthis.generateCurrent();\n\t\tlet scripts = this.scripts;\n\n\t\treturn `\nconsole.log('processes.js loaded');\n\n(function(){\nvar exports = {};\n${scripts}\n\n\tengine.setScriptMap(exports);\n})();\n`\n\t}\n}\n","/**\n * Created by rockyl on 2019-11-29.\n */\n\nexport default class ScriptManager {\n\tconstructor() {\n\t\tthis.pool = [];\n\t}\n\n\tdeal(script){\n\t\tthis.pool.push(script);\n\t}\n\n\tgenerate(){\n\t\tlet scripts = '';\n\t\tfor(let {id, code} of this.pool){\n\t\t\tscripts += `\n/*=====START ${id} START=====*/\n(function(exports){\n${code}\n})(exports);\n\tengine.registerScriptDef(exports.default.id, exports.default);\n/*=====END ${id} END=====*/`;\n\t\t}\n\n\t\treturn `\nconsole.log('scripts.js loaded');\n\n(function(){\nvar exports = {};\n${scripts}\n})();\n`;\n\t}\n}\n","/**\n * Created by rockyl on 2019-11-29.\n */\n\nexport default class CustomManager {\n\tconstructor() {\n\t\tthis.pool = [];\n\t}\n\n\tdeal(custom) {\n\t\tthis.pool.push(custom);\n\t}\n\n\tgenerate() {\n\t\tlet scripts = '';\n\t\tfor (let {id, code} of this.pool) {\n\t\t\tscripts += `\n/*=====START ${id} START=====*/\nvar module = {\n\texports: {}\n};\n(function(module){\nfunction getAssetByUUID(uuid){\n\treturn engine.resolveCustomAsset('${id}', uuid);\n}\nfunction getProps(){\n\treturn engine.getProps('${id}');\n}\n\n${code}\n})(module);\nexports['${id}'] = module.exports;\n/*=====END ${id} END=====*/`;\n\t\t}\n\n\t\treturn `\nconsole.log('customs.js loaded');\n\n(function(){\nvar exports = {};\n\nfunction require(id){\n\tif(id === 'tslib'){\n\t\treturn window['tslib']\t\n\t}else{\n\t\tconsole.log('missing require', id);\n\t}\n}\n\n${scripts}\n\n\tfor(var key in exports){\n\t\tengine.registerCustomModule(key, exports[key]);\n\t}\n})();\n`\n\t}\n}\n","/**\n * Created by rockyl on 2019-12-20.\n */\n\nimport ProcessManager from \"./ProcessManager\";\nimport ScriptManager from \"./ScriptManager\";\nimport CustomManager from \"./CustomManager\";\nimport {compute} from \"props-compute\";\n\nconst TAG = 'zeroing-code-divider';\n\nexport async function divideCode(data, {debug, compile, uglify, getPackages}) {\n\tconst processManager = new ProcessManager();\n\tconst scriptManager = new ScriptManager();\n\tconst customManager = new CustomManager();\n\n\tconst dependencies = data.dependencies;\n\n\t/*=====START process =====*/\n\t//console.log(TAG, 'start process');\n\tlet processIDs = [];\n\tfindDepPidsBat(processIDs, data.processes);\n\tlet builtinProcesses = data.builtinProcesses = [];\n\n\tlet bProcessIDs = processIDs;\n\twhile (true) {\n\t\tlet newPids = await addBuiltinProcesses(builtinProcesses, bProcessIDs, getPackages, dependencies);\n\t\tbProcessIDs = [];\n\t\tfor (let id of newPids) {\n\t\t\tif (!processIDs.includes(id)) {\n\t\t\t\tbProcessIDs.push(id);\n\t\t\t\tprocessIDs.push(id);\n\t\t\t}\n\t\t}\n\t\tif (bProcessIDs.length === 0) {\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tfor (let process of data.processes) {\n\t\tprocessManager.deal(process);\n\t}\n\n\t//console.log(TAG, 'processManager.generateCurrent()');\n\n\tlet ptScript = processManager.generateCurrent();\n\tif (compile) {\n\t\tconst result = await compile(ptScript);\n\t\tprocessManager.coverScripts(result.code); //自定义过程先编译\n\t}\n\n\tfor (let process of builtinProcesses) {\n\t\tprocessManager.deal(process);\n\t}\n\n\tlet processScriptContent = processManager.generate();\n\t//console.log(processScriptContent);\n\tif (!debug) {\n\t\tprocessScriptContent = uglify(processScriptContent);\n\t}\n\t/*=====END process =====*/\n\n\t/*=====START script =====*/\n\t//console.log(TAG, 'start script');\n\tlet scriptIDs = [];\n\tfor (let view of data.views) {\n\t\ttraverseNode(view, (node) => {\n\t\t\tif (node.scripts && node.scripts.length > 0) {\n\t\t\t\tfor (let {script} of node.scripts) {\n\t\t\t\t\tif (!scriptIDs.includes(script)) {\n\t\t\t\t\t\tscriptIDs.push(script);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\t//console.log('scriptIDs:', scriptIDs);\n\t//let scriptsContainer = data.scripts = {};\n\t//let scriptsCode = '';\n\tif (scriptIDs.length > 0) {\n\t\tconst scripts = await getPackages(scriptIDs);\n\t\tfor (let scriptData of scripts) {\n\t\t\tlet script = typeof scriptData === 'string' ? JSON.parse(scriptData) : scriptData;\n\t\t\t//scriptsContainer[id] = code;\n\t\t\tscriptManager.deal(script);\n\t\t}\n\t\t//console.log('scripts:', scriptsContainer);\n\t}\n\n\tlet scriptsContent = scriptManager.generate();\n\t//console.log(scriptsContent);\n\tif (!debug) {\n\t\tscriptsContent = uglify(scriptsContent);\n\t}\n\t/*=====END script =====*/\n\n\t/*=====START custom =====*/\n\t//console.log(TAG, 'start custom');\n\t//data.customs = [];\n\tconst customs = data.customs;\n\tif (customs && customs.length > 0) {\n\t\tlet customMetas = await getPackages(customs.map(item => item.id));\n\t\tdata.customs = customMetas.map(item => {\n\t\t\tconst custom = typeof item === 'string' ? JSON.parse(item) : item;\n\t\t\tcustomManager.deal(custom);\n\t\t\tlet {props, assetMapping} = customs.find(c => c.id === custom.id);\n\t\t\t/*if (props) {\n\t\t\t\tfor (let key in custom.props) {\n\t\t\t\t\tif (!props.hasOwnProperty(key) && custom.props[key].hasOwnProperty('default')) {\n\t\t\t\t\t\tprops[key] = custom.props[key].default;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}*/\n\t\t\tcompute(props, custom.props);\n\t\t\tfor (let uuid in assetMapping) {\n\t\t\t\tlet asset = custom.assets.find(item => item.uuid === uuid);\n\t\t\t\tif (asset) {\n\t\t\t\t\tasset.url = assetMapping[uuid];\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tid: custom.id,\n\t\t\t\tname: custom.name,\n\t\t\t\tassets: custom.assets,\n\t\t\t\tprops,\n\t\t\t};\n\t\t})\n\t}\n\tlet customScriptContent = customManager.generate();\n\t//console.log(customScriptContent);\n\tif (!debug) {\n\t\tcustomScriptContent = uglify(customScriptContent);\n\t}\n\t/*=====END custom =====*/\n\n\treturn {\n\t\tprocessScriptContent,\n\t\tscriptsContent,\n\t\tcustomScriptContent,\n\t}\n}\n\nfunction findDepPids(list, process) {\n\tif (process.sub) {\n\t\tfor (let key in process.sub) {\n\t\t\tlet p = process.sub[key];\n\t\t\tif (!list.includes(p.meta)) {\n\t\t\t\tlist.push(p.meta);\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction findDepPidsBat(list, processes) {\n\tfor (let process of processes) {\n\t\tfindDepPids(list, process);\n\t\tif (process.metas) {\n\t\t\tfindDepPidsBat(list, process.metas)\n\t\t}\n\t}\n}\n\nasync function addBuiltinProcesses(list, ids, getPackages, dependencies) {\n\tlet newPids = [];\n\tlet schema = {};\n\tif (ids.length > 0) {\n\t\tfor(let id of ids){\n\t\t\tschema[id] = dependencies[id];\n\t\t}\n\t\tlet processes = await getPackages(schema);\n\t\tfor (let processData of processes) {\n\t\t\tlet process = typeof processData === 'string' ? JSON.parse(processData) : processData;\n\t\t\tlist.push(process);\n\t\t\tfindDepPids(newPids, process);\n\t\t}\n\t}\n\treturn newPids;\n}\n\nfunction traverseNode(root, callback) {\n\tcallback(root);\n\tif (root.children && root.children.length > 0) {\n\t\tfor (let childNode of root.children) {\n\t\t\ttraverseNode(childNode, callback);\n\t\t}\n\t}\n}\n"],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O,IAAI,SAAS,EAAE;EAC9B,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;EAC3B,IAAI,OAAO,CAAC,KAAK,EAAE;GAClB,cAAc,CAAC,IAAI,EAAE,OAAO,CAAC,KAAK,EAAC;GACnC;EACD;CACD;;AAED,eAAe,mBAAmB,CAAC,IAAI,EAAE,GAAG,EAAE,WAAW,EAAE,YAAY,EAAE;CACxE,IAAI,OAAO,GAAG,EAAE,CAAC;CACjB,IAAI,MAAM,GAAG,EAAE,CAAC;CAChB,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE;EACnB,IAAI,IAAI,EAAE,IAAI,GAAG,CAAC;GACjB,MAAM,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,EAAE,CAAC,CAAC;GAC9B;EACD,IAAI,SAAS,GAAG,MAAM,WAAW,CAAC,MAAM,CAAC,CAAC;EAC1C,KAAK,IAAI,WAAW,IAAI,SAAS,EAAE;GAClC,IAAI,OAAO,GAAG,OAAO,WAAW,KAAK,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,WAAW,CAAC;GACtF,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;GACnB,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;GAC9B;EACD;CACD,OAAO,OAAO,CAAC;CACf;;AAED,SAAS,YAAY,CAAC,IAAI,EAAE,QAAQ,EAAE;CACrC,QAAQ,CAAC,IAAI,CAAC,CAAC;CACf,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;EAC9C,KAAK,IAAI,SAAS,IAAI,IAAI,CAAC,QAAQ,EAAE;GACpC,YAAY,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;GAClC;EACD;CACD;;;;"}
\ No newline at end of file
{"version":3,"file":"index.es.js","sources":["../src/ProcessManager.js","../src/ScriptManager.js","../src/CustomManager.js","../src/main.js"],"sourcesContent":["/**\n * Created by rockyl on 2019-11-29.\n */\n\nimport crypto from 'crypto'\n\nfunction md5(source) {\n\tconst hash = crypto.createHash('md5');\n\treturn hash.update(source).digest('hex');\n}\n\nexport default class ProcessManager {\n\tconstructor() {\n\t\tthis.pool = {};\n\t\tthis.scripts = '';\n\t}\n\n\tdeal(process) {\n\t\tlet hash = this.put(process);\n\t\tif (hash) {\n\t\t\tprocess.script = 'link://' + hash;\n\t\t}\n\t\tif (process.metas) {\n\t\t\tfor (let subProcess of process.metas) {\n\t\t\t\tthis.deal(subProcess);\n\t\t\t}\n\t\t}\n\t}\n\n\tput(process) {\n\t\tconst {id, name, script} = process;\n\t\tif (script) {\n\t\t\tlet hash = md5(script);\n\t\t\tif (!this.pool.hasOwnProperty(hash)) {\n\t\t\t\tthis.pool[hash] = {\n\t\t\t\t\tscript,\n\t\t\t\t\tids: [],\n\t\t\t\t};\n\t\t\t}\n\t\t\tthis.pool[hash].ids.push(`${id} - ${name}`);\n\t\t\treturn hash;\n\t\t}\n\t}\n\n\tgenerateCurrent() {\n\t\tlet scripts = '';\n\t\tfor (let hash in this.pool) {\n\t\t\tlet {script, ids} = this.pool[hash];\n\t\t\tlet idsComment = ids.map(id => {\n\t\t\t\treturn `/*== ${id} ==*/`\n\t\t\t}).join('\\n');\n\t\t\tscripts += `\n\texports['${hash}'] = function(args, props, target, global, vm, scope){\n\t\treturn new Promise(function(resolve, reject){\n\n${idsComment}\n${script}\n\n\t\tfunction next(type, payload){resolve({type: type, payload: payload})}\n\t\t});\n\t};\n`;\n\t\t}\n\t\tthis.scripts += scripts;\n\t\tthis.pool = {};\n\n\t\treturn scripts;\n\t}\n\n\tcoverScripts(scripts) {\n\t\tthis.scripts = scripts;\n\t}\n\n\tgenerate() {\n\t\tthis.generateCurrent();\n\t\tlet scripts = this.scripts;\n\n\t\treturn `\nconsole.log('processes.js loaded');\n\n(function(){\nvar exports = {};\n${scripts}\n\n\tengine.setScriptMap(exports);\n})();\n`\n\t}\n}\n","/**\n * Created by rockyl on 2019-11-29.\n */\n\nexport default class ScriptManager {\n\tconstructor() {\n\t\tthis.pool = [];\n\t}\n\n\tdeal(script){\n\t\tthis.pool.push(script);\n\t}\n\n\tgenerate(){\n\t\tlet scripts = '';\n\t\tfor(let {id, code} of this.pool){\n\t\t\tscripts += `\n/*=====START ${id} START=====*/\n(function(exports){\n${code}\n})(exports);\n\tengine.registerScriptDef(exports.default.id, exports.default);\n/*=====END ${id} END=====*/`;\n\t\t}\n\n\t\treturn `\nconsole.log('scripts.js loaded');\n\n(function(){\nvar exports = {};\n${scripts}\n})();\n`;\n\t}\n}\n","/**\n * Created by rockyl on 2019-11-29.\n */\n\nexport default class CustomManager {\n\tconstructor() {\n\t\tthis.pool = [];\n\t}\n\n\tdeal(custom) {\n\t\tthis.pool.push(custom);\n\t}\n\n\tgenerate() {\n\t\tlet scripts = '';\n\t\tfor (let {id, code} of this.pool) {\n\t\t\tscripts += `\n/*=====START ${id} START=====*/\nvar module = {\n\texports: {}\n};\n(function(module){\nfunction getAssetByUUID(uuid){\n\treturn engine.resolveCustomAsset('${id}', uuid);\n}\nfunction getProps(){\n\treturn engine.getProps('${id}');\n}\n\n${code}\n})(module);\nexports['${id}'] = module.exports;\n/*=====END ${id} END=====*/`;\n\t\t}\n\n\t\treturn `\nconsole.log('customs.js loaded');\n\n(function(){\nvar exports = {};\n\nfunction require(id){\n\tif(id === 'tslib'){\n\t\treturn window['tslib']\t\n\t}else{\n\t\tconsole.log('missing require', id);\n\t}\n}\n\n${scripts}\n\n\tfor(var key in exports){\n\t\tengine.registerCustomModule(key, exports[key]);\n\t}\n})();\n`\n\t}\n}\n","/**\n * Created by rockyl on 2019-12-20.\n */\n\nimport ProcessManager from \"./ProcessManager\";\nimport ScriptManager from \"./ScriptManager\";\nimport CustomManager from \"./CustomManager\";\nimport {compute} from \"props-compute\";\n\nconst TAG = 'zeroing-code-divider';\n\nexport async function divideCode(data, {debug, compile, uglify, getPackages, dependencies}) {\n\tconst processManager = new ProcessManager();\n\tconst scriptManager = new ScriptManager();\n\tconst customManager = new CustomManager();\n\n\tasync function getPackagesTrans(schema, type) {\n\t\tlet packages = await getPackages(schema, type);\n\t\tlet packageDatas = [];\n\t\tfor (let packageItem of packages) {\n\t\t\tlet data = packageItem.data;\n\t\t\tif (typeof packageItem.data === 'string') {\n\t\t\t\tdata = JSON.parse(data);\n\t\t\t}\n\t\t\tpackageDatas.push(data);\n\t\t}\n\t\treturn packageDatas;\n\t}\n\n\t/*=====START process =====*/\n\t//console.log(TAG, 'start process');\n\tlet processIDs = [];\n\tfindDepPidsBat(processIDs, data.processes);\n\tlet builtinProcesses = data.builtinProcesses = [];\n\n\tlet bProcessIDs = processIDs;\n\twhile (true) {\n\t\tlet newPids = await addBuiltinProcesses(builtinProcesses, bProcessIDs, getPackagesTrans, dependencies);\n\t\tbProcessIDs = [];\n\t\tfor (let id of newPids) {\n\t\t\tif (!processIDs.includes(id)) {\n\t\t\t\tbProcessIDs.push(id);\n\t\t\t\tprocessIDs.push(id);\n\t\t\t}\n\t\t}\n\t\tif (bProcessIDs.length === 0) {\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tfor (let process of data.processes) {\n\t\tprocessManager.deal(process);\n\t}\n\n\t//console.log(TAG, 'processManager.generateCurrent()');\n\n\tlet ptScript = processManager.generateCurrent();\n\tif (compile) {\n\t\tconst result = await compile(ptScript);\n\t\tprocessManager.coverScripts(result.code); //自定义过程先编译\n\t}\n\n\tfor (let process of builtinProcesses) {\n\t\tprocessManager.deal(process);\n\t}\n\n\tlet processScriptContent = processManager.generate();\n\t//console.log(processScriptContent);\n\tif (!debug) {\n\t\tprocessScriptContent = uglify(processScriptContent);\n\t}\n\t/*=====END process =====*/\n\n\t/*=====START script =====*/\n\t//console.log(TAG, 'start script');\n\tlet scriptIDs = [];\n\tfor (let view of data.views) {\n\t\ttraverseNode(view, (node) => {\n\t\t\tif (node.scripts && node.scripts.length > 0) {\n\t\t\t\tfor (let {script} of node.scripts) {\n\t\t\t\t\tif (!scriptIDs.includes(script)) {\n\t\t\t\t\t\tscriptIDs.push(script);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\t//console.log('scriptIDs:', scriptIDs);\n\t//let scriptsContainer = data.scripts = {};\n\t//let scriptsCode = '';\n\tif (scriptIDs.length > 0) {\n\t\tlet schema = idsToSchema(scriptIDs, dependencies);\n\t\tconst scripts = await getPackagesTrans(schema, 2);\n\t\tfor (let scriptData of scripts) {\n\t\t\tlet script = typeof scriptData === 'string' ? JSON.parse(scriptData) : scriptData;\n\t\t\t//scriptsContainer[id] = code;\n\t\t\tscriptManager.deal(script);\n\t\t}\n\t\t//console.log('scripts:', scriptsContainer);\n\t}\n\n\tlet scriptsContent = scriptManager.generate();\n\t//console.log(scriptsContent);\n\tif (!debug) {\n\t\tscriptsContent = uglify(scriptsContent);\n\t}\n\t/*=====END script =====*/\n\n\t/*=====START custom =====*/\n\t//console.log(TAG, 'start custom');\n\t//data.customs = [];\n\tconst customs = data.customs;\n\tif (customs && customs.length > 0) {\n\t\tlet schema = idsToSchema(customs.map(item => item.id), dependencies);\n\t\tlet customMetas = await getPackagesTrans(schema, 3);\n\t\tdata.customs = customMetas.map(item => {\n\t\t\tconst custom = typeof item === 'string' ? JSON.parse(item) : item;\n\t\t\tcustomManager.deal(custom);\n\t\t\tlet {props, assetMapping} = customs.find(c => c.id === custom.id);\n\t\t\t/*if (props) {\n\t\t\t\tfor (let key in custom.props) {\n\t\t\t\t\tif (!props.hasOwnProperty(key) && custom.props[key].hasOwnProperty('default')) {\n\t\t\t\t\t\tprops[key] = custom.props[key].default;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}*/\n\t\t\tcompute(props, custom.props);\n\t\t\tfor (let uuid in assetMapping) {\n\t\t\t\tlet asset = custom.assets.find(item => item.uuid === uuid);\n\t\t\t\tif (asset) {\n\t\t\t\t\tasset.url = assetMapping[uuid];\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tid: custom.id,\n\t\t\t\tname: custom.name,\n\t\t\t\tassets: custom.assets,\n\t\t\t\tprops,\n\t\t\t};\n\t\t})\n\t}\n\tlet customScriptContent = customManager.generate();\n\t//console.log(customScriptContent);\n\tif (!debug) {\n\t\tcustomScriptContent = uglify(customScriptContent);\n\t}\n\t/*=====END custom =====*/\n\n\treturn {\n\t\tprocessScriptContent,\n\t\tscriptsContent,\n\t\tcustomScriptContent,\n\t}\n}\n\nfunction findDepPids(list, process) {\n\tif (process.sub) {\n\t\tfor (let key in process.sub) {\n\t\t\tlet p = process.sub[key];\n\t\t\tif (!list.includes(p.meta)) {\n\t\t\t\tlist.push(p.meta);\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction findDepPidsBat(list, processes) {\n\tfor (let process of processes) {\n\t\tfindDepPids(list, process);\n\t\tif (process.metas) {\n\t\t\tfindDepPidsBat(list, process.metas)\n\t\t}\n\t}\n}\n\nasync function addBuiltinProcesses(list, ids, getPackagesTrans, dependencies) {\n\tlet newPids = [];\n\tif (ids.length > 0) {\n\t\tlet schema = idsToSchema(ids, dependencies);\n\t\tlet processes = await getPackagesTrans(schema, 1);\n\t\tfor (let processData of processes) {\n\t\t\tlet process = typeof processData === 'string' ? JSON.parse(processData) : processData;\n\t\t\tlist.push(process);\n\t\t\tfindDepPids(newPids, process);\n\t\t}\n\t}\n\treturn newPids;\n}\n\nfunction traverseNode(root, callback) {\n\tcallback(root);\n\tif (root.children && root.children.length > 0) {\n\t\tfor (let childNode of root.children) {\n\t\t\ttraverseNode(childNode, callback);\n\t\t}\n\t}\n}\n\nfunction idsToSchema(ids, dependencies){\n\tif(ids.length > 0){\n\t\tlet schema = {};\n\t\tfor (let id of ids) {\n\t\t\tif(dependencies[id]){\n\t\t\t\tschema[id] = dependencies[id];\n\t\t\t}\n\t\t}\n\t\treturn schema;\n\t}\n}\n"],"names":[],"mappings":";;;AAAA;;;AAGA,AAEA;AACA,SAAS,GAAG,CAAC,MAAM,EAA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AAC,CAAC;GAC9B;EACD;CACD,OAAO,OAAO,CAAC;CACf;;AAED,SAAS,YAAY,CAAC,IAAI,EAAE,QAAQ,EAAE;CACrC,QAAQ,CAAC,IAAI,CAAC,CAAC;CACf,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;EAC9C,KAAK,IAAI,SAAS,IAAI,IAAI,CAAC,QAAQ,EAAE;GACpC,YAAY,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;GAClC;EACD;CACD;;AAED,SAAS,WAAW,CAAC,GAAG,EAAE,YAAY,CAAC;CACtC,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC;EACjB,IAAI,MAAM,GAAG,EAAE,CAAC;EAChB,KAAK,IAAI,EAAE,IAAI,GAAG,EAAE;GACnB,GAAG,YAAY,CAAC,EAAE,CAAC,CAAC;IACnB,MAAM,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,EAAE,CAAC,CAAC;IAC9B;GACD;EACD,OAAO,MAAM,CAAC;EACd;CACD;;;;"}
\ No newline at end of file
......@@ -194,12 +194,23 @@ ${scripts}
* Created by rockyl on 2019-12-20.
*/
async function divideCode(data, {debug, compile, uglify, getPackages}) {
async function divideCode(data, {debug, compile, uglify, getPackages, dependencies}) {
const processManager = new ProcessManager();
const scriptManager = new ScriptManager();
const customManager = new CustomManager();
const dependencies = data.dependencies;
async function getPackagesTrans(schema, type) {
let packages = await getPackages(schema, type);
let packageDatas = [];
for (let packageItem of packages) {
let data = packageItem.data;
if (typeof packageItem.data === 'string') {
data = JSON.parse(data);
}
packageDatas.push(data);
}
return packageDatas;
}
/*=====START process =====*/
//console.log(TAG, 'start process');
......@@ -209,7 +220,7 @@ async function divideCode(data, {debug, compile, uglify, getPackages}) {
let bProcessIDs = processIDs;
while (true) {
let newPids = await addBuiltinProcesses(builtinProcesses, bProcessIDs, getPackages, dependencies);
let newPids = await addBuiltinProcesses(builtinProcesses, bProcessIDs, getPackagesTrans, dependencies);
bProcessIDs = [];
for (let id of newPids) {
if (!processIDs.includes(id)) {
......@@ -263,7 +274,8 @@ async function divideCode(data, {debug, compile, uglify, getPackages}) {
//let scriptsContainer = data.scripts = {};
//let scriptsCode = '';
if (scriptIDs.length > 0) {
const scripts = await getPackages(scriptIDs);
let schema = idsToSchema(scriptIDs, dependencies);
const scripts = await getPackagesTrans(schema, 2);
for (let scriptData of scripts) {
let script = typeof scriptData === 'string' ? JSON.parse(scriptData) : scriptData;
//scriptsContainer[id] = code;
......@@ -284,7 +296,8 @@ async function divideCode(data, {debug, compile, uglify, getPackages}) {
//data.customs = [];
const customs = data.customs;
if (customs && customs.length > 0) {
let customMetas = await getPackages(customs.map(item => item.id));
let schema = idsToSchema(customs.map(item => item.id), dependencies);
let customMetas = await getPackagesTrans(schema, 3);
data.customs = customMetas.map(item => {
const custom = typeof item === 'string' ? JSON.parse(item) : item;
customManager.deal(custom);
......@@ -345,14 +358,11 @@ function findDepPidsBat(list, processes) {
}
}
async function addBuiltinProcesses(list, ids, getPackages, dependencies) {
async function addBuiltinProcesses(list, ids, getPackagesTrans, dependencies) {
let newPids = [];
let schema = {};
if (ids.length > 0) {
for(let id of ids){
schema[id] = dependencies[id];
}
let processes = await getPackages(schema);
let schema = idsToSchema(ids, dependencies);
let processes = await getPackagesTrans(schema, 1);
for (let processData of processes) {
let process = typeof processData === 'string' ? JSON.parse(processData) : processData;
list.push(process);
......@@ -371,5 +381,17 @@ function traverseNode(root, callback) {
}
}
function idsToSchema(ids, dependencies){
if(ids.length > 0){
let schema = {};
for (let id of ids) {
if(dependencies[id]){
schema[id] = dependencies[id];
}
}
return schema;
}
}
exports.divideCode = divideCode;
//# sourceMappingURL=index.js.map
{"version":3,"file":"index.js","sources":["../src/ProcessManager.js","../src/ScriptManager.js","../src/CustomManager.js","../src/main.js"],"sourcesContent":["/**\n * Created by rockyl on 2019-11-29.\n */\n\nimport crypto from 'crypto'\n\nfunction md5(source) {\n\tconst hash = crypto.createHash('md5');\n\treturn hash.update(source).digest('hex');\n}\n\nexport default class ProcessManager {\n\tconstructor() {\n\t\tthis.pool = {};\n\t\tthis.scripts = '';\n\t}\n\n\tdeal(process) {\n\t\tlet hash = this.put(process);\n\t\tif (hash) {\n\t\t\tprocess.script = 'link://' + hash;\n\t\t}\n\t\tif (process.metas) {\n\t\t\tfor (let subProcess of process.metas) {\n\t\t\t\tthis.deal(subProcess);\n\t\t\t}\n\t\t}\n\t}\n\n\tput(process) {\n\t\tconst {id, name, script} = process;\n\t\tif (script) {\n\t\t\tlet hash = md5(script);\n\t\t\tif (!this.pool.hasOwnProperty(hash)) {\n\t\t\t\tthis.pool[hash] = {\n\t\t\t\t\tscript,\n\t\t\t\t\tids: [],\n\t\t\t\t};\n\t\t\t}\n\t\t\tthis.pool[hash].ids.push(`${id} - ${name}`);\n\t\t\treturn hash;\n\t\t}\n\t}\n\n\tgenerateCurrent() {\n\t\tlet scripts = '';\n\t\tfor (let hash in this.pool) {\n\t\t\tlet {script, ids} = this.pool[hash];\n\t\t\tlet idsComment = ids.map(id => {\n\t\t\t\treturn `/*== ${id} ==*/`\n\t\t\t}).join('\\n');\n\t\t\tscripts += `\n\texports['${hash}'] = function(args, props, target, global, vm, scope){\n\t\treturn new Promise(function(resolve, reject){\n\n${idsComment}\n${script}\n\n\t\tfunction next(type, payload){resolve({type: type, payload: payload})}\n\t\t});\n\t};\n`;\n\t\t}\n\t\tthis.scripts += scripts;\n\t\tthis.pool = {};\n\n\t\treturn scripts;\n\t}\n\n\tcoverScripts(scripts) {\n\t\tthis.scripts = scripts;\n\t}\n\n\tgenerate() {\n\t\tthis.generateCurrent();\n\t\tlet scripts = this.scripts;\n\n\t\treturn `\nconsole.log('processes.js loaded');\n\n(function(){\nvar exports = {};\n${scripts}\n\n\tengine.setScriptMap(exports);\n})();\n`\n\t}\n}\n","/**\n * Created by rockyl on 2019-11-29.\n */\n\nexport default class ScriptManager {\n\tconstructor() {\n\t\tthis.pool = [];\n\t}\n\n\tdeal(script){\n\t\tthis.pool.push(script);\n\t}\n\n\tgenerate(){\n\t\tlet scripts = '';\n\t\tfor(let {id, code} of this.pool){\n\t\t\tscripts += `\n/*=====START ${id} START=====*/\n(function(exports){\n${code}\n})(exports);\n\tengine.registerScriptDef(exports.default.id, exports.default);\n/*=====END ${id} END=====*/`;\n\t\t}\n\n\t\treturn `\nconsole.log('scripts.js loaded');\n\n(function(){\nvar exports = {};\n${scripts}\n})();\n`;\n\t}\n}\n","/**\n * Created by rockyl on 2019-11-29.\n */\n\nexport default class CustomManager {\n\tconstructor() {\n\t\tthis.pool = [];\n\t}\n\n\tdeal(custom) {\n\t\tthis.pool.push(custom);\n\t}\n\n\tgenerate() {\n\t\tlet scripts = '';\n\t\tfor (let {id, code} of this.pool) {\n\t\t\tscripts += `\n/*=====START ${id} START=====*/\nvar module = {\n\texports: {}\n};\n(function(module){\nfunction getAssetByUUID(uuid){\n\treturn engine.resolveCustomAsset('${id}', uuid);\n}\nfunction getProps(){\n\treturn engine.getProps('${id}');\n}\n\n${code}\n})(module);\nexports['${id}'] = module.exports;\n/*=====END ${id} END=====*/`;\n\t\t}\n\n\t\treturn `\nconsole.log('customs.js loaded');\n\n(function(){\nvar exports = {};\n\nfunction require(id){\n\tif(id === 'tslib'){\n\t\treturn window['tslib']\t\n\t}else{\n\t\tconsole.log('missing require', id);\n\t}\n}\n\n${scripts}\n\n\tfor(var key in exports){\n\t\tengine.registerCustomModule(key, exports[key]);\n\t}\n})();\n`\n\t}\n}\n","/**\n * Created by rockyl on 2019-12-20.\n */\n\nimport ProcessManager from \"./ProcessManager\";\nimport ScriptManager from \"./ScriptManager\";\nimport CustomManager from \"./CustomManager\";\nimport {compute} from \"props-compute\";\n\nconst TAG = 'zeroing-code-divider';\n\nexport async function divideCode(data, {debug, compile, uglify, getPackages}) {\n\tconst processManager = new ProcessManager();\n\tconst scriptManager = new ScriptManager();\n\tconst customManager = new CustomManager();\n\n\tconst dependencies = data.dependencies;\n\n\t/*=====START process =====*/\n\t//console.log(TAG, 'start process');\n\tlet processIDs = [];\n\tfindDepPidsBat(processIDs, data.processes);\n\tlet builtinProcesses = data.builtinProcesses = [];\n\n\tlet bProcessIDs = processIDs;\n\twhile (true) {\n\t\tlet newPids = await addBuiltinProcesses(builtinProcesses, bProcessIDs, getPackages, dependencies);\n\t\tbProcessIDs = [];\n\t\tfor (let id of newPids) {\n\t\t\tif (!processIDs.includes(id)) {\n\t\t\t\tbProcessIDs.push(id);\n\t\t\t\tprocessIDs.push(id);\n\t\t\t}\n\t\t}\n\t\tif (bProcessIDs.length === 0) {\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tfor (let process of data.processes) {\n\t\tprocessManager.deal(process);\n\t}\n\n\t//console.log(TAG, 'processManager.generateCurrent()');\n\n\tlet ptScript = processManager.generateCurrent();\n\tif (compile) {\n\t\tconst result = await compile(ptScript);\n\t\tprocessManager.coverScripts(result.code); //自定义过程先编译\n\t}\n\n\tfor (let process of builtinProcesses) {\n\t\tprocessManager.deal(process);\n\t}\n\n\tlet processScriptContent = processManager.generate();\n\t//console.log(processScriptContent);\n\tif (!debug) {\n\t\tprocessScriptContent = uglify(processScriptContent);\n\t}\n\t/*=====END process =====*/\n\n\t/*=====START script =====*/\n\t//console.log(TAG, 'start script');\n\tlet scriptIDs = [];\n\tfor (let view of data.views) {\n\t\ttraverseNode(view, (node) => {\n\t\t\tif (node.scripts && node.scripts.length > 0) {\n\t\t\t\tfor (let {script} of node.scripts) {\n\t\t\t\t\tif (!scriptIDs.includes(script)) {\n\t\t\t\t\t\tscriptIDs.push(script);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\t//console.log('scriptIDs:', scriptIDs);\n\t//let scriptsContainer = data.scripts = {};\n\t//let scriptsCode = '';\n\tif (scriptIDs.length > 0) {\n\t\tconst scripts = await getPackages(scriptIDs);\n\t\tfor (let scriptData of scripts) {\n\t\t\tlet script = typeof scriptData === 'string' ? JSON.parse(scriptData) : scriptData;\n\t\t\t//scriptsContainer[id] = code;\n\t\t\tscriptManager.deal(script);\n\t\t}\n\t\t//console.log('scripts:', scriptsContainer);\n\t}\n\n\tlet scriptsContent = scriptManager.generate();\n\t//console.log(scriptsContent);\n\tif (!debug) {\n\t\tscriptsContent = uglify(scriptsContent);\n\t}\n\t/*=====END script =====*/\n\n\t/*=====START custom =====*/\n\t//console.log(TAG, 'start custom');\n\t//data.customs = [];\n\tconst customs = data.customs;\n\tif (customs && customs.length > 0) {\n\t\tlet customMetas = await getPackages(customs.map(item => item.id));\n\t\tdata.customs = customMetas.map(item => {\n\t\t\tconst custom = typeof item === 'string' ? JSON.parse(item) : item;\n\t\t\tcustomManager.deal(custom);\n\t\t\tlet {props, assetMapping} = customs.find(c => c.id === custom.id);\n\t\t\t/*if (props) {\n\t\t\t\tfor (let key in custom.props) {\n\t\t\t\t\tif (!props.hasOwnProperty(key) && custom.props[key].hasOwnProperty('default')) {\n\t\t\t\t\t\tprops[key] = custom.props[key].default;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}*/\n\t\t\tcompute(props, custom.props);\n\t\t\tfor (let uuid in assetMapping) {\n\t\t\t\tlet asset = custom.assets.find(item => item.uuid === uuid);\n\t\t\t\tif (asset) {\n\t\t\t\t\tasset.url = assetMapping[uuid];\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tid: custom.id,\n\t\t\t\tname: custom.name,\n\t\t\t\tassets: custom.assets,\n\t\t\t\tprops,\n\t\t\t};\n\t\t})\n\t}\n\tlet customScriptContent = customManager.generate();\n\t//console.log(customScriptContent);\n\tif (!debug) {\n\t\tcustomScriptContent = uglify(customScriptContent);\n\t}\n\t/*=====END custom =====*/\n\n\treturn {\n\t\tprocessScriptContent,\n\t\tscriptsContent,\n\t\tcustomScriptContent,\n\t}\n}\n\nfunction findDepPids(list, process) {\n\tif (process.sub) {\n\t\tfor (let key in process.sub) {\n\t\t\tlet p = process.sub[key];\n\t\t\tif (!list.includes(p.meta)) {\n\t\t\t\tlist.push(p.meta);\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction findDepPidsBat(list, processes) {\n\tfor (let process of processes) {\n\t\tfindDepPids(list, process);\n\t\tif (process.metas) {\n\t\t\tfindDepPidsBat(list, process.metas)\n\t\t}\n\t}\n}\n\nasync function addBuiltinProcesses(list, ids, getPackages, dependencies) {\n\tlet newPids = [];\n\tlet schema = {};\n\tif (ids.length > 0) {\n\t\tfor(let id of ids){\n\t\t\tschema[id] = dependencies[id];\n\t\t}\n\t\tlet processes = await getPackages(schema);\n\t\tfor (let processData of processes) {\n\t\t\tlet process = typeof processData === 'string' ? JSON.parse(processData) : processData;\n\t\t\tlist.push(process);\n\t\t\tfindDepPids(newPids, process);\n\t\t}\n\t}\n\treturn newPids;\n}\n\nfunction traverseNode(root, callback) {\n\tcallback(root);\n\tif (root.children && root.children.length > 0) {\n\t\tfor (let childNode of root.children) {\n\t\t\ttraverseNode(childNode, callback);\n\t\t}\n\t}\n}\n"],"names":["compute"],"mappings":";;;;;;;;;AAAA;;;AAGA,AAEA;AACA,SAAS,GAAG,CAAC,MAAM,EAAE;CACpB,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;CACtC,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;CACzC;;AAED,AAAe,MAAM,cAAc,CAAC;CACnC,WAAW,GAAG;EACb,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;EACf,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;EAClB;;CAED,IAAI,CAAC,OAAO,EAAE;EACb,IAAI,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;EAC7B,IAAI,IAAI,EAAE;GACT,OAAO,CAAC,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;GAClC;EACD,IAAI,OAAO,CAAC,KAAK,EAAE;GAClB,KAAK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AE;GAClC,IAAI,OAAO,GAAG,OAAO,WAAW,KAAK,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,WAAW,CAAC;GACtF,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;GACnB,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;GAC9B;EACD;CACD,OAAO,OAAO,CAAC;CACf;;AAED,SAAS,YAAY,CAAC,IAAI,EAAE,QAAQ,EAAE;CACrC,QAAQ,CAAC,IAAI,CAAC,CAAC;CACf,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;EAC9C,KAAK,IAAI,SAAS,IAAI,IAAI,CAAC,QAAQ,EAAE;GACpC,YAAY,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;GAClC;EACD;CACD;;;;"}
\ No newline at end of file
{"version":3,"file":"index.js","sources":["../src/ProcessManager.js","../src/ScriptManager.js","../src/CustomManager.js","../src/main.js"],"sourcesContent":["/**\n * Created by rockyl on 2019-11-29.\n */\n\nimport crypto from 'crypto'\n\nfunction md5(source) {\n\tconst hash = crypto.createHash('md5');\n\treturn hash.update(source).digest('hex');\n}\n\nexport default class ProcessManager {\n\tconstructor() {\n\t\tthis.pool = {};\n\t\tthis.scripts = '';\n\t}\n\n\tdeal(process) {\n\t\tlet hash = this.put(process);\n\t\tif (hash) {\n\t\t\tprocess.script = 'link://' + hash;\n\t\t}\n\t\tif (process.metas) {\n\t\t\tfor (let subProcess of process.metas) {\n\t\t\t\tthis.deal(subProcess);\n\t\t\t}\n\t\t}\n\t}\n\n\tput(process) {\n\t\tconst {id, name, script} = process;\n\t\tif (script) {\n\t\t\tlet hash = md5(script);\n\t\t\tif (!this.pool.hasOwnProperty(hash)) {\n\t\t\t\tthis.pool[hash] = {\n\t\t\t\t\tscript,\n\t\t\t\t\tids: [],\n\t\t\t\t};\n\t\t\t}\n\t\t\tthis.pool[hash].ids.push(`${id} - ${name}`);\n\t\t\treturn hash;\n\t\t}\n\t}\n\n\tgenerateCurrent() {\n\t\tlet scripts = '';\n\t\tfor (let hash in this.pool) {\n\t\t\tlet {script, ids} = this.pool[hash];\n\t\t\tlet idsComment = ids.map(id => {\n\t\t\t\treturn `/*== ${id} ==*/`\n\t\t\t}).join('\\n');\n\t\t\tscripts += `\n\texports['${hash}'] = function(args, props, target, global, vm, scope){\n\t\treturn new Promise(function(resolve, reject){\n\n${idsComment}\n${script}\n\n\t\tfunction next(type, payload){resolve({type: type, payload: payload})}\n\t\t});\n\t};\n`;\n\t\t}\n\t\tthis.scripts += scripts;\n\t\tthis.pool = {};\n\n\t\treturn scripts;\n\t}\n\n\tcoverScripts(scripts) {\n\t\tthis.scripts = scripts;\n\t}\n\n\tgenerate() {\n\t\tthis.generateCurrent();\n\t\tlet scripts = this.scripts;\n\n\t\treturn `\nconsole.log('processes.js loaded');\n\n(function(){\nvar exports = {};\n${scripts}\n\n\tengine.setScriptMap(exports);\n})();\n`\n\t}\n}\n","/**\n * Created by rockyl on 2019-11-29.\n */\n\nexport default class ScriptManager {\n\tconstructor() {\n\t\tthis.pool = [];\n\t}\n\n\tdeal(script){\n\t\tthis.pool.push(script);\n\t}\n\n\tgenerate(){\n\t\tlet scripts = '';\n\t\tfor(let {id, code} of this.pool){\n\t\t\tscripts += `\n/*=====START ${id} START=====*/\n(function(exports){\n${code}\n})(exports);\n\tengine.registerScriptDef(exports.default.id, exports.default);\n/*=====END ${id} END=====*/`;\n\t\t}\n\n\t\treturn `\nconsole.log('scripts.js loaded');\n\n(function(){\nvar exports = {};\n${scripts}\n})();\n`;\n\t}\n}\n","/**\n * Created by rockyl on 2019-11-29.\n */\n\nexport default class CustomManager {\n\tconstructor() {\n\t\tthis.pool = [];\n\t}\n\n\tdeal(custom) {\n\t\tthis.pool.push(custom);\n\t}\n\n\tgenerate() {\n\t\tlet scripts = '';\n\t\tfor (let {id, code} of this.pool) {\n\t\t\tscripts += `\n/*=====START ${id} START=====*/\nvar module = {\n\texports: {}\n};\n(function(module){\nfunction getAssetByUUID(uuid){\n\treturn engine.resolveCustomAsset('${id}', uuid);\n}\nfunction getProps(){\n\treturn engine.getProps('${id}');\n}\n\n${code}\n})(module);\nexports['${id}'] = module.exports;\n/*=====END ${id} END=====*/`;\n\t\t}\n\n\t\treturn `\nconsole.log('customs.js loaded');\n\n(function(){\nvar exports = {};\n\nfunction require(id){\n\tif(id === 'tslib'){\n\t\treturn window['tslib']\t\n\t}else{\n\t\tconsole.log('missing require', id);\n\t}\n}\n\n${scripts}\n\n\tfor(var key in exports){\n\t\tengine.registerCustomModule(key, exports[key]);\n\t}\n})();\n`\n\t}\n}\n","/**\n * Created by rockyl on 2019-12-20.\n */\n\nimport ProcessManager from \"./ProcessManager\";\nimport ScriptManager from \"./ScriptManager\";\nimport CustomManager from \"./CustomManager\";\nimport {compute} from \"props-compute\";\n\nconst TAG = 'zeroing-code-divider';\n\nexport async function divideCode(data, {debug, compile, uglify, getPackages, dependencies}) {\n\tconst processManager = new ProcessManager();\n\tconst scriptManager = new ScriptManager();\n\tconst customManager = new CustomManager();\n\n\tasync function getPackagesTrans(schema, type) {\n\t\tlet packages = await getPackages(schema, type);\n\t\tlet packageDatas = [];\n\t\tfor (let packageItem of packages) {\n\t\t\tlet data = packageItem.data;\n\t\t\tif (typeof packageItem.data === 'string') {\n\t\t\t\tdata = JSON.parse(data);\n\t\t\t}\n\t\t\tpackageDatas.push(data);\n\t\t}\n\t\treturn packageDatas;\n\t}\n\n\t/*=====START process =====*/\n\t//console.log(TAG, 'start process');\n\tlet processIDs = [];\n\tfindDepPidsBat(processIDs, data.processes);\n\tlet builtinProcesses = data.builtinProcesses = [];\n\n\tlet bProcessIDs = processIDs;\n\twhile (true) {\n\t\tlet newPids = await addBuiltinProcesses(builtinProcesses, bProcessIDs, getPackagesTrans, dependencies);\n\t\tbProcessIDs = [];\n\t\tfor (let id of newPids) {\n\t\t\tif (!processIDs.includes(id)) {\n\t\t\t\tbProcessIDs.push(id);\n\t\t\t\tprocessIDs.push(id);\n\t\t\t}\n\t\t}\n\t\tif (bProcessIDs.length === 0) {\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tfor (let process of data.processes) {\n\t\tprocessManager.deal(process);\n\t}\n\n\t//console.log(TAG, 'processManager.generateCurrent()');\n\n\tlet ptScript = processManager.generateCurrent();\n\tif (compile) {\n\t\tconst result = await compile(ptScript);\n\t\tprocessManager.coverScripts(result.code); //自定义过程先编译\n\t}\n\n\tfor (let process of builtinProcesses) {\n\t\tprocessManager.deal(process);\n\t}\n\n\tlet processScriptContent = processManager.generate();\n\t//console.log(processScriptContent);\n\tif (!debug) {\n\t\tprocessScriptContent = uglify(processScriptContent);\n\t}\n\t/*=====END process =====*/\n\n\t/*=====START script =====*/\n\t//console.log(TAG, 'start script');\n\tlet scriptIDs = [];\n\tfor (let view of data.views) {\n\t\ttraverseNode(view, (node) => {\n\t\t\tif (node.scripts && node.scripts.length > 0) {\n\t\t\t\tfor (let {script} of node.scripts) {\n\t\t\t\t\tif (!scriptIDs.includes(script)) {\n\t\t\t\t\t\tscriptIDs.push(script);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\t//console.log('scriptIDs:', scriptIDs);\n\t//let scriptsContainer = data.scripts = {};\n\t//let scriptsCode = '';\n\tif (scriptIDs.length > 0) {\n\t\tlet schema = idsToSchema(scriptIDs, dependencies);\n\t\tconst scripts = await getPackagesTrans(schema, 2);\n\t\tfor (let scriptData of scripts) {\n\t\t\tlet script = typeof scriptData === 'string' ? JSON.parse(scriptData) : scriptData;\n\t\t\t//scriptsContainer[id] = code;\n\t\t\tscriptManager.deal(script);\n\t\t}\n\t\t//console.log('scripts:', scriptsContainer);\n\t}\n\n\tlet scriptsContent = scriptManager.generate();\n\t//console.log(scriptsContent);\n\tif (!debug) {\n\t\tscriptsContent = uglify(scriptsContent);\n\t}\n\t/*=====END script =====*/\n\n\t/*=====START custom =====*/\n\t//console.log(TAG, 'start custom');\n\t//data.customs = [];\n\tconst customs = data.customs;\n\tif (customs && customs.length > 0) {\n\t\tlet schema = idsToSchema(customs.map(item => item.id), dependencies);\n\t\tlet customMetas = await getPackagesTrans(schema, 3);\n\t\tdata.customs = customMetas.map(item => {\n\t\t\tconst custom = typeof item === 'string' ? JSON.parse(item) : item;\n\t\t\tcustomManager.deal(custom);\n\t\t\tlet {props, assetMapping} = customs.find(c => c.id === custom.id);\n\t\t\t/*if (props) {\n\t\t\t\tfor (let key in custom.props) {\n\t\t\t\t\tif (!props.hasOwnProperty(key) && custom.props[key].hasOwnProperty('default')) {\n\t\t\t\t\t\tprops[key] = custom.props[key].default;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}*/\n\t\t\tcompute(props, custom.props);\n\t\t\tfor (let uuid in assetMapping) {\n\t\t\t\tlet asset = custom.assets.find(item => item.uuid === uuid);\n\t\t\t\tif (asset) {\n\t\t\t\t\tasset.url = assetMapping[uuid];\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tid: custom.id,\n\t\t\t\tname: custom.name,\n\t\t\t\tassets: custom.assets,\n\t\t\t\tprops,\n\t\t\t};\n\t\t})\n\t}\n\tlet customScriptContent = customManager.generate();\n\t//console.log(customScriptContent);\n\tif (!debug) {\n\t\tcustomScriptContent = uglify(customScriptContent);\n\t}\n\t/*=====END custom =====*/\n\n\treturn {\n\t\tprocessScriptContent,\n\t\tscriptsContent,\n\t\tcustomScriptContent,\n\t}\n}\n\nfunction findDepPids(list, process) {\n\tif (process.sub) {\n\t\tfor (let key in process.sub) {\n\t\t\tlet p = process.sub[key];\n\t\t\tif (!list.includes(p.meta)) {\n\t\t\t\tlist.push(p.meta);\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction findDepPidsBat(list, processes) {\n\tfor (let process of processes) {\n\t\tfindDepPids(list, process);\n\t\tif (process.metas) {\n\t\t\tfindDepPidsBat(list, process.metas)\n\t\t}\n\t}\n}\n\nasync function addBuiltinProcesses(list, ids, getPackagesTrans, dependencies) {\n\tlet newPids = [];\n\tif (ids.length > 0) {\n\t\tlet schema = idsToSchema(ids, dependencies);\n\t\tlet processes = await getPackagesTrans(schema, 1);\n\t\tfor (let processData of processes) {\n\t\t\tlet process = typeof processData === 'string' ? JSON.parse(processData) : processData;\n\t\t\tlist.push(process);\n\t\t\tfindDepPids(newPids, process);\n\t\t}\n\t}\n\treturn newPids;\n}\n\nfunction traverseNode(root, callback) {\n\tcallback(root);\n\tif (root.children && root.children.length > 0) {\n\t\tfor (let childNode of root.children) {\n\t\t\ttraverseNode(childNode, callback);\n\t\t}\n\t}\n}\n\nfunction idsToSchema(ids, dependencies){\n\tif(ids.length > 0){\n\t\tlet schema = {};\n\t\tfor (let id of ids) {\n\t\t\tif(dependencies[id]){\n\t\t\t\tschema[id] = dependencies[id];\n\t\t\t}\n\t\t}\n\t\treturn schema;\n\t}\n}\n"],"names":["compute"],"mappings":";;;;;;;;;AAAA;;;AAGA,AAEA;AACA,SAAS,GAAG,CAAC,MAAM,EAAE;CACpB,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;CACtC,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;CACzC;;AAED,AAAe,MAAM,cAAc,CAAC;CACnC,WAAW,GAAG;EACb,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;EACf,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;EAClB;;CAED,IAAI,CAAC,OAAO,EAAE;EACb,IAAI,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;EAC7B,IAAI,IAAI,EAAE;GACT,OAAO,CAAC,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;GAClC;EACD,IAAI,OAAO,CAAC,KAAK,EAAE;GAClB,KAAK,IAAI,UAAU,IAAI,OAAO,CAAC,KAAK,EAAE;IACrC,IAAI,CA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AC,EAAE,CAAC,GAAG,YAAY,CAAC,EAAE,CAAC,CAAC;IAC9B;GACD;EACD,OAAO,MAAM,CAAC;EACd;CACD;;;;"}
\ No newline at end of file
......@@ -193,12 +193,23 @@ ${scripts}
* Created by rockyl on 2019-12-20.
*/
async function divideCode(data, {debug, compile, uglify, getPackages}) {
async function divideCode(data, {debug, compile, uglify, getPackages, dependencies}) {
const processManager = new ProcessManager();
const scriptManager = new ScriptManager();
const customManager = new CustomManager();
const dependencies = data.dependencies;
async function getPackagesTrans(schema, type) {
let packages = await getPackages(schema, type);
let packageDatas = [];
for (let packageItem of packages) {
let data = packageItem.data;
if (typeof packageItem.data === 'string') {
data = JSON.parse(data);
}
packageDatas.push(data);
}
return packageDatas;
}
/*=====START process =====*/
//console.log(TAG, 'start process');
......@@ -208,7 +219,7 @@ ${scripts}
let bProcessIDs = processIDs;
while (true) {
let newPids = await addBuiltinProcesses(builtinProcesses, bProcessIDs, getPackages, dependencies);
let newPids = await addBuiltinProcesses(builtinProcesses, bProcessIDs, getPackagesTrans, dependencies);
bProcessIDs = [];
for (let id of newPids) {
if (!processIDs.includes(id)) {
......@@ -262,7 +273,8 @@ ${scripts}
//let scriptsContainer = data.scripts = {};
//let scriptsCode = '';
if (scriptIDs.length > 0) {
const scripts = await getPackages(scriptIDs);
let schema = idsToSchema(scriptIDs, dependencies);
const scripts = await getPackagesTrans(schema, 2);
for (let scriptData of scripts) {
let script = typeof scriptData === 'string' ? JSON.parse(scriptData) : scriptData;
//scriptsContainer[id] = code;
......@@ -283,7 +295,8 @@ ${scripts}
//data.customs = [];
const customs = data.customs;
if (customs && customs.length > 0) {
let customMetas = await getPackages(customs.map(item => item.id));
let schema = idsToSchema(customs.map(item => item.id), dependencies);
let customMetas = await getPackagesTrans(schema, 3);
data.customs = customMetas.map(item => {
const custom = typeof item === 'string' ? JSON.parse(item) : item;
customManager.deal(custom);
......@@ -344,14 +357,11 @@ ${scripts}
}
}
async function addBuiltinProcesses(list, ids, getPackages, dependencies) {
async function addBuiltinProcesses(list, ids, getPackagesTrans, dependencies) {
let newPids = [];
let schema = {};
if (ids.length > 0) {
for(let id of ids){
schema[id] = dependencies[id];
}
let processes = await getPackages(schema);
let schema = idsToSchema(ids, dependencies);
let processes = await getPackagesTrans(schema, 1);
for (let processData of processes) {
let process = typeof processData === 'string' ? JSON.parse(processData) : processData;
list.push(process);
......@@ -370,6 +380,18 @@ ${scripts}
}
}
function idsToSchema(ids, dependencies){
if(ids.length > 0){
let schema = {};
for (let id of ids) {
if(dependencies[id]){
schema[id] = dependencies[id];
}
}
return schema;
}
}
exports.divideCode = divideCode;
Object.defineProperty(exports, '__esModule', { value: true });
......
{"version":3,"file":"index.umd.js","sources":["../src/ProcessManager.js","../src/ScriptManager.js","../src/CustomManager.js","../src/main.js"],"sourcesContent":["/**\n * Created by rockyl on 2019-11-29.\n */\n\nimport crypto from 'crypto'\n\nfunction md5(source) {\n\tconst hash = crypto.createHash('md5');\n\treturn hash.update(source).digest('hex');\n}\n\nexport default class ProcessManager {\n\tconstructor() {\n\t\tthis.pool = {};\n\t\tthis.scripts = '';\n\t}\n\n\tdeal(process) {\n\t\tlet hash = this.put(process);\n\t\tif (hash) {\n\t\t\tprocess.script = 'link://' + hash;\n\t\t}\n\t\tif (process.metas) {\n\t\t\tfor (let subProcess of process.metas) {\n\t\t\t\tthis.deal(subProcess);\n\t\t\t}\n\t\t}\n\t}\n\n\tput(process) {\n\t\tconst {id, name, script} = process;\n\t\tif (script) {\n\t\t\tlet hash = md5(script);\n\t\t\tif (!this.pool.hasOwnProperty(hash)) {\n\t\t\t\tthis.pool[hash] = {\n\t\t\t\t\tscript,\n\t\t\t\t\tids: [],\n\t\t\t\t};\n\t\t\t}\n\t\t\tthis.pool[hash].ids.push(`${id} - ${name}`);\n\t\t\treturn hash;\n\t\t}\n\t}\n\n\tgenerateCurrent() {\n\t\tlet scripts = '';\n\t\tfor (let hash in this.pool) {\n\t\t\tlet {script, ids} = this.pool[hash];\n\t\t\tlet idsComment = ids.map(id => {\n\t\t\t\treturn `/*== ${id} ==*/`\n\t\t\t}).join('\\n');\n\t\t\tscripts += `\n\texports['${hash}'] = function(args, props, target, global, vm, scope){\n\t\treturn new Promise(function(resolve, reject){\n\n${idsComment}\n${script}\n\n\t\tfunction next(type, payload){resolve({type: type, payload: payload})}\n\t\t});\n\t};\n`;\n\t\t}\n\t\tthis.scripts += scripts;\n\t\tthis.pool = {};\n\n\t\treturn scripts;\n\t}\n\n\tcoverScripts(scripts) {\n\t\tthis.scripts = scripts;\n\t}\n\n\tgenerate() {\n\t\tthis.generateCurrent();\n\t\tlet scripts = this.scripts;\n\n\t\treturn `\nconsole.log('processes.js loaded');\n\n(function(){\nvar exports = {};\n${scripts}\n\n\tengine.setScriptMap(exports);\n})();\n`\n\t}\n}\n","/**\n * Created by rockyl on 2019-11-29.\n */\n\nexport default class ScriptManager {\n\tconstructor() {\n\t\tthis.pool = [];\n\t}\n\n\tdeal(script){\n\t\tthis.pool.push(script);\n\t}\n\n\tgenerate(){\n\t\tlet scripts = '';\n\t\tfor(let {id, code} of this.pool){\n\t\t\tscripts += `\n/*=====START ${id} START=====*/\n(function(exports){\n${code}\n})(exports);\n\tengine.registerScriptDef(exports.default.id, exports.default);\n/*=====END ${id} END=====*/`;\n\t\t}\n\n\t\treturn `\nconsole.log('scripts.js loaded');\n\n(function(){\nvar exports = {};\n${scripts}\n})();\n`;\n\t}\n}\n","/**\n * Created by rockyl on 2019-11-29.\n */\n\nexport default class CustomManager {\n\tconstructor() {\n\t\tthis.pool = [];\n\t}\n\n\tdeal(custom) {\n\t\tthis.pool.push(custom);\n\t}\n\n\tgenerate() {\n\t\tlet scripts = '';\n\t\tfor (let {id, code} of this.pool) {\n\t\t\tscripts += `\n/*=====START ${id} START=====*/\nvar module = {\n\texports: {}\n};\n(function(module){\nfunction getAssetByUUID(uuid){\n\treturn engine.resolveCustomAsset('${id}', uuid);\n}\nfunction getProps(){\n\treturn engine.getProps('${id}');\n}\n\n${code}\n})(module);\nexports['${id}'] = module.exports;\n/*=====END ${id} END=====*/`;\n\t\t}\n\n\t\treturn `\nconsole.log('customs.js loaded');\n\n(function(){\nvar exports = {};\n\nfunction require(id){\n\tif(id === 'tslib'){\n\t\treturn window['tslib']\t\n\t}else{\n\t\tconsole.log('missing require', id);\n\t}\n}\n\n${scripts}\n\n\tfor(var key in exports){\n\t\tengine.registerCustomModule(key, exports[key]);\n\t}\n})();\n`\n\t}\n}\n","/**\n * Created by rockyl on 2019-12-20.\n */\n\nimport ProcessManager from \"./ProcessManager\";\nimport ScriptManager from \"./ScriptManager\";\nimport CustomManager from \"./CustomManager\";\nimport {compute} from \"props-compute\";\n\nconst TAG = 'zeroing-code-divider';\n\nexport async function divideCode(data, {debug, compile, uglify, getPackages}) {\n\tconst processManager = new ProcessManager();\n\tconst scriptManager = new ScriptManager();\n\tconst customManager = new CustomManager();\n\n\tconst dependencies = data.dependencies;\n\n\t/*=====START process =====*/\n\t//console.log(TAG, 'start process');\n\tlet processIDs = [];\n\tfindDepPidsBat(processIDs, data.processes);\n\tlet builtinProcesses = data.builtinProcesses = [];\n\n\tlet bProcessIDs = processIDs;\n\twhile (true) {\n\t\tlet newPids = await addBuiltinProcesses(builtinProcesses, bProcessIDs, getPackages, dependencies);\n\t\tbProcessIDs = [];\n\t\tfor (let id of newPids) {\n\t\t\tif (!processIDs.includes(id)) {\n\t\t\t\tbProcessIDs.push(id);\n\t\t\t\tprocessIDs.push(id);\n\t\t\t}\n\t\t}\n\t\tif (bProcessIDs.length === 0) {\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tfor (let process of data.processes) {\n\t\tprocessManager.deal(process);\n\t}\n\n\t//console.log(TAG, 'processManager.generateCurrent()');\n\n\tlet ptScript = processManager.generateCurrent();\n\tif (compile) {\n\t\tconst result = await compile(ptScript);\n\t\tprocessManager.coverScripts(result.code); //自定义过程先编译\n\t}\n\n\tfor (let process of builtinProcesses) {\n\t\tprocessManager.deal(process);\n\t}\n\n\tlet processScriptContent = processManager.generate();\n\t//console.log(processScriptContent);\n\tif (!debug) {\n\t\tprocessScriptContent = uglify(processScriptContent);\n\t}\n\t/*=====END process =====*/\n\n\t/*=====START script =====*/\n\t//console.log(TAG, 'start script');\n\tlet scriptIDs = [];\n\tfor (let view of data.views) {\n\t\ttraverseNode(view, (node) => {\n\t\t\tif (node.scripts && node.scripts.length > 0) {\n\t\t\t\tfor (let {script} of node.scripts) {\n\t\t\t\t\tif (!scriptIDs.includes(script)) {\n\t\t\t\t\t\tscriptIDs.push(script);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\t//console.log('scriptIDs:', scriptIDs);\n\t//let scriptsContainer = data.scripts = {};\n\t//let scriptsCode = '';\n\tif (scriptIDs.length > 0) {\n\t\tconst scripts = await getPackages(scriptIDs);\n\t\tfor (let scriptData of scripts) {\n\t\t\tlet script = typeof scriptData === 'string' ? JSON.parse(scriptData) : scriptData;\n\t\t\t//scriptsContainer[id] = code;\n\t\t\tscriptManager.deal(script);\n\t\t}\n\t\t//console.log('scripts:', scriptsContainer);\n\t}\n\n\tlet scriptsContent = scriptManager.generate();\n\t//console.log(scriptsContent);\n\tif (!debug) {\n\t\tscriptsContent = uglify(scriptsContent);\n\t}\n\t/*=====END script =====*/\n\n\t/*=====START custom =====*/\n\t//console.log(TAG, 'start custom');\n\t//data.customs = [];\n\tconst customs = data.customs;\n\tif (customs && customs.length > 0) {\n\t\tlet customMetas = await getPackages(customs.map(item => item.id));\n\t\tdata.customs = customMetas.map(item => {\n\t\t\tconst custom = typeof item === 'string' ? JSON.parse(item) : item;\n\t\t\tcustomManager.deal(custom);\n\t\t\tlet {props, assetMapping} = customs.find(c => c.id === custom.id);\n\t\t\t/*if (props) {\n\t\t\t\tfor (let key in custom.props) {\n\t\t\t\t\tif (!props.hasOwnProperty(key) && custom.props[key].hasOwnProperty('default')) {\n\t\t\t\t\t\tprops[key] = custom.props[key].default;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}*/\n\t\t\tcompute(props, custom.props);\n\t\t\tfor (let uuid in assetMapping) {\n\t\t\t\tlet asset = custom.assets.find(item => item.uuid === uuid);\n\t\t\t\tif (asset) {\n\t\t\t\t\tasset.url = assetMapping[uuid];\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tid: custom.id,\n\t\t\t\tname: custom.name,\n\t\t\t\tassets: custom.assets,\n\t\t\t\tprops,\n\t\t\t};\n\t\t})\n\t}\n\tlet customScriptContent = customManager.generate();\n\t//console.log(customScriptContent);\n\tif (!debug) {\n\t\tcustomScriptContent = uglify(customScriptContent);\n\t}\n\t/*=====END custom =====*/\n\n\treturn {\n\t\tprocessScriptContent,\n\t\tscriptsContent,\n\t\tcustomScriptContent,\n\t}\n}\n\nfunction findDepPids(list, process) {\n\tif (process.sub) {\n\t\tfor (let key in process.sub) {\n\t\t\tlet p = process.sub[key];\n\t\t\tif (!list.includes(p.meta)) {\n\t\t\t\tlist.push(p.meta);\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction findDepPidsBat(list, processes) {\n\tfor (let process of processes) {\n\t\tfindDepPids(list, process);\n\t\tif (process.metas) {\n\t\t\tfindDepPidsBat(list, process.metas)\n\t\t}\n\t}\n}\n\nasync function addBuiltinProcesses(list, ids, getPackages, dependencies) {\n\tlet newPids = [];\n\tlet schema = {};\n\tif (ids.length > 0) {\n\t\tfor(let id of ids){\n\t\t\tschema[id] = dependencies[id];\n\t\t}\n\t\tlet processes = await getPackages(schema);\n\t\tfor (let processData of processes) {\n\t\t\tlet process = typeof processData === 'string' ? JSON.parse(processData) : processData;\n\t\t\tlist.push(process);\n\t\t\tfindDepPids(newPids, process);\n\t\t}\n\t}\n\treturn newPids;\n}\n\nfunction traverseNode(root, callback) {\n\tcallback(root);\n\tif (root.children && root.children.length > 0) {\n\t\tfor (let childNode of root.children) {\n\t\t\ttraverseNode(childNode, callback);\n\t\t}\n\t}\n}\n"],"names":["compute"],"mappings":";;;;;;;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YAAY,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;CACrC,GAAG;CACH,EAAE;CACF,CAAC;;;;;;;;;;;;"}
\ No newline at end of file
{"version":3,"file":"index.umd.js","sources":["../src/ProcessManager.js","../src/ScriptManager.js","../src/CustomManager.js","../src/main.js"],"sourcesContent":["/**\n * Created by rockyl on 2019-11-29.\n */\n\nimport crypto from 'crypto'\n\nfunction md5(source) {\n\tconst hash = crypto.createHash('md5');\n\treturn hash.update(source).digest('hex');\n}\n\nexport default class ProcessManager {\n\tconstructor() {\n\t\tthis.pool = {};\n\t\tthis.scripts = '';\n\t}\n\n\tdeal(process) {\n\t\tlet hash = this.put(process);\n\t\tif (hash) {\n\t\t\tprocess.script = 'link://' + hash;\n\t\t}\n\t\tif (process.metas) {\n\t\t\tfor (let subProcess of process.metas) {\n\t\t\t\tthis.deal(subProcess);\n\t\t\t}\n\t\t}\n\t}\n\n\tput(process) {\n\t\tconst {id, name, script} = process;\n\t\tif (script) {\n\t\t\tlet hash = md5(script);\n\t\t\tif (!this.pool.hasOwnProperty(hash)) {\n\t\t\t\tthis.pool[hash] = {\n\t\t\t\t\tscript,\n\t\t\t\t\tids: [],\n\t\t\t\t};\n\t\t\t}\n\t\t\tthis.pool[hash].ids.push(`${id} - ${name}`);\n\t\t\treturn hash;\n\t\t}\n\t}\n\n\tgenerateCurrent() {\n\t\tlet scripts = '';\n\t\tfor (let hash in this.pool) {\n\t\t\tlet {script, ids} = this.pool[hash];\n\t\t\tlet idsComment = ids.map(id => {\n\t\t\t\treturn `/*== ${id} ==*/`\n\t\t\t}).join('\\n');\n\t\t\tscripts += `\n\texports['${hash}'] = function(args, props, target, global, vm, scope){\n\t\treturn new Promise(function(resolve, reject){\n\n${idsComment}\n${script}\n\n\t\tfunction next(type, payload){resolve({type: type, payload: payload})}\n\t\t});\n\t};\n`;\n\t\t}\n\t\tthis.scripts += scripts;\n\t\tthis.pool = {};\n\n\t\treturn scripts;\n\t}\n\n\tcoverScripts(scripts) {\n\t\tthis.scripts = scripts;\n\t}\n\n\tgenerate() {\n\t\tthis.generateCurrent();\n\t\tlet scripts = this.scripts;\n\n\t\treturn `\nconsole.log('processes.js loaded');\n\n(function(){\nvar exports = {};\n${scripts}\n\n\tengine.setScriptMap(exports);\n})();\n`\n\t}\n}\n","/**\n * Created by rockyl on 2019-11-29.\n */\n\nexport default class ScriptManager {\n\tconstructor() {\n\t\tthis.pool = [];\n\t}\n\n\tdeal(script){\n\t\tthis.pool.push(script);\n\t}\n\n\tgenerate(){\n\t\tlet scripts = '';\n\t\tfor(let {id, code} of this.pool){\n\t\t\tscripts += `\n/*=====START ${id} START=====*/\n(function(exports){\n${code}\n})(exports);\n\tengine.registerScriptDef(exports.default.id, exports.default);\n/*=====END ${id} END=====*/`;\n\t\t}\n\n\t\treturn `\nconsole.log('scripts.js loaded');\n\n(function(){\nvar exports = {};\n${scripts}\n})();\n`;\n\t}\n}\n","/**\n * Created by rockyl on 2019-11-29.\n */\n\nexport default class CustomManager {\n\tconstructor() {\n\t\tthis.pool = [];\n\t}\n\n\tdeal(custom) {\n\t\tthis.pool.push(custom);\n\t}\n\n\tgenerate() {\n\t\tlet scripts = '';\n\t\tfor (let {id, code} of this.pool) {\n\t\t\tscripts += `\n/*=====START ${id} START=====*/\nvar module = {\n\texports: {}\n};\n(function(module){\nfunction getAssetByUUID(uuid){\n\treturn engine.resolveCustomAsset('${id}', uuid);\n}\nfunction getProps(){\n\treturn engine.getProps('${id}');\n}\n\n${code}\n})(module);\nexports['${id}'] = module.exports;\n/*=====END ${id} END=====*/`;\n\t\t}\n\n\t\treturn `\nconsole.log('customs.js loaded');\n\n(function(){\nvar exports = {};\n\nfunction require(id){\n\tif(id === 'tslib'){\n\t\treturn window['tslib']\t\n\t}else{\n\t\tconsole.log('missing require', id);\n\t}\n}\n\n${scripts}\n\n\tfor(var key in exports){\n\t\tengine.registerCustomModule(key, exports[key]);\n\t}\n})();\n`\n\t}\n}\n","/**\n * Created by rockyl on 2019-12-20.\n */\n\nimport ProcessManager from \"./ProcessManager\";\nimport ScriptManager from \"./ScriptManager\";\nimport CustomManager from \"./CustomManager\";\nimport {compute} from \"props-compute\";\n\nconst TAG = 'zeroing-code-divider';\n\nexport async function divideCode(data, {debug, compile, uglify, getPackages, dependencies}) {\n\tconst processManager = new ProcessManager();\n\tconst scriptManager = new ScriptManager();\n\tconst customManager = new CustomManager();\n\n\tasync function getPackagesTrans(schema, type) {\n\t\tlet packages = await getPackages(schema, type);\n\t\tlet packageDatas = [];\n\t\tfor (let packageItem of packages) {\n\t\t\tlet data = packageItem.data;\n\t\t\tif (typeof packageItem.data === 'string') {\n\t\t\t\tdata = JSON.parse(data);\n\t\t\t}\n\t\t\tpackageDatas.push(data);\n\t\t}\n\t\treturn packageDatas;\n\t}\n\n\t/*=====START process =====*/\n\t//console.log(TAG, 'start process');\n\tlet processIDs = [];\n\tfindDepPidsBat(processIDs, data.processes);\n\tlet builtinProcesses = data.builtinProcesses = [];\n\n\tlet bProcessIDs = processIDs;\n\twhile (true) {\n\t\tlet newPids = await addBuiltinProcesses(builtinProcesses, bProcessIDs, getPackagesTrans, dependencies);\n\t\tbProcessIDs = [];\n\t\tfor (let id of newPids) {\n\t\t\tif (!processIDs.includes(id)) {\n\t\t\t\tbProcessIDs.push(id);\n\t\t\t\tprocessIDs.push(id);\n\t\t\t}\n\t\t}\n\t\tif (bProcessIDs.length === 0) {\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tfor (let process of data.processes) {\n\t\tprocessManager.deal(process);\n\t}\n\n\t//console.log(TAG, 'processManager.generateCurrent()');\n\n\tlet ptScript = processManager.generateCurrent();\n\tif (compile) {\n\t\tconst result = await compile(ptScript);\n\t\tprocessManager.coverScripts(result.code); //自定义过程先编译\n\t}\n\n\tfor (let process of builtinProcesses) {\n\t\tprocessManager.deal(process);\n\t}\n\n\tlet processScriptContent = processManager.generate();\n\t//console.log(processScriptContent);\n\tif (!debug) {\n\t\tprocessScriptContent = uglify(processScriptContent);\n\t}\n\t/*=====END process =====*/\n\n\t/*=====START script =====*/\n\t//console.log(TAG, 'start script');\n\tlet scriptIDs = [];\n\tfor (let view of data.views) {\n\t\ttraverseNode(view, (node) => {\n\t\t\tif (node.scripts && node.scripts.length > 0) {\n\t\t\t\tfor (let {script} of node.scripts) {\n\t\t\t\t\tif (!scriptIDs.includes(script)) {\n\t\t\t\t\t\tscriptIDs.push(script);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\t//console.log('scriptIDs:', scriptIDs);\n\t//let scriptsContainer = data.scripts = {};\n\t//let scriptsCode = '';\n\tif (scriptIDs.length > 0) {\n\t\tlet schema = idsToSchema(scriptIDs, dependencies);\n\t\tconst scripts = await getPackagesTrans(schema, 2);\n\t\tfor (let scriptData of scripts) {\n\t\t\tlet script = typeof scriptData === 'string' ? JSON.parse(scriptData) : scriptData;\n\t\t\t//scriptsContainer[id] = code;\n\t\t\tscriptManager.deal(script);\n\t\t}\n\t\t//console.log('scripts:', scriptsContainer);\n\t}\n\n\tlet scriptsContent = scriptManager.generate();\n\t//console.log(scriptsContent);\n\tif (!debug) {\n\t\tscriptsContent = uglify(scriptsContent);\n\t}\n\t/*=====END script =====*/\n\n\t/*=====START custom =====*/\n\t//console.log(TAG, 'start custom');\n\t//data.customs = [];\n\tconst customs = data.customs;\n\tif (customs && customs.length > 0) {\n\t\tlet schema = idsToSchema(customs.map(item => item.id), dependencies);\n\t\tlet customMetas = await getPackagesTrans(schema, 3);\n\t\tdata.customs = customMetas.map(item => {\n\t\t\tconst custom = typeof item === 'string' ? JSON.parse(item) : item;\n\t\t\tcustomManager.deal(custom);\n\t\t\tlet {props, assetMapping} = customs.find(c => c.id === custom.id);\n\t\t\t/*if (props) {\n\t\t\t\tfor (let key in custom.props) {\n\t\t\t\t\tif (!props.hasOwnProperty(key) && custom.props[key].hasOwnProperty('default')) {\n\t\t\t\t\t\tprops[key] = custom.props[key].default;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}*/\n\t\t\tcompute(props, custom.props);\n\t\t\tfor (let uuid in assetMapping) {\n\t\t\t\tlet asset = custom.assets.find(item => item.uuid === uuid);\n\t\t\t\tif (asset) {\n\t\t\t\t\tasset.url = assetMapping[uuid];\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tid: custom.id,\n\t\t\t\tname: custom.name,\n\t\t\t\tassets: custom.assets,\n\t\t\t\tprops,\n\t\t\t};\n\t\t})\n\t}\n\tlet customScriptContent = customManager.generate();\n\t//console.log(customScriptContent);\n\tif (!debug) {\n\t\tcustomScriptContent = uglify(customScriptContent);\n\t}\n\t/*=====END custom =====*/\n\n\treturn {\n\t\tprocessScriptContent,\n\t\tscriptsContent,\n\t\tcustomScriptContent,\n\t}\n}\n\nfunction findDepPids(list, process) {\n\tif (process.sub) {\n\t\tfor (let key in process.sub) {\n\t\t\tlet p = process.sub[key];\n\t\t\tif (!list.includes(p.meta)) {\n\t\t\t\tlist.push(p.meta);\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction findDepPidsBat(list, processes) {\n\tfor (let process of processes) {\n\t\tfindDepPids(list, process);\n\t\tif (process.metas) {\n\t\t\tfindDepPidsBat(list, process.metas)\n\t\t}\n\t}\n}\n\nasync function addBuiltinProcesses(list, ids, getPackagesTrans, dependencies) {\n\tlet newPids = [];\n\tif (ids.length > 0) {\n\t\tlet schema = idsToSchema(ids, dependencies);\n\t\tlet processes = await getPackagesTrans(schema, 1);\n\t\tfor (let processData of processes) {\n\t\t\tlet process = typeof processData === 'string' ? JSON.parse(processData) : processData;\n\t\t\tlist.push(process);\n\t\t\tfindDepPids(newPids, process);\n\t\t}\n\t}\n\treturn newPids;\n}\n\nfunction traverseNode(root, callback) {\n\tcallback(root);\n\tif (root.children && root.children.length > 0) {\n\t\tfor (let childNode of root.children) {\n\t\t\ttraverseNode(childNode, callback);\n\t\t}\n\t}\n}\n\nfunction idsToSchema(ids, dependencies){\n\tif(ids.length > 0){\n\t\tl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,6 +8,7 @@
"props-compute": "http://gitlab2.dui88.com/laoqifeng/props-compute.git"
},
"scripts": {
"dev": "rollup -c -w",
"build": "rollup -c"
}
}
......@@ -9,12 +9,23 @@ import {compute} from "props-compute";
const TAG = 'zeroing-code-divider';
export async function divideCode(data, {debug, compile, uglify, getPackages}) {
export async function divideCode(data, {debug, compile, uglify, getPackages, dependencies}) {
const processManager = new ProcessManager();
const scriptManager = new ScriptManager();
const customManager = new CustomManager();
const dependencies = data.dependencies;
async function getPackagesTrans(schema, type) {
let packages = await getPackages(schema, type);
let packageDatas = [];
for (let packageItem of packages) {
let data = packageItem.data;
if (typeof packageItem.data === 'string') {
data = JSON.parse(data);
}
packageDatas.push(data);
}
return packageDatas;
}
/*=====START process =====*/
//console.log(TAG, 'start process');
......@@ -24,7 +35,7 @@ export async function divideCode(data, {debug, compile, uglify, getPackages}) {
let bProcessIDs = processIDs;
while (true) {
let newPids = await addBuiltinProcesses(builtinProcesses, bProcessIDs, getPackages, dependencies);
let newPids = await addBuiltinProcesses(builtinProcesses, bProcessIDs, getPackagesTrans, dependencies);
bProcessIDs = [];
for (let id of newPids) {
if (!processIDs.includes(id)) {
......@@ -78,7 +89,8 @@ export async function divideCode(data, {debug, compile, uglify, getPackages}) {
//let scriptsContainer = data.scripts = {};
//let scriptsCode = '';
if (scriptIDs.length > 0) {
const scripts = await getPackages(scriptIDs);
let schema = idsToSchema(scriptIDs, dependencies);
const scripts = await getPackagesTrans(schema, 2);
for (let scriptData of scripts) {
let script = typeof scriptData === 'string' ? JSON.parse(scriptData) : scriptData;
//scriptsContainer[id] = code;
......@@ -99,7 +111,8 @@ export async function divideCode(data, {debug, compile, uglify, getPackages}) {
//data.customs = [];
const customs = data.customs;
if (customs && customs.length > 0) {
let customMetas = await getPackages(customs.map(item => item.id));
let schema = idsToSchema(customs.map(item => item.id), dependencies);
let customMetas = await getPackagesTrans(schema, 3);
data.customs = customMetas.map(item => {
const custom = typeof item === 'string' ? JSON.parse(item) : item;
customManager.deal(custom);
......@@ -160,14 +173,11 @@ function findDepPidsBat(list, processes) {
}
}
async function addBuiltinProcesses(list, ids, getPackages, dependencies) {
async function addBuiltinProcesses(list, ids, getPackagesTrans, dependencies) {
let newPids = [];
let schema = {};
if (ids.length > 0) {
for(let id of ids){
schema[id] = dependencies[id];
}
let processes = await getPackages(schema);
let schema = idsToSchema(ids, dependencies);
let processes = await getPackagesTrans(schema, 1);
for (let processData of processes) {
let process = typeof processData === 'string' ? JSON.parse(processData) : processData;
list.push(process);
......@@ -185,3 +195,15 @@ function traverseNode(root, callback) {
}
}
}
function idsToSchema(ids, dependencies){
if(ids.length > 0){
let schema = {};
for (let id of ids) {
if(dependencies[id]){
schema[id] = dependencies[id];
}
}
return schema;
}
}
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