Commit 86d6f6e6 authored by rockyl's avatar rockyl

过程代码增加id注释

parent fb1e8780
...@@ -65,7 +65,7 @@ class ProcessManager { ...@@ -65,7 +65,7 @@ class ProcessManager {
} }
put(process) { put(process) {
const {id, script} = process; const {id, name, script} = process;
if (script) { if (script) {
let hash = md5(script); let hash = md5(script);
if (!this.pool.hasOwnProperty(hash)) { if (!this.pool.hasOwnProperty(hash)) {
...@@ -74,20 +74,21 @@ class ProcessManager { ...@@ -74,20 +74,21 @@ class ProcessManager {
ids: [], ids: [],
}; };
} }
this.pool[hash].ids.push(id); this.pool[hash].ids.push(name || id);
return hash; return hash;
} }
} }
async generateCurrent() { generateCurrent() {
let scripts = ''; let scripts = '';
for (let hash in this.pool) { for (let hash in this.pool) {
let {script, ids} = this.pool[hash]; let {script, ids} = this.pool[hash];
let idsComment = ids.map(id=>{return `/*== ${id} ==*/`}).join('\n');
scripts += ` scripts += `
${ids.map(id=>{return `/*== ${id} *==/\n`})}
exports['${hash}'] = function(args, props, target, global, vm){ exports['${hash}'] = function(args, props, target, global, vm){
return new Promise(function(resolve, reject){ return new Promise(function(resolve, reject){
${idsComment}
${script} ${script}
function next(type, payload){resolve({type: type, payload: payload})} function next(type, payload){resolve({type: type, payload: payload})}
...@@ -95,12 +96,13 @@ ${script} ...@@ -95,12 +96,13 @@ ${script}
}; };
`; `;
} }
this.scripts += scripts;
this.pool = {}; this.pool = {};
}
//console.log('scripts', scripts); async compile(){
try { try {
const {code ,sourcemap} = await compile(scripts, true); const {code ,sourcemap} = await compile(this.scripts, true);
this.scripts = code; this.scripts = code;
}catch (e) { }catch (e) {
console.log('编译失败', e); console.log('编译失败', e);
...@@ -108,20 +110,8 @@ ${script} ...@@ -108,20 +110,8 @@ ${script}
} }
generate() { generate() {
this.generateCurrent();
let scripts = this.scripts; let scripts = this.scripts;
for (let hash in this.pool) {
let code = this.pool[hash];
scripts += `
exports['${hash}'] = function(args, props, target, global, vm){
return new Promise(function(resolve, reject){
${code}
function next(type, payload){resolve({type: type, payload: payload})}
});
};
`;
}
return ` return `
(function(){ (function(){
...@@ -281,7 +271,9 @@ async function packData(data, {debug, getProcesses, getScripts, getCustoms}) { ...@@ -281,7 +271,9 @@ async function packData(data, {debug, getProcesses, getScripts, getCustoms}) {
} }
console.log(TAG, 'processManager.generateCurrent()'); console.log(TAG, 'processManager.generateCurrent()');
await processManager.generateCurrent(); //自定义过程先编译
processManager.generateCurrent();
await processManager.compile(); //自定义过程先编译
for (let process of builtinProcesses) { for (let process of builtinProcesses) {
processManager.deal(process); processManager.deal(process);
......
This diff is collapsed.
...@@ -71,7 +71,7 @@ class ProcessManager { ...@@ -71,7 +71,7 @@ class ProcessManager {
} }
put(process) { put(process) {
const {id, script} = process; const {id, name, script} = process;
if (script) { if (script) {
let hash = md5(script); let hash = md5(script);
if (!this.pool.hasOwnProperty(hash)) { if (!this.pool.hasOwnProperty(hash)) {
...@@ -80,20 +80,21 @@ class ProcessManager { ...@@ -80,20 +80,21 @@ class ProcessManager {
ids: [], ids: [],
}; };
} }
this.pool[hash].ids.push(id); this.pool[hash].ids.push(name || id);
return hash; return hash;
} }
} }
async generateCurrent() { generateCurrent() {
let scripts = ''; let scripts = '';
for (let hash in this.pool) { for (let hash in this.pool) {
let {script, ids} = this.pool[hash]; let {script, ids} = this.pool[hash];
let idsComment = ids.map(id=>{return `/*== ${id} ==*/`}).join('\n');
scripts += ` scripts += `
${ids.map(id=>{return `/*== ${id} *==/\n`})}
exports['${hash}'] = function(args, props, target, global, vm){ exports['${hash}'] = function(args, props, target, global, vm){
return new Promise(function(resolve, reject){ return new Promise(function(resolve, reject){
${idsComment}
${script} ${script}
function next(type, payload){resolve({type: type, payload: payload})} function next(type, payload){resolve({type: type, payload: payload})}
...@@ -101,12 +102,13 @@ ${script} ...@@ -101,12 +102,13 @@ ${script}
}; };
`; `;
} }
this.scripts += scripts;
this.pool = {}; this.pool = {};
}
//console.log('scripts', scripts); async compile(){
try { try {
const {code ,sourcemap} = await compile(scripts, true); const {code ,sourcemap} = await compile(this.scripts, true);
this.scripts = code; this.scripts = code;
}catch (e) { }catch (e) {
console.log('编译失败', e); console.log('编译失败', e);
...@@ -114,20 +116,8 @@ ${script} ...@@ -114,20 +116,8 @@ ${script}
} }
generate() { generate() {
this.generateCurrent();
let scripts = this.scripts; let scripts = this.scripts;
for (let hash in this.pool) {
let code = this.pool[hash];
scripts += `
exports['${hash}'] = function(args, props, target, global, vm){
return new Promise(function(resolve, reject){
${code}
function next(type, payload){resolve({type: type, payload: payload})}
});
};
`;
}
return ` return `
(function(){ (function(){
...@@ -287,7 +277,9 @@ async function packData(data, {debug, getProcesses, getScripts, getCustoms}) { ...@@ -287,7 +277,9 @@ async function packData(data, {debug, getProcesses, getScripts, getCustoms}) {
} }
console.log(TAG, 'processManager.generateCurrent()'); console.log(TAG, 'processManager.generateCurrent()');
await processManager.generateCurrent(); //自定义过程先编译
processManager.generateCurrent();
await processManager.compile(); //自定义过程先编译
for (let process of builtinProcesses) { for (let process of builtinProcesses) {
processManager.deal(process); processManager.deal(process);
......
This diff is collapsed.
...@@ -71,7 +71,7 @@ ...@@ -71,7 +71,7 @@
} }
put(process) { put(process) {
const {id, script} = process; const {id, name, script} = process;
if (script) { if (script) {
let hash = md5(script); let hash = md5(script);
if (!this.pool.hasOwnProperty(hash)) { if (!this.pool.hasOwnProperty(hash)) {
...@@ -80,20 +80,21 @@ ...@@ -80,20 +80,21 @@
ids: [], ids: [],
}; };
} }
this.pool[hash].ids.push(id); this.pool[hash].ids.push(name || id);
return hash; return hash;
} }
} }
async generateCurrent() { generateCurrent() {
let scripts = ''; let scripts = '';
for (let hash in this.pool) { for (let hash in this.pool) {
let {script, ids} = this.pool[hash]; let {script, ids} = this.pool[hash];
let idsComment = ids.map(id=>{return `/*== ${id} ==*/`}).join('\n');
scripts += ` scripts += `
${ids.map(id=>{return `/*== ${id} *==/\n`})}
exports['${hash}'] = function(args, props, target, global, vm){ exports['${hash}'] = function(args, props, target, global, vm){
return new Promise(function(resolve, reject){ return new Promise(function(resolve, reject){
${idsComment}
${script} ${script}
function next(type, payload){resolve({type: type, payload: payload})} function next(type, payload){resolve({type: type, payload: payload})}
...@@ -101,12 +102,13 @@ ${script} ...@@ -101,12 +102,13 @@ ${script}
}; };
`; `;
} }
this.scripts += scripts;
this.pool = {}; this.pool = {};
}
//console.log('scripts', scripts); async compile(){
try { try {
const {code ,sourcemap} = await compile(scripts, true); const {code ,sourcemap} = await compile(this.scripts, true);
this.scripts = code; this.scripts = code;
}catch (e) { }catch (e) {
console.log('编译失败', e); console.log('编译失败', e);
...@@ -114,20 +116,8 @@ ${script} ...@@ -114,20 +116,8 @@ ${script}
} }
generate() { generate() {
this.generateCurrent();
let scripts = this.scripts; let scripts = this.scripts;
for (let hash in this.pool) {
let code = this.pool[hash];
scripts += `
exports['${hash}'] = function(args, props, target, global, vm){
return new Promise(function(resolve, reject){
${code}
function next(type, payload){resolve({type: type, payload: payload})}
});
};
`;
}
return ` return `
(function(){ (function(){
...@@ -287,7 +277,9 @@ ${scripts} ...@@ -287,7 +277,9 @@ ${scripts}
} }
console.log(TAG, 'processManager.generateCurrent()'); console.log(TAG, 'processManager.generateCurrent()');
await processManager.generateCurrent(); //自定义过程先编译
processManager.generateCurrent();
await processManager.compile(); //自定义过程先编译
for (let process of builtinProcesses) { for (let process of builtinProcesses) {
processManager.deal(process); processManager.deal(process);
......
This diff is collapsed.
...@@ -32,7 +32,7 @@ export default class ProcessManager { ...@@ -32,7 +32,7 @@ export default class ProcessManager {
} }
put(process) { put(process) {
const {id, script} = process; const {id, name, script} = process;
if (script) { if (script) {
let hash = md5(script); let hash = md5(script);
if (!this.pool.hasOwnProperty(hash)) { if (!this.pool.hasOwnProperty(hash)) {
...@@ -41,20 +41,21 @@ export default class ProcessManager { ...@@ -41,20 +41,21 @@ export default class ProcessManager {
ids: [], ids: [],
}; };
} }
this.pool[hash].ids.push(id); this.pool[hash].ids.push(name || id);
return hash; return hash;
} }
} }
async generateCurrent() { generateCurrent() {
let scripts = ''; let scripts = '';
for (let hash in this.pool) { for (let hash in this.pool) {
let {script, ids} = this.pool[hash]; let {script, ids} = this.pool[hash];
let idsComment = ids.map(id=>{return `/*== ${id} ==*/`}).join('\n');
scripts += ` scripts += `
${ids.map(id=>{return `/*== ${id} *==/\n`})}
exports['${hash}'] = function(args, props, target, global, vm){ exports['${hash}'] = function(args, props, target, global, vm){
return new Promise(function(resolve, reject){ return new Promise(function(resolve, reject){
${idsComment}
${script} ${script}
function next(type, payload){resolve({type: type, payload: payload})} function next(type, payload){resolve({type: type, payload: payload})}
...@@ -62,12 +63,13 @@ ${script} ...@@ -62,12 +63,13 @@ ${script}
}; };
`; `;
} }
this.scripts += scripts;
this.pool = {}; this.pool = {};
}
//console.log('scripts', scripts); async compile(){
try { try {
const {code ,sourcemap} = await compile(scripts, true); const {code ,sourcemap} = await compile(this.scripts, true);
this.scripts = code; this.scripts = code;
}catch (e) { }catch (e) {
console.log('编译失败', e); console.log('编译失败', e);
...@@ -75,20 +77,8 @@ ${script} ...@@ -75,20 +77,8 @@ ${script}
} }
generate() { generate() {
this.generateCurrent();
let scripts = this.scripts; let scripts = this.scripts;
for (let hash in this.pool) {
let code = this.pool[hash];
scripts += `
exports['${hash}'] = function(args, props, target, global, vm){
return new Promise(function(resolve, reject){
${code}
function next(type, payload){resolve({type: type, payload: payload})}
});
};
`;
}
return ` return `
(function(){ (function(){
......
...@@ -72,7 +72,9 @@ async function packData(data, {debug, getProcesses, getScripts, getCustoms}) { ...@@ -72,7 +72,9 @@ async function packData(data, {debug, getProcesses, getScripts, getCustoms}) {
} }
console.log(TAG, 'processManager.generateCurrent()'); console.log(TAG, 'processManager.generateCurrent()');
await processManager.generateCurrent(); //自定义过程先编译
processManager.generateCurrent();
await processManager.compile(); //自定义过程先编译
for (let process of builtinProcesses) { for (let process of builtinProcesses) {
processManager.deal(process); processManager.deal(process);
......
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