Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
zeroing-code-divider
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
劳工
zeroing-code-divider
Commits
727a7e83
Commit
727a7e83
authored
Dec 20, 2019
by
rockyl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
分离代码分离器
parent
18776cf8
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
19 additions
and
7 deletions
+19
-7
index.es.js
dist/index.es.js
+4
-1
index.es.js.map
dist/index.es.js.map
+1
-1
index.js
dist/index.js
+4
-1
index.js.map
dist/index.js.map
+1
-1
index.umd.js
dist/index.umd.js
+4
-1
index.umd.js.map
dist/index.umd.js.map
+1
-1
index.js
src/index.js
+4
-1
No files found.
dist/index.es.js
View file @
727a7e83
...
...
@@ -167,6 +167,8 @@ ${scripts}
* Created by rockyl on 2019-12-20.
*/
const
TAG
=
'zeroing-code-divider'
;
async
function
divideCode
(
data
,
{
debug
,
compile
,
uglify
,
getProcesses
,
getScripts
,
getCustoms
})
{
const
processManager
=
new
ProcessManager
();
const
scriptManager
=
new
ScriptManager
();
...
...
@@ -201,7 +203,8 @@ async function divideCode(data, {debug, compile, uglify, getProcesses, getScript
let
ptScript
=
processManager
.
generateCurrent
();
if
(
compile
)
{
processManager
.
coverScripts
(
await
compile
(
ptScript
));
//自定义过程先编译
const
result
=
await
compile
(
ptScript
);
processManager
.
coverScripts
(
result
.
code
);
//自定义过程先编译
}
for
(
let
process
of
builtinProcesses
)
{
...
...
dist/index.es.js.map
View file @
727a7e83
{
"version"
:
3
,
"file"
:
"index.es.js"
,
"sources"
:
[
"../src/ProcessManager.js"
,
"../src/ScriptManager.js"
,
"../src/CustomManager.js"
,
"../src/index.js"
],
"sourcesContent"
:
[
"/**
\n
* Created by rockyl on 2019-11-29.
\n
*/
\n\n
import crypto from 'crypto'
\n\n
function md5(source) {\n
\t
const hash = crypto.createHash('md5');
\n\t
return hash.update(source).digest('hex');
\n
}
\n\n
export default class ProcessManager {\n
\t
constructor() {\n
\t\t
this.pool = {};
\n\t\t
this.scripts = '';
\n\t
}
\n\n\t
deal(process) {\n
\t\t
let hash = this.put(process);
\n\t\t
if (hash) {\n
\t\t\t
process.script = 'link://' + hash;
\n\t\t
}
\n\t\t
if (process.metas) {\n
\t\t\t
for (let subProcess of process.metas)
{
\n\t\t\t\tthis.deal(subProcess);\n\t\t\t}\n\t\t}\n\t
}
\n\n\t
put(process) {\n
\t\t
const {id, name, script} = process;
\n\t\t
if (script) {\n
\t\t\t
let hash = md5(script);
\n\t\t\t
if (!this.pool.hasOwnProperty(hash)) {\n
\t\t\t\t
this.pool[hash] = {\n
\t\t\t\t\t
script,
\n\t\t\t\t\t
ids: [],
\n\t\t\t\t
};
\n\t\t\t
}
\n\t\t\t
this.pool[hash].ids.push(`${id} - ${name}`);
\n\t\t\t
return hash;
\n\t\t
}
\n\t
}
\n\n\t
generateCurrent() {\n
\t\t
let scripts = '';
\n\t\t
for (let hash in this.pool) {\n
\t\t\t
let {script, ids} = this.pool[hash];
\n\t\t\t
let idsComment = ids.map(id => {\n
\t\t\t\t
return `/*== ${id} ==*/`
\n\t\t\t
}).join('
\\
n');
\n\t\t\t
scripts += `
\n\t
exports['${hash}'] = function(args, props, target, global, vm){\n
\t\t
return new Promise(function(resolve, reject)
{
\n\n${idsComment}\n${script
}
\n\n\t\t
function next(type, payload){resolve({type: type, payload: payload})}
\n\t\t
});
\n\t
};
\n
`;
\n\t\t
}
\n\t\t
this.scripts += scripts;
\n\t\t
this.pool = {};
\n\n\t\t
return scripts;
\n\t
}
\n\n\t
coverScripts(scripts) {\n
\t\t
this.scripts = scripts;
\n\t
}
\n\n\t
generate() {\n
\t\t
this.generateCurrent();
\n\t\t
let scripts = this.scripts;
\n\n\t\t
return `
\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\n
export default class ScriptManager {\n
\t
constructor() {\n
\t\t
this.pool = [];
\n\t
}
\n\n\t
deal(script)
{
\n\t\tthis.pool.push(script);\n\t
}
\n\n\t
generate(){\n
\t\t
let scripts = '';
\n\t\t
for(let {id, code} of this.pool){\n
\t\t\t
scripts += `
\n
/*=====START ${id} START=====*/
\n
(function(exports)
{
\n${code}\n
}
)(exports);
\n\t
engine.registerScriptDef(exports.default.id, exports.default);
\n
/*=====END ${id} END=====*/`;
\n\t\t
}
\n\n\t\t
return `
\n
(function(){\nvar exports =
{
};\n${scripts}\n})();\n`;\n\t}\n
}
\n
"
,
"/**
\n
* Created by rockyl on 2019-11-29.
\n
*/
\n\n
export default class CustomManager {\n
\t
constructor() {\n
\t\t
this.pool = [];
\n\t
}
\n\n\t
deal(custom)
{
\n\t\tthis.pool.push(custom);\n\t
}
\n\n\t
generate(){\n
\t\t
let scripts = '';
\n\t\t
for(let {id, code} of this.pool){\n
\t\t\t
scripts += `
\n
/*=====START ${id} START=====*/
\n
module = {\n
\t
exports:
{
}\n};\n(function(module){\n${code}\n})(module);\nexports['${id
}
'] = module.exports;
\n
/*=====END ${id} END=====*/`;
\n\t\t
}
\n\n\t\t
return `
\n
(function(){\nvar exports = {};
\n
var module;
\n\n
${scripts}
\n\n\t
for(var key in exports){\n
\t\t
engine.registerCustomModule(key, exports[key]);
\n\t
}
\n
})();
\n
`
\n\t
}
\n
}
\n
"
,
"/**
\n
* Created by rockyl on 2019-12-20.
\n
*/
\n\n
import ProcessManager from
\"
./ProcessManager
\"
;
\n
import ScriptManager from
\"
./ScriptManager
\"
;
\n
import CustomManager from
\"
./CustomManager
\"
;
\n\n
export async function divideCode(data, {debug, compile, uglify, getProcesses, getScripts, getCustoms}) {\n
\t
const processManager = new ProcessManager();
\n\t
const scriptManager = new ScriptManager();
\n\t
const customManager = new CustomManager();
\n\n\t
/*=====START process =====*/
\n\t
console.log(TAG, 'start process');
\n\t
let processIDs = [];
\n\t
findDepPidsBat(processIDs, data.processes);
\n\t
let builtinProcesses = data.builtinProcesses = [];
\n\n\t
let bProcessIDs = processIDs;
\n\t
while (true) {\n
\t\t
let newPids = await addBuiltinProcesses(builtinProcesses, bProcessIDs, getProcesses);
\n\t\t
bProcessIDs = [];
\n\t\t
for (let id of newPids) {\n
\t\t\t
if (!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\t
if (bProcessIDs.length === 0)
{
\n\t\t\tbreak;\n\t\t}\n\t
}
\n\n\t
for (let process of data.processes)
{
\n\t\tprocessManager.deal(process);\n\t
}
\n\n\t
console.log(TAG, 'processManager.generateCurrent()');
\n\n\t
let ptScript = processManager.generateCurrent();
\n\t
if (compile) {\n
\t\t
processManager.coverScripts(await compile(ptScript)); //自定义过程先编译
\n\t
}
\n\n\t
for (let process of builtinProcesses)
{
\n\t\tprocessManager.deal(process);\n\t
}
\n\n\t
let processScriptContent = processManager.generate();
\n\t
//console.log(processScriptContent);
\n\t
if (!debug) {\n
\t\t
processScriptContent = uglify(processScriptContent);
\n\t
}
\n\t
/*=====END process =====*/
\n\n\t
/*=====START script =====*/
\n\t
console.log(TAG, 'start script');
\n\t
let scriptIDs = [];
\n\t
for (let view of data.views) {\n
\t\t
traverseNode(view, (node) => {\n
\t\t\t
if (node.scripts && node.scripts.length > 0) {\n
\t\t\t\t
for (let
{
script
}
of node.scripts) {\n
\t\t\t\t\t
if (!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\t
if (scriptIDs.length > 0) {\n
\t\t
const scripts = await getScripts(scriptIDs);
\n\t\t
for (let scriptData of scripts) {\n
\t\t\t
let script = JSON.parse(scriptData);
\n\t\t\t
//scriptsContainer[id] = code;
\n\t\t\t
scriptManager.deal(script);
\n\t\t
}
\n\t\t
//console.log('scripts:', scriptsContainer);
\n\t
}
\n\n\t
let scriptsContent = scriptManager.generate();
\n\t
//console.log(scriptsContent);
\n\t
if (!debug) {\n
\t\t
scriptsContent = 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\t
if (data.customs && data.customs.length > 0) {\n
\t\t
/*data.customs = */
\n\t\t
(await getCustoms(data.customs)).map(item => {\n
\t\t\t
customManager.deal(JSON.parse(item));
\n\t\t\t
//return JSON.parse(item);
\n\t\t
})
\n\t
}
\n\t
let customScriptContent = customManager.generate();
\n\t
//console.log(customScriptContent);
\n\t
if (!debug) {\n
\t\t
customScriptContent = uglify(customScriptContent);
\n\t
}
\n\t
/*=====END custom =====*/
\n\n\t
return
{
\n\t\tprocessScriptContent,\n\t\tscriptsContent,\n\t\tcustomScriptContent,\n\t}\n
}
\n\n
function findDepPids(list, process) {\n
\t
if (process.sub) {\n
\t\t
for (let key in process.sub) {\n
\t\t\t
let p = process.sub[key];
\n\t\t\t
if (!list.includes(p.meta))
{
\n\t\t\t\tlist.push(p.meta);\n\t\t\t}\n\t\t}\n\t}\n
}
\n\n
function findDepPidsBat(list, processes) {\n
\t
for (let process of processes) {\n
\t\t
findDepPids(list, process);
\n\t
}
\n
}
\n\n
async function addBuiltinProcesses(list, ids, getProcesses) {\n
\t
let newPids = [];
\n\t
if (ids.length > 0) {\n
\t\t
let processes = await getProcesses(ids);
\n\t\t
for (let processData of processes) {\n
\t\t\t
let process = JSON.parse(processData);
\n\t\t\t
list.push(process);
\n\t\t\t
findDepPids(newPids, process);
\n\t\t
}
\n\t
}
\n\t
return newPids;
\n
}
\n\n
function traverseNode(root, callback) {\n
\t
callback(root);
\n\t
if (root.children && root.children.length > 0) {\n
\t\t
for (let childNode of root.children) {\n
\t\t\t
traverseNode(childNode, callback);
\n\t\t
}
\n\t
}
\n
}
\n
"
],
"names"
:
[],
"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,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACtB;GACD;EACD;;CAED,GAAG,CAAC,OAAO,EAAE;EACZ,MAAM,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC;EACnC,IAAI,MAAM,EAAE;GACX,IAAI,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC;GACvB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,E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E,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/index.js"
],
"sourcesContent"
:
[
"/**
\n
* Created by rockyl on 2019-11-29.
\n
*/
\n\n
import crypto from 'crypto'
\n\n
function md5(source) {\n
\t
const hash = crypto.createHash('md5');
\n\t
return hash.update(source).digest('hex');
\n
}
\n\n
export default class ProcessManager {\n
\t
constructor() {\n
\t\t
this.pool = {};
\n\t\t
this.scripts = '';
\n\t
}
\n\n\t
deal(process) {\n
\t\t
let hash = this.put(process);
\n\t\t
if (hash) {\n
\t\t\t
process.script = 'link://' + hash;
\n\t\t
}
\n\t\t
if (process.metas) {\n
\t\t\t
for (let subProcess of process.metas)
{
\n\t\t\t\tthis.deal(subProcess);\n\t\t\t}\n\t\t}\n\t
}
\n\n\t
put(process) {\n
\t\t
const {id, name, script} = process;
\n\t\t
if (script) {\n
\t\t\t
let hash = md5(script);
\n\t\t\t
if (!this.pool.hasOwnProperty(hash)) {\n
\t\t\t\t
this.pool[hash] = {\n
\t\t\t\t\t
script,
\n\t\t\t\t\t
ids: [],
\n\t\t\t\t
};
\n\t\t\t
}
\n\t\t\t
this.pool[hash].ids.push(`${id} - ${name}`);
\n\t\t\t
return hash;
\n\t\t
}
\n\t
}
\n\n\t
generateCurrent() {\n
\t\t
let scripts = '';
\n\t\t
for (let hash in this.pool) {\n
\t\t\t
let {script, ids} = this.pool[hash];
\n\t\t\t
let idsComment = ids.map(id => {\n
\t\t\t\t
return `/*== ${id} ==*/`
\n\t\t\t
}).join('
\\
n');
\n\t\t\t
scripts += `
\n\t
exports['${hash}'] = function(args, props, target, global, vm){\n
\t\t
return new Promise(function(resolve, reject)
{
\n\n${idsComment}\n${script
}
\n\n\t\t
function next(type, payload){resolve({type: type, payload: payload})}
\n\t\t
});
\n\t
};
\n
`;
\n\t\t
}
\n\t\t
this.scripts += scripts;
\n\t\t
this.pool = {};
\n\n\t\t
return scripts;
\n\t
}
\n\n\t
coverScripts(scripts) {\n
\t\t
this.scripts = scripts;
\n\t
}
\n\n\t
generate() {\n
\t\t
this.generateCurrent();
\n\t\t
let scripts = this.scripts;
\n\n\t\t
return `
\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\n
export default class ScriptManager {\n
\t
constructor() {\n
\t\t
this.pool = [];
\n\t
}
\n\n\t
deal(script)
{
\n\t\tthis.pool.push(script);\n\t
}
\n\n\t
generate(){\n
\t\t
let scripts = '';
\n\t\t
for(let {id, code} of this.pool){\n
\t\t\t
scripts += `
\n
/*=====START ${id} START=====*/
\n
(function(exports)
{
\n${code}\n
}
)(exports);
\n\t
engine.registerScriptDef(exports.default.id, exports.default);
\n
/*=====END ${id} END=====*/`;
\n\t\t
}
\n\n\t\t
return `
\n
(function(){\nvar exports =
{
};\n${scripts}\n})();\n`;\n\t}\n
}
\n
"
,
"/**
\n
* Created by rockyl on 2019-11-29.
\n
*/
\n\n
export default class CustomManager {\n
\t
constructor() {\n
\t\t
this.pool = [];
\n\t
}
\n\n\t
deal(custom)
{
\n\t\tthis.pool.push(custom);\n\t
}
\n\n\t
generate(){\n
\t\t
let scripts = '';
\n\t\t
for(let {id, code} of this.pool){\n
\t\t\t
scripts += `
\n
/*=====START ${id} START=====*/
\n
module = {\n
\t
exports:
{
}\n};\n(function(module){\n${code}\n})(module);\nexports['${id
}
'] = module.exports;
\n
/*=====END ${id} END=====*/`;
\n\t\t
}
\n\n\t\t
return `
\n
(function(){\nvar exports = {};
\n
var module;
\n\n
${scripts}
\n\n\t
for(var key in exports){\n
\t\t
engine.registerCustomModule(key, exports[key]);
\n\t
}
\n
})();
\n
`
\n\t
}
\n
}
\n
"
,
"/**
\n
* Created by rockyl on 2019-12-20.
\n
*/
\n\n
import ProcessManager from
\"
./ProcessManager
\"
;
\n
import ScriptManager from
\"
./ScriptManager
\"
;
\n
import CustomManager from
\"
./CustomManager
\"
;
\n\n
const TAG = 'zeroing-code-divider';
\n\n
export async function divideCode(data, {debug, compile, uglify, getProcesses, getScripts, getCustoms}) {\n
\t
const processManager = new ProcessManager();
\n\t
const scriptManager = new ScriptManager();
\n\t
const customManager = new CustomManager();
\n\n\t
/*=====START process =====*/
\n\t
console.log(TAG, 'start process');
\n\t
let processIDs = [];
\n\t
findDepPidsBat(processIDs, data.processes);
\n\t
let builtinProcesses = data.builtinProcesses = [];
\n\n\t
let bProcessIDs = processIDs;
\n\t
while (true) {\n
\t\t
let newPids = await addBuiltinProcesses(builtinProcesses, bProcessIDs, getProcesses);
\n\t\t
bProcessIDs = [];
\n\t\t
for (let id of newPids) {\n
\t\t\t
if (!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\t
if (bProcessIDs.length === 0)
{
\n\t\t\tbreak;\n\t\t}\n\t
}
\n\n\t
for (let process of data.processes)
{
\n\t\tprocessManager.deal(process);\n\t
}
\n\n\t
console.log(TAG, 'processManager.generateCurrent()');
\n\n\t
let ptScript = processManager.generateCurrent();
\n\t
if (compile) {\n
\t\t
const result = await compile(ptScript);
\n\t\t
processManager.coverScripts(result.code); //自定义过程先编译
\n\t
}
\n\n\t
for (let process of builtinProcesses)
{
\n\t\tprocessManager.deal(process);\n\t
}
\n\n\t
let processScriptContent = processManager.generate();
\n\t
//console.log(processScriptContent);
\n\t
if (!debug) {\n
\t\t
processScriptContent = uglify(processScriptContent);
\n\t
}
\n\t
/*=====END process =====*/
\n\n\t
/*=====START script =====*/
\n\t
console.log(TAG, 'start script');
\n\t
let scriptIDs = [];
\n\t
for (let view of data.views) {\n
\t\t
traverseNode(view, (node) => {\n
\t\t\t
if (node.scripts && node.scripts.length > 0) {\n
\t\t\t\t
for (let
{
script
}
of node.scripts) {\n
\t\t\t\t\t
if (!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\t
if (scriptIDs.length > 0) {\n
\t\t
const scripts = await getScripts(scriptIDs);
\n\t\t
for (let scriptData of scripts) {\n
\t\t\t
let script = JSON.parse(scriptData);
\n\t\t\t
//scriptsContainer[id] = code;
\n\t\t\t
scriptManager.deal(script);
\n\t\t
}
\n\t\t
//console.log('scripts:', scriptsContainer);
\n\t
}
\n\n\t
let scriptsContent = scriptManager.generate();
\n\t
//console.log(scriptsContent);
\n\t
if (!debug) {\n
\t\t
scriptsContent = 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\t
if (data.customs && data.customs.length > 0) {\n
\t\t
/*data.customs = */
\n\t\t
(await getCustoms(data.customs)).map(item => {\n
\t\t\t
customManager.deal(JSON.parse(item));
\n\t\t\t
//return JSON.parse(item);
\n\t\t
})
\n\t
}
\n\t
let customScriptContent = customManager.generate();
\n\t
//console.log(customScriptContent);
\n\t
if (!debug) {\n
\t\t
customScriptContent = uglify(customScriptContent);
\n\t
}
\n\t
/*=====END custom =====*/
\n\n\t
return
{
\n\t\tprocessScriptContent,\n\t\tscriptsContent,\n\t\tcustomScriptContent,\n\t}\n
}
\n\n
function findDepPids(list, process) {\n
\t
if (process.sub) {\n
\t\t
for (let key in process.sub) {\n
\t\t\t
let p = process.sub[key];
\n\t\t\t
if (!list.includes(p.meta))
{
\n\t\t\t\tlist.push(p.meta);\n\t\t\t}\n\t\t}\n\t}\n
}
\n\n
function findDepPidsBat(list, processes) {\n
\t
for (let process of processes) {\n
\t\t
findDepPids(list, process);
\n\t
}
\n
}
\n\n
async function addBuiltinProcesses(list, ids, getProcesses) {\n
\t
let newPids = [];
\n\t
if (ids.length > 0) {\n
\t\t
let processes = await getProcesses(ids);
\n\t\t
for (let processData of processes) {\n
\t\t\t
let process = JSON.parse(processData);
\n\t\t\t
list.push(process);
\n\t\t\t
findDepPids(newPids, process);
\n\t\t
}
\n\t
}
\n\t
return newPids;
\n
}
\n\n
function traverseNode(root, callback) {\n
\t
callback(root);
\n\t
if (root.children && root.children.length > 0) {\n
\t\t
for (let childNode of root.children) {\n
\t\t\t
traverseNode(childNode, callback);
\n\t\t
}
\n\t
}
\n
}
\n
"
],
"names"
:
[],
"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,GAA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,SAAS,EAAE;CACxC,KAAK,IAAI,OAAO,IAAI,SAAS,EAAE;EAC9B,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;EAC3B;CACD;;AAED,eAAe,mBAAmB,CAAC,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE;CAC3D,IAAI,OAAO,GAAG,EAAE,CAAC;CACjB,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE;EACnB,IAAI,SAAS,GAAG,MAAM,YAAY,CAAC,GAAG,CAAC,CAAC;EACxC,KAAK,IAAI,WAAW,IAAI,SAAS,EAAE;GAClC,IAAI,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;GACtC,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
dist/index.js
View file @
727a7e83
...
...
@@ -173,6 +173,8 @@ ${scripts}
* Created by rockyl on 2019-12-20.
*/
const
TAG
=
'zeroing-code-divider'
;
async
function
divideCode
(
data
,
{
debug
,
compile
,
uglify
,
getProcesses
,
getScripts
,
getCustoms
})
{
const
processManager
=
new
ProcessManager
();
const
scriptManager
=
new
ScriptManager
();
...
...
@@ -207,7 +209,8 @@ async function divideCode(data, {debug, compile, uglify, getProcesses, getScript
let
ptScript
=
processManager
.
generateCurrent
();
if
(
compile
)
{
processManager
.
coverScripts
(
await
compile
(
ptScript
));
//自定义过程先编译
const
result
=
await
compile
(
ptScript
);
processManager
.
coverScripts
(
result
.
code
);
//自定义过程先编译
}
for
(
let
process
of
builtinProcesses
)
{
...
...
dist/index.js.map
View file @
727a7e83
{
"version"
:
3
,
"file"
:
"index.js"
,
"sources"
:
[
"../src/ProcessManager.js"
,
"../src/ScriptManager.js"
,
"../src/CustomManager.js"
,
"../src/index.js"
],
"sourcesContent"
:
[
"/**
\n
* Created by rockyl on 2019-11-29.
\n
*/
\n\n
import crypto from 'crypto'
\n\n
function md5(source) {\n
\t
const hash = crypto.createHash('md5');
\n\t
return hash.update(source).digest('hex');
\n
}
\n\n
export default class ProcessManager {\n
\t
constructor() {\n
\t\t
this.pool = {};
\n\t\t
this.scripts = '';
\n\t
}
\n\n\t
deal(process) {\n
\t\t
let hash = this.put(process);
\n\t\t
if (hash) {\n
\t\t\t
process.script = 'link://' + hash;
\n\t\t
}
\n\t\t
if (process.metas) {\n
\t\t\t
for (let subProcess of process.metas)
{
\n\t\t\t\tthis.deal(subProcess);\n\t\t\t}\n\t\t}\n\t
}
\n\n\t
put(process) {\n
\t\t
const {id, name, script} = process;
\n\t\t
if (script) {\n
\t\t\t
let hash = md5(script);
\n\t\t\t
if (!this.pool.hasOwnProperty(hash)) {\n
\t\t\t\t
this.pool[hash] = {\n
\t\t\t\t\t
script,
\n\t\t\t\t\t
ids: [],
\n\t\t\t\t
};
\n\t\t\t
}
\n\t\t\t
this.pool[hash].ids.push(`${id} - ${name}`);
\n\t\t\t
return hash;
\n\t\t
}
\n\t
}
\n\n\t
generateCurrent() {\n
\t\t
let scripts = '';
\n\t\t
for (let hash in this.pool) {\n
\t\t\t
let {script, ids} = this.pool[hash];
\n\t\t\t
let idsComment = ids.map(id => {\n
\t\t\t\t
return `/*== ${id} ==*/`
\n\t\t\t
}).join('
\\
n');
\n\t\t\t
scripts += `
\n\t
exports['${hash}'] = function(args, props, target, global, vm){\n
\t\t
return new Promise(function(resolve, reject)
{
\n\n${idsComment}\n${script
}
\n\n\t\t
function next(type, payload){resolve({type: type, payload: payload})}
\n\t\t
});
\n\t
};
\n
`;
\n\t\t
}
\n\t\t
this.scripts += scripts;
\n\t\t
this.pool = {};
\n\n\t\t
return scripts;
\n\t
}
\n\n\t
coverScripts(scripts) {\n
\t\t
this.scripts = scripts;
\n\t
}
\n\n\t
generate() {\n
\t\t
this.generateCurrent();
\n\t\t
let scripts = this.scripts;
\n\n\t\t
return `
\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\n
export default class ScriptManager {\n
\t
constructor() {\n
\t\t
this.pool = [];
\n\t
}
\n\n\t
deal(script)
{
\n\t\tthis.pool.push(script);\n\t
}
\n\n\t
generate(){\n
\t\t
let scripts = '';
\n\t\t
for(let {id, code} of this.pool){\n
\t\t\t
scripts += `
\n
/*=====START ${id} START=====*/
\n
(function(exports)
{
\n${code}\n
}
)(exports);
\n\t
engine.registerScriptDef(exports.default.id, exports.default);
\n
/*=====END ${id} END=====*/`;
\n\t\t
}
\n\n\t\t
return `
\n
(function(){\nvar exports =
{
};\n${scripts}\n})();\n`;\n\t}\n
}
\n
"
,
"/**
\n
* Created by rockyl on 2019-11-29.
\n
*/
\n\n
export default class CustomManager {\n
\t
constructor() {\n
\t\t
this.pool = [];
\n\t
}
\n\n\t
deal(custom)
{
\n\t\tthis.pool.push(custom);\n\t
}
\n\n\t
generate(){\n
\t\t
let scripts = '';
\n\t\t
for(let {id, code} of this.pool){\n
\t\t\t
scripts += `
\n
/*=====START ${id} START=====*/
\n
module = {\n
\t
exports:
{
}\n};\n(function(module){\n${code}\n})(module);\nexports['${id
}
'] = module.exports;
\n
/*=====END ${id} END=====*/`;
\n\t\t
}
\n\n\t\t
return `
\n
(function(){\nvar exports = {};
\n
var module;
\n\n
${scripts}
\n\n\t
for(var key in exports){\n
\t\t
engine.registerCustomModule(key, exports[key]);
\n\t
}
\n
})();
\n
`
\n\t
}
\n
}
\n
"
,
"/**
\n
* Created by rockyl on 2019-12-20.
\n
*/
\n\n
import ProcessManager from
\"
./ProcessManager
\"
;
\n
import ScriptManager from
\"
./ScriptManager
\"
;
\n
import CustomManager from
\"
./CustomManager
\"
;
\n\n
export async function divideCode(data, {debug, compile, uglify, getProcesses, getScripts, getCustoms}) {\n
\t
const processManager = new ProcessManager();
\n\t
const scriptManager = new ScriptManager();
\n\t
const customManager = new CustomManager();
\n\n\t
/*=====START process =====*/
\n\t
console.log(TAG, 'start process');
\n\t
let processIDs = [];
\n\t
findDepPidsBat(processIDs, data.processes);
\n\t
let builtinProcesses = data.builtinProcesses = [];
\n\n\t
let bProcessIDs = processIDs;
\n\t
while (true) {\n
\t\t
let newPids = await addBuiltinProcesses(builtinProcesses, bProcessIDs, getProcesses);
\n\t\t
bProcessIDs = [];
\n\t\t
for (let id of newPids) {\n
\t\t\t
if (!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\t
if (bProcessIDs.length === 0)
{
\n\t\t\tbreak;\n\t\t}\n\t
}
\n\n\t
for (let process of data.processes)
{
\n\t\tprocessManager.deal(process);\n\t
}
\n\n\t
console.log(TAG, 'processManager.generateCurrent()');
\n\n\t
let ptScript = processManager.generateCurrent();
\n\t
if (compile) {\n
\t\t
processManager.coverScripts(await compile(ptScript)); //自定义过程先编译
\n\t
}
\n\n\t
for (let process of builtinProcesses)
{
\n\t\tprocessManager.deal(process);\n\t
}
\n\n\t
let processScriptContent = processManager.generate();
\n\t
//console.log(processScriptContent);
\n\t
if (!debug) {\n
\t\t
processScriptContent = uglify(processScriptContent);
\n\t
}
\n\t
/*=====END process =====*/
\n\n\t
/*=====START script =====*/
\n\t
console.log(TAG, 'start script');
\n\t
let scriptIDs = [];
\n\t
for (let view of data.views) {\n
\t\t
traverseNode(view, (node) => {\n
\t\t\t
if (node.scripts && node.scripts.length > 0) {\n
\t\t\t\t
for (let
{
script
}
of node.scripts) {\n
\t\t\t\t\t
if (!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\t
if (scriptIDs.length > 0) {\n
\t\t
const scripts = await getScripts(scriptIDs);
\n\t\t
for (let scriptData of scripts) {\n
\t\t\t
let script = JSON.parse(scriptData);
\n\t\t\t
//scriptsContainer[id] = code;
\n\t\t\t
scriptManager.deal(script);
\n\t\t
}
\n\t\t
//console.log('scripts:', scriptsContainer);
\n\t
}
\n\n\t
let scriptsContent = scriptManager.generate();
\n\t
//console.log(scriptsContent);
\n\t
if (!debug) {\n
\t\t
scriptsContent = 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\t
if (data.customs && data.customs.length > 0) {\n
\t\t
/*data.customs = */
\n\t\t
(await getCustoms(data.customs)).map(item => {\n
\t\t\t
customManager.deal(JSON.parse(item));
\n\t\t\t
//return JSON.parse(item);
\n\t\t
})
\n\t
}
\n\t
let customScriptContent = customManager.generate();
\n\t
//console.log(customScriptContent);
\n\t
if (!debug) {\n
\t\t
customScriptContent = uglify(customScriptContent);
\n\t
}
\n\t
/*=====END custom =====*/
\n\n\t
return
{
\n\t\tprocessScriptContent,\n\t\tscriptsContent,\n\t\tcustomScriptContent,\n\t}\n
}
\n\n
function findDepPids(list, process) {\n
\t
if (process.sub) {\n
\t\t
for (let key in process.sub) {\n
\t\t\t
let p = process.sub[key];
\n\t\t\t
if (!list.includes(p.meta))
{
\n\t\t\t\tlist.push(p.meta);\n\t\t\t}\n\t\t}\n\t}\n
}
\n\n
function findDepPidsBat(list, processes) {\n
\t
for (let process of processes) {\n
\t\t
findDepPids(list, process);
\n\t
}
\n
}
\n\n
async function addBuiltinProcesses(list, ids, getProcesses) {\n
\t
let newPids = [];
\n\t
if (ids.length > 0) {\n
\t\t
let processes = await getProcesses(ids);
\n\t\t
for (let processData of processes) {\n
\t\t\t
let process = JSON.parse(processData);
\n\t\t\t
list.push(process);
\n\t\t\t
findDepPids(newPids, process);
\n\t\t
}
\n\t
}
\n\t
return newPids;
\n
}
\n\n
function traverseNode(root, callback) {\n
\t
callback(root);
\n\t
if (root.children && root.children.length > 0) {\n
\t\t
for (let childNode of root.children) {\n
\t\t\t
traverseNode(childNode, callback);
\n\t\t
}
\n\t
}
\n
}
\n
"
],
"names"
:
[],
"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,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACtB;GACD;EACD;;CAED,GAAG,CAAC,OAAO,EAAE;EACZ,MAAM,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,OAAO,CAA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AAE;GAClC,IAAI,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;GACtC,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/index.js"
],
"sourcesContent"
:
[
"/**
\n
* Created by rockyl on 2019-11-29.
\n
*/
\n\n
import crypto from 'crypto'
\n\n
function md5(source) {\n
\t
const hash = crypto.createHash('md5');
\n\t
return hash.update(source).digest('hex');
\n
}
\n\n
export default class ProcessManager {\n
\t
constructor() {\n
\t\t
this.pool = {};
\n\t\t
this.scripts = '';
\n\t
}
\n\n\t
deal(process) {\n
\t\t
let hash = this.put(process);
\n\t\t
if (hash) {\n
\t\t\t
process.script = 'link://' + hash;
\n\t\t
}
\n\t\t
if (process.metas) {\n
\t\t\t
for (let subProcess of process.metas)
{
\n\t\t\t\tthis.deal(subProcess);\n\t\t\t}\n\t\t}\n\t
}
\n\n\t
put(process) {\n
\t\t
const {id, name, script} = process;
\n\t\t
if (script) {\n
\t\t\t
let hash = md5(script);
\n\t\t\t
if (!this.pool.hasOwnProperty(hash)) {\n
\t\t\t\t
this.pool[hash] = {\n
\t\t\t\t\t
script,
\n\t\t\t\t\t
ids: [],
\n\t\t\t\t
};
\n\t\t\t
}
\n\t\t\t
this.pool[hash].ids.push(`${id} - ${name}`);
\n\t\t\t
return hash;
\n\t\t
}
\n\t
}
\n\n\t
generateCurrent() {\n
\t\t
let scripts = '';
\n\t\t
for (let hash in this.pool) {\n
\t\t\t
let {script, ids} = this.pool[hash];
\n\t\t\t
let idsComment = ids.map(id => {\n
\t\t\t\t
return `/*== ${id} ==*/`
\n\t\t\t
}).join('
\\
n');
\n\t\t\t
scripts += `
\n\t
exports['${hash}'] = function(args, props, target, global, vm){\n
\t\t
return new Promise(function(resolve, reject)
{
\n\n${idsComment}\n${script
}
\n\n\t\t
function next(type, payload){resolve({type: type, payload: payload})}
\n\t\t
});
\n\t
};
\n
`;
\n\t\t
}
\n\t\t
this.scripts += scripts;
\n\t\t
this.pool = {};
\n\n\t\t
return scripts;
\n\t
}
\n\n\t
coverScripts(scripts) {\n
\t\t
this.scripts = scripts;
\n\t
}
\n\n\t
generate() {\n
\t\t
this.generateCurrent();
\n\t\t
let scripts = this.scripts;
\n\n\t\t
return `
\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\n
export default class ScriptManager {\n
\t
constructor() {\n
\t\t
this.pool = [];
\n\t
}
\n\n\t
deal(script)
{
\n\t\tthis.pool.push(script);\n\t
}
\n\n\t
generate(){\n
\t\t
let scripts = '';
\n\t\t
for(let {id, code} of this.pool){\n
\t\t\t
scripts += `
\n
/*=====START ${id} START=====*/
\n
(function(exports)
{
\n${code}\n
}
)(exports);
\n\t
engine.registerScriptDef(exports.default.id, exports.default);
\n
/*=====END ${id} END=====*/`;
\n\t\t
}
\n\n\t\t
return `
\n
(function(){\nvar exports =
{
};\n${scripts}\n})();\n`;\n\t}\n
}
\n
"
,
"/**
\n
* Created by rockyl on 2019-11-29.
\n
*/
\n\n
export default class CustomManager {\n
\t
constructor() {\n
\t\t
this.pool = [];
\n\t
}
\n\n\t
deal(custom)
{
\n\t\tthis.pool.push(custom);\n\t
}
\n\n\t
generate(){\n
\t\t
let scripts = '';
\n\t\t
for(let {id, code} of this.pool){\n
\t\t\t
scripts += `
\n
/*=====START ${id} START=====*/
\n
module = {\n
\t
exports:
{
}\n};\n(function(module){\n${code}\n})(module);\nexports['${id
}
'] = module.exports;
\n
/*=====END ${id} END=====*/`;
\n\t\t
}
\n\n\t\t
return `
\n
(function(){\nvar exports = {};
\n
var module;
\n\n
${scripts}
\n\n\t
for(var key in exports){\n
\t\t
engine.registerCustomModule(key, exports[key]);
\n\t
}
\n
})();
\n
`
\n\t
}
\n
}
\n
"
,
"/**
\n
* Created by rockyl on 2019-12-20.
\n
*/
\n\n
import ProcessManager from
\"
./ProcessManager
\"
;
\n
import ScriptManager from
\"
./ScriptManager
\"
;
\n
import CustomManager from
\"
./CustomManager
\"
;
\n\n
const TAG = 'zeroing-code-divider';
\n\n
export async function divideCode(data, {debug, compile, uglify, getProcesses, getScripts, getCustoms}) {\n
\t
const processManager = new ProcessManager();
\n\t
const scriptManager = new ScriptManager();
\n\t
const customManager = new CustomManager();
\n\n\t
/*=====START process =====*/
\n\t
console.log(TAG, 'start process');
\n\t
let processIDs = [];
\n\t
findDepPidsBat(processIDs, data.processes);
\n\t
let builtinProcesses = data.builtinProcesses = [];
\n\n\t
let bProcessIDs = processIDs;
\n\t
while (true) {\n
\t\t
let newPids = await addBuiltinProcesses(builtinProcesses, bProcessIDs, getProcesses);
\n\t\t
bProcessIDs = [];
\n\t\t
for (let id of newPids) {\n
\t\t\t
if (!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\t
if (bProcessIDs.length === 0)
{
\n\t\t\tbreak;\n\t\t}\n\t
}
\n\n\t
for (let process of data.processes)
{
\n\t\tprocessManager.deal(process);\n\t
}
\n\n\t
console.log(TAG, 'processManager.generateCurrent()');
\n\n\t
let ptScript = processManager.generateCurrent();
\n\t
if (compile) {\n
\t\t
const result = await compile(ptScript);
\n\t\t
processManager.coverScripts(result.code); //自定义过程先编译
\n\t
}
\n\n\t
for (let process of builtinProcesses)
{
\n\t\tprocessManager.deal(process);\n\t
}
\n\n\t
let processScriptContent = processManager.generate();
\n\t
//console.log(processScriptContent);
\n\t
if (!debug) {\n
\t\t
processScriptContent = uglify(processScriptContent);
\n\t
}
\n\t
/*=====END process =====*/
\n\n\t
/*=====START script =====*/
\n\t
console.log(TAG, 'start script');
\n\t
let scriptIDs = [];
\n\t
for (let view of data.views) {\n
\t\t
traverseNode(view, (node) => {\n
\t\t\t
if (node.scripts && node.scripts.length > 0) {\n
\t\t\t\t
for (let
{
script
}
of node.scripts) {\n
\t\t\t\t\t
if (!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\t
if (scriptIDs.length > 0) {\n
\t\t
const scripts = await getScripts(scriptIDs);
\n\t\t
for (let scriptData of scripts) {\n
\t\t\t
let script = JSON.parse(scriptData);
\n\t\t\t
//scriptsContainer[id] = code;
\n\t\t\t
scriptManager.deal(script);
\n\t\t
}
\n\t\t
//console.log('scripts:', scriptsContainer);
\n\t
}
\n\n\t
let scriptsContent = scriptManager.generate();
\n\t
//console.log(scriptsContent);
\n\t
if (!debug) {\n
\t\t
scriptsContent = 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\t
if (data.customs && data.customs.length > 0) {\n
\t\t
/*data.customs = */
\n\t\t
(await getCustoms(data.customs)).map(item => {\n
\t\t\t
customManager.deal(JSON.parse(item));
\n\t\t\t
//return JSON.parse(item);
\n\t\t
})
\n\t
}
\n\t
let customScriptContent = customManager.generate();
\n\t
//console.log(customScriptContent);
\n\t
if (!debug) {\n
\t\t
customScriptContent = uglify(customScriptContent);
\n\t
}
\n\t
/*=====END custom =====*/
\n\n\t
return
{
\n\t\tprocessScriptContent,\n\t\tscriptsContent,\n\t\tcustomScriptContent,\n\t}\n
}
\n\n
function findDepPids(list, process) {\n
\t
if (process.sub) {\n
\t\t
for (let key in process.sub) {\n
\t\t\t
let p = process.sub[key];
\n\t\t\t
if (!list.includes(p.meta))
{
\n\t\t\t\tlist.push(p.meta);\n\t\t\t}\n\t\t}\n\t}\n
}
\n\n
function findDepPidsBat(list, processes) {\n
\t
for (let process of processes) {\n
\t\t
findDepPids(list, process);
\n\t
}
\n
}
\n\n
async function addBuiltinProcesses(list, ids, getProcesses) {\n
\t
let newPids = [];
\n\t
if (ids.length > 0) {\n
\t\t
let processes = await getProcesses(ids);
\n\t\t
for (let processData of processes) {\n
\t\t\t
let process = JSON.parse(processData);
\n\t\t\t
list.push(process);
\n\t\t\t
findDepPids(newPids, process);
\n\t\t
}
\n\t
}
\n\t
return newPids;
\n
}
\n\n
function traverseNode(root, callback) {\n
\t
callback(root);
\n\t
if (root.children && root.children.length > 0) {\n
\t\t
for (let childNode of root.children) {\n
\t\t\t
traverseNode(childNode, callback);
\n\t\t
}
\n\t
}
\n
}
\n
"
],
"names"
:
[],
"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,I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AAC,CAAC,CAAC,IAAI,CAAC,EAAE;IAC3B,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAClB;GACD;EACD;CACD;;AAED,SAAS,cAAc,CAAC,IAAI,EAAE,SAAS,EAAE;CACxC,KAAK,IAAI,OAAO,IAAI,SAAS,EAAE;EAC9B,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;EAC3B;CACD;;AAED,eAAe,mBAAmB,CAAC,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE;CAC3D,IAAI,OAAO,GAAG,EAAE,CAAC;CACjB,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE;EACnB,IAAI,SAAS,GAAG,MAAM,YAAY,CAAC,GAAG,CAAC,CAAC;EACxC,KAAK,IAAI,WAAW,IAAI,SAAS,EAAE;GAClC,IAAI,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;GACtC,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
dist/index.umd.js
View file @
727a7e83
...
...
@@ -173,6 +173,8 @@ ${scripts}
* Created by rockyl on 2019-12-20.
*/
const
TAG
=
'zeroing-code-divider'
;
async
function
divideCode
(
data
,
{
debug
,
compile
,
uglify
,
getProcesses
,
getScripts
,
getCustoms
})
{
const
processManager
=
new
ProcessManager
();
const
scriptManager
=
new
ScriptManager
();
...
...
@@ -207,7 +209,8 @@ ${scripts}
let
ptScript
=
processManager
.
generateCurrent
();
if
(
compile
)
{
processManager
.
coverScripts
(
await
compile
(
ptScript
));
//自定义过程先编译
const
result
=
await
compile
(
ptScript
);
processManager
.
coverScripts
(
result
.
code
);
//自定义过程先编译
}
for
(
let
process
of
builtinProcesses
)
{
...
...
dist/index.umd.js.map
View file @
727a7e83
{
"version"
:
3
,
"file"
:
"index.umd.js"
,
"sources"
:
[
"../src/ProcessManager.js"
,
"../src/ScriptManager.js"
,
"../src/CustomManager.js"
,
"../src/index.js"
],
"sourcesContent"
:
[
"/**
\n
* Created by rockyl on 2019-11-29.
\n
*/
\n\n
import crypto from 'crypto'
\n\n
function md5(source) {\n
\t
const hash = crypto.createHash('md5');
\n\t
return hash.update(source).digest('hex');
\n
}
\n\n
export default class ProcessManager {\n
\t
constructor() {\n
\t\t
this.pool = {};
\n\t\t
this.scripts = '';
\n\t
}
\n\n\t
deal(process) {\n
\t\t
let hash = this.put(process);
\n\t\t
if (hash) {\n
\t\t\t
process.script = 'link://' + hash;
\n\t\t
}
\n\t\t
if (process.metas) {\n
\t\t\t
for (let subProcess of process.metas)
{
\n\t\t\t\tthis.deal(subProcess);\n\t\t\t}\n\t\t}\n\t
}
\n\n\t
put(process) {\n
\t\t
const {id, name, script} = process;
\n\t\t
if (script) {\n
\t\t\t
let hash = md5(script);
\n\t\t\t
if (!this.pool.hasOwnProperty(hash)) {\n
\t\t\t\t
this.pool[hash] = {\n
\t\t\t\t\t
script,
\n\t\t\t\t\t
ids: [],
\n\t\t\t\t
};
\n\t\t\t
}
\n\t\t\t
this.pool[hash].ids.push(`${id} - ${name}`);
\n\t\t\t
return hash;
\n\t\t
}
\n\t
}
\n\n\t
generateCurrent() {\n
\t\t
let scripts = '';
\n\t\t
for (let hash in this.pool) {\n
\t\t\t
let {script, ids} = this.pool[hash];
\n\t\t\t
let idsComment = ids.map(id => {\n
\t\t\t\t
return `/*== ${id} ==*/`
\n\t\t\t
}).join('
\\
n');
\n\t\t\t
scripts += `
\n\t
exports['${hash}'] = function(args, props, target, global, vm){\n
\t\t
return new Promise(function(resolve, reject)
{
\n\n${idsComment}\n${script
}
\n\n\t\t
function next(type, payload){resolve({type: type, payload: payload})}
\n\t\t
});
\n\t
};
\n
`;
\n\t\t
}
\n\t\t
this.scripts += scripts;
\n\t\t
this.pool = {};
\n\n\t\t
return scripts;
\n\t
}
\n\n\t
coverScripts(scripts) {\n
\t\t
this.scripts = scripts;
\n\t
}
\n\n\t
generate() {\n
\t\t
this.generateCurrent();
\n\t\t
let scripts = this.scripts;
\n\n\t\t
return `
\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\n
export default class ScriptManager {\n
\t
constructor() {\n
\t\t
this.pool = [];
\n\t
}
\n\n\t
deal(script)
{
\n\t\tthis.pool.push(script);\n\t
}
\n\n\t
generate(){\n
\t\t
let scripts = '';
\n\t\t
for(let {id, code} of this.pool){\n
\t\t\t
scripts += `
\n
/*=====START ${id} START=====*/
\n
(function(exports)
{
\n${code}\n
}
)(exports);
\n\t
engine.registerScriptDef(exports.default.id, exports.default);
\n
/*=====END ${id} END=====*/`;
\n\t\t
}
\n\n\t\t
return `
\n
(function(){\nvar exports =
{
};\n${scripts}\n})();\n`;\n\t}\n
}
\n
"
,
"/**
\n
* Created by rockyl on 2019-11-29.
\n
*/
\n\n
export default class CustomManager {\n
\t
constructor() {\n
\t\t
this.pool = [];
\n\t
}
\n\n\t
deal(custom)
{
\n\t\tthis.pool.push(custom);\n\t
}
\n\n\t
generate(){\n
\t\t
let scripts = '';
\n\t\t
for(let {id, code} of this.pool){\n
\t\t\t
scripts += `
\n
/*=====START ${id} START=====*/
\n
module = {\n
\t
exports:
{
}\n};\n(function(module){\n${code}\n})(module);\nexports['${id
}
'] = module.exports;
\n
/*=====END ${id} END=====*/`;
\n\t\t
}
\n\n\t\t
return `
\n
(function(){\nvar exports = {};
\n
var module;
\n\n
${scripts}
\n\n\t
for(var key in exports){\n
\t\t
engine.registerCustomModule(key, exports[key]);
\n\t
}
\n
})();
\n
`
\n\t
}
\n
}
\n
"
,
"/**
\n
* Created by rockyl on 2019-12-20.
\n
*/
\n\n
import ProcessManager from
\"
./ProcessManager
\"
;
\n
import ScriptManager from
\"
./ScriptManager
\"
;
\n
import CustomManager from
\"
./CustomManager
\"
;
\n\n
export async function divideCode(data, {debug, compile, uglify, getProcesses, getScripts, getCustoms}) {\n
\t
const processManager = new ProcessManager();
\n\t
const scriptManager = new ScriptManager();
\n\t
const customManager = new CustomManager();
\n\n\t
/*=====START process =====*/
\n\t
console.log(TAG, 'start process');
\n\t
let processIDs = [];
\n\t
findDepPidsBat(processIDs, data.processes);
\n\t
let builtinProcesses = data.builtinProcesses = [];
\n\n\t
let bProcessIDs = processIDs;
\n\t
while (true) {\n
\t\t
let newPids = await addBuiltinProcesses(builtinProcesses, bProcessIDs, getProcesses);
\n\t\t
bProcessIDs = [];
\n\t\t
for (let id of newPids) {\n
\t\t\t
if (!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\t
if (bProcessIDs.length === 0)
{
\n\t\t\tbreak;\n\t\t}\n\t
}
\n\n\t
for (let process of data.processes)
{
\n\t\tprocessManager.deal(process);\n\t
}
\n\n\t
console.log(TAG, 'processManager.generateCurrent()');
\n\n\t
let ptScript = processManager.generateCurrent();
\n\t
if (compile) {\n
\t\t
processManager.coverScripts(await compile(ptScript)); //自定义过程先编译
\n\t
}
\n\n\t
for (let process of builtinProcesses)
{
\n\t\tprocessManager.deal(process);\n\t
}
\n\n\t
let processScriptContent = processManager.generate();
\n\t
//console.log(processScriptContent);
\n\t
if (!debug) {\n
\t\t
processScriptContent = uglify(processScriptContent);
\n\t
}
\n\t
/*=====END process =====*/
\n\n\t
/*=====START script =====*/
\n\t
console.log(TAG, 'start script');
\n\t
let scriptIDs = [];
\n\t
for (let view of data.views) {\n
\t\t
traverseNode(view, (node) => {\n
\t\t\t
if (node.scripts && node.scripts.length > 0) {\n
\t\t\t\t
for (let
{
script
}
of node.scripts) {\n
\t\t\t\t\t
if (!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\t
if (scriptIDs.length > 0) {\n
\t\t
const scripts = await getScripts(scriptIDs);
\n\t\t
for (let scriptData of scripts) {\n
\t\t\t
let script = JSON.parse(scriptData);
\n\t\t\t
//scriptsContainer[id] = code;
\n\t\t\t
scriptManager.deal(script);
\n\t\t
}
\n\t\t
//console.log('scripts:', scriptsContainer);
\n\t
}
\n\n\t
let scriptsContent = scriptManager.generate();
\n\t
//console.log(scriptsContent);
\n\t
if (!debug) {\n
\t\t
scriptsContent = 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\t
if (data.customs && data.customs.length > 0) {\n
\t\t
/*data.customs = */
\n\t\t
(await getCustoms(data.customs)).map(item => {\n
\t\t\t
customManager.deal(JSON.parse(item));
\n\t\t\t
//return JSON.parse(item);
\n\t\t
})
\n\t
}
\n\t
let customScriptContent = customManager.generate();
\n\t
//console.log(customScriptContent);
\n\t
if (!debug) {\n
\t\t
customScriptContent = uglify(customScriptContent);
\n\t
}
\n\t
/*=====END custom =====*/
\n\n\t
return
{
\n\t\tprocessScriptContent,\n\t\tscriptsContent,\n\t\tcustomScriptContent,\n\t}\n
}
\n\n
function findDepPids(list, process) {\n
\t
if (process.sub) {\n
\t\t
for (let key in process.sub) {\n
\t\t\t
let p = process.sub[key];
\n\t\t\t
if (!list.includes(p.meta))
{
\n\t\t\t\tlist.push(p.meta);\n\t\t\t}\n\t\t}\n\t}\n
}
\n\n
function findDepPidsBat(list, processes) {\n
\t
for (let process of processes) {\n
\t\t
findDepPids(list, process);
\n\t
}
\n
}
\n\n
async function addBuiltinProcesses(list, ids, getProcesses) {\n
\t
let newPids = [];
\n\t
if (ids.length > 0) {\n
\t\t
let processes = await getProcesses(ids);
\n\t\t
for (let processData of processes) {\n
\t\t\t
let process = JSON.parse(processData);
\n\t\t\t
list.push(process);
\n\t\t\t
findDepPids(newPids, process);
\n\t\t
}
\n\t
}
\n\t
return newPids;
\n
}
\n\n
function traverseNode(root, callback) {\n
\t
callback(root);
\n\t
if (root.children && root.children.length > 0) {\n
\t\t
for (let childNode of root.children) {\n
\t\t\t
traverseNode(childNode, callback);
\n\t\t
}
\n\t
}
\n
}
\n
"
],
"names"
:
[],
"mappings"
:
";;;;;;;;CAAA;CACA;CACA;AACA,AAEA;CACA,SAAS,GAAG,CAAC,MAAM,EAAE;CACrB,CAAC,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;CACvC,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;CAC1C,CAAC;;AAED,CAAe,MAAM,cAAc,CAAC;CACpC,CAAC,WAAW,GAAG;CACf,EAAE,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;CACjB,EAAE,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;CACpB,EAAE;;CAEF,CAAC,IAAI,CAAC,OAAO,EAAE;CACf,EAAE,IAAI,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;CAC/B,EAAE,IAAI,IAAI,EAAE;CACZ,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;CACrC,GAAG;CACH,EAAE,IAAI,OAAO,CAAC,KAAK,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MAAM,YAAY,CAAC,GAAG,CAAC,CAAC;CAC1C,EAAE,KAAK,IAAI,WAAW,IAAI,SAAS,EAAE;CACrC,GAAG,IAAI,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;CACzC,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;CACtB,GAAG,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;CACjC,GAAG;CACH,EAAE;CACF,CAAC,OAAO,OAAO,CAAC;CAChB,CAAC;;CAED,SAAS,YAAY,CAAC,IAAI,EAAE,QAAQ,EAAE;CACtC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;CAChB,CAAC,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;CAChD,EAAE,KAAK,IAAI,SAAS,IAAI,IAAI,CAAC,QAAQ,EAAE;CACvC,GAAG,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/index.js"
],
"sourcesContent"
:
[
"/**
\n
* Created by rockyl on 2019-11-29.
\n
*/
\n\n
import crypto from 'crypto'
\n\n
function md5(source) {\n
\t
const hash = crypto.createHash('md5');
\n\t
return hash.update(source).digest('hex');
\n
}
\n\n
export default class ProcessManager {\n
\t
constructor() {\n
\t\t
this.pool = {};
\n\t\t
this.scripts = '';
\n\t
}
\n\n\t
deal(process) {\n
\t\t
let hash = this.put(process);
\n\t\t
if (hash) {\n
\t\t\t
process.script = 'link://' + hash;
\n\t\t
}
\n\t\t
if (process.metas) {\n
\t\t\t
for (let subProcess of process.metas)
{
\n\t\t\t\tthis.deal(subProcess);\n\t\t\t}\n\t\t}\n\t
}
\n\n\t
put(process) {\n
\t\t
const {id, name, script} = process;
\n\t\t
if (script) {\n
\t\t\t
let hash = md5(script);
\n\t\t\t
if (!this.pool.hasOwnProperty(hash)) {\n
\t\t\t\t
this.pool[hash] = {\n
\t\t\t\t\t
script,
\n\t\t\t\t\t
ids: [],
\n\t\t\t\t
};
\n\t\t\t
}
\n\t\t\t
this.pool[hash].ids.push(`${id} - ${name}`);
\n\t\t\t
return hash;
\n\t\t
}
\n\t
}
\n\n\t
generateCurrent() {\n
\t\t
let scripts = '';
\n\t\t
for (let hash in this.pool) {\n
\t\t\t
let {script, ids} = this.pool[hash];
\n\t\t\t
let idsComment = ids.map(id => {\n
\t\t\t\t
return `/*== ${id} ==*/`
\n\t\t\t
}).join('
\\
n');
\n\t\t\t
scripts += `
\n\t
exports['${hash}'] = function(args, props, target, global, vm){\n
\t\t
return new Promise(function(resolve, reject)
{
\n\n${idsComment}\n${script
}
\n\n\t\t
function next(type, payload){resolve({type: type, payload: payload})}
\n\t\t
});
\n\t
};
\n
`;
\n\t\t
}
\n\t\t
this.scripts += scripts;
\n\t\t
this.pool = {};
\n\n\t\t
return scripts;
\n\t
}
\n\n\t
coverScripts(scripts) {\n
\t\t
this.scripts = scripts;
\n\t
}
\n\n\t
generate() {\n
\t\t
this.generateCurrent();
\n\t\t
let scripts = this.scripts;
\n\n\t\t
return `
\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\n
export default class ScriptManager {\n
\t
constructor() {\n
\t\t
this.pool = [];
\n\t
}
\n\n\t
deal(script)
{
\n\t\tthis.pool.push(script);\n\t
}
\n\n\t
generate(){\n
\t\t
let scripts = '';
\n\t\t
for(let {id, code} of this.pool){\n
\t\t\t
scripts += `
\n
/*=====START ${id} START=====*/
\n
(function(exports)
{
\n${code}\n
}
)(exports);
\n\t
engine.registerScriptDef(exports.default.id, exports.default);
\n
/*=====END ${id} END=====*/`;
\n\t\t
}
\n\n\t\t
return `
\n
(function(){\nvar exports =
{
};\n${scripts}\n})();\n`;\n\t}\n
}
\n
"
,
"/**
\n
* Created by rockyl on 2019-11-29.
\n
*/
\n\n
export default class CustomManager {\n
\t
constructor() {\n
\t\t
this.pool = [];
\n\t
}
\n\n\t
deal(custom)
{
\n\t\tthis.pool.push(custom);\n\t
}
\n\n\t
generate(){\n
\t\t
let scripts = '';
\n\t\t
for(let {id, code} of this.pool){\n
\t\t\t
scripts += `
\n
/*=====START ${id} START=====*/
\n
module = {\n
\t
exports:
{
}\n};\n(function(module){\n${code}\n})(module);\nexports['${id
}
'] = module.exports;
\n
/*=====END ${id} END=====*/`;
\n\t\t
}
\n\n\t\t
return `
\n
(function(){\nvar exports = {};
\n
var module;
\n\n
${scripts}
\n\n\t
for(var key in exports){\n
\t\t
engine.registerCustomModule(key, exports[key]);
\n\t
}
\n
})();
\n
`
\n\t
}
\n
}
\n
"
,
"/**
\n
* Created by rockyl on 2019-12-20.
\n
*/
\n\n
import ProcessManager from
\"
./ProcessManager
\"
;
\n
import ScriptManager from
\"
./ScriptManager
\"
;
\n
import CustomManager from
\"
./CustomManager
\"
;
\n\n
const TAG = 'zeroing-code-divider';
\n\n
export async function divideCode(data, {debug, compile, uglify, getProcesses, getScripts, getCustoms}) {\n
\t
const processManager = new ProcessManager();
\n\t
const scriptManager = new ScriptManager();
\n\t
const customManager = new CustomManager();
\n\n\t
/*=====START process =====*/
\n\t
console.log(TAG, 'start process');
\n\t
let processIDs = [];
\n\t
findDepPidsBat(processIDs, data.processes);
\n\t
let builtinProcesses = data.builtinProcesses = [];
\n\n\t
let bProcessIDs = processIDs;
\n\t
while (true) {\n
\t\t
let newPids = await addBuiltinProcesses(builtinProcesses, bProcessIDs, getProcesses);
\n\t\t
bProcessIDs = [];
\n\t\t
for (let id of newPids) {\n
\t\t\t
if (!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\t
if (bProcessIDs.length === 0)
{
\n\t\t\tbreak;\n\t\t}\n\t
}
\n\n\t
for (let process of data.processes)
{
\n\t\tprocessManager.deal(process);\n\t
}
\n\n\t
console.log(TAG, 'processManager.generateCurrent()');
\n\n\t
let ptScript = processManager.generateCurrent();
\n\t
if (compile) {\n
\t\t
const result = await compile(ptScript);
\n\t\t
processManager.coverScripts(result.code); //自定义过程先编译
\n\t
}
\n\n\t
for (let process of builtinProcesses)
{
\n\t\tprocessManager.deal(process);\n\t
}
\n\n\t
let processScriptContent = processManager.generate();
\n\t
//console.log(processScriptContent);
\n\t
if (!debug) {\n
\t\t
processScriptContent = uglify(processScriptContent);
\n\t
}
\n\t
/*=====END process =====*/
\n\n\t
/*=====START script =====*/
\n\t
console.log(TAG, 'start script');
\n\t
let scriptIDs = [];
\n\t
for (let view of data.views) {\n
\t\t
traverseNode(view, (node) => {\n
\t\t\t
if (node.scripts && node.scripts.length > 0) {\n
\t\t\t\t
for (let
{
script
}
of node.scripts) {\n
\t\t\t\t\t
if (!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\t
if (scriptIDs.length > 0) {\n
\t\t
const scripts = await getScripts(scriptIDs);
\n\t\t
for (let scriptData of scripts) {\n
\t\t\t
let script = JSON.parse(scriptData);
\n\t\t\t
//scriptsContainer[id] = code;
\n\t\t\t
scriptManager.deal(script);
\n\t\t
}
\n\t\t
//console.log('scripts:', scriptsContainer);
\n\t
}
\n\n\t
let scriptsContent = scriptManager.generate();
\n\t
//console.log(scriptsContent);
\n\t
if (!debug) {\n
\t\t
scriptsContent = 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\t
if (data.customs && data.customs.length > 0) {\n
\t\t
/*data.customs = */
\n\t\t
(await getCustoms(data.customs)).map(item => {\n
\t\t\t
customManager.deal(JSON.parse(item));
\n\t\t\t
//return JSON.parse(item);
\n\t\t
})
\n\t
}
\n\t
let customScriptContent = customManager.generate();
\n\t
//console.log(customScriptContent);
\n\t
if (!debug) {\n
\t\t
customScriptContent = uglify(customScriptContent);
\n\t
}
\n\t
/*=====END custom =====*/
\n\n\t
return
{
\n\t\tprocessScriptContent,\n\t\tscriptsContent,\n\t\tcustomScriptContent,\n\t}\n
}
\n\n
function findDepPids(list, process) {\n
\t
if (process.sub) {\n
\t\t
for (let key in process.sub) {\n
\t\t\t
let p = process.sub[key];
\n\t\t\t
if (!list.includes(p.meta))
{
\n\t\t\t\tlist.push(p.meta);\n\t\t\t}\n\t\t}\n\t}\n
}
\n\n
function findDepPidsBat(list, processes) {\n
\t
for (let process of processes) {\n
\t\t
findDepPids(list, process);
\n\t
}
\n
}
\n\n
async function addBuiltinProcesses(list, ids, getProcesses) {\n
\t
let newPids = [];
\n\t
if (ids.length > 0) {\n
\t\t
let processes = await getProcesses(ids);
\n\t\t
for (let processData of processes) {\n
\t\t\t
let process = JSON.parse(processData);
\n\t\t\t
list.push(process);
\n\t\t\t
findDepPids(newPids, process);
\n\t\t
}
\n\t
}
\n\t
return newPids;
\n
}
\n\n
function traverseNode(root, callback) {\n
\t
callback(root);
\n\t
if (root.children && root.children.length > 0) {\n
\t\t
for (let childNode of root.children) {\n
\t\t\t
traverseNode(childNode, callback);
\n\t\t
}
\n\t
}
\n
}
\n
"
],
"names"
:
[],
"mappings"
:
";;;;;;;;CAAA;CACA;CACA;AACA,AAEA;CACA,SAAS,GAAG,CAAC,MAAM,EAAE;CACrB,CAAC,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;CACvC,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,M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;;;;;;;;;"
}
\ No newline at end of file
src/index.js
View file @
727a7e83
...
...
@@ -6,6 +6,8 @@ import ProcessManager from "./ProcessManager";
import
ScriptManager
from
"./ScriptManager"
;
import
CustomManager
from
"./CustomManager"
;
const
TAG
=
'zeroing-code-divider'
;
export
async
function
divideCode
(
data
,
{
debug
,
compile
,
uglify
,
getProcesses
,
getScripts
,
getCustoms
})
{
const
processManager
=
new
ProcessManager
();
const
scriptManager
=
new
ScriptManager
();
...
...
@@ -40,7 +42,8 @@ export async function divideCode(data, {debug, compile, uglify, getProcesses, ge
let
ptScript
=
processManager
.
generateCurrent
();
if
(
compile
)
{
processManager
.
coverScripts
(
await
compile
(
ptScript
));
//自定义过程先编译
const
result
=
await
compile
(
ptScript
);
processManager
.
coverScripts
(
result
.
code
);
//自定义过程先编译
}
for
(
let
process
of
builtinProcesses
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment