Commit 2ab6ba47 authored by rockyl's avatar rockyl

增加zeroing-template-fill

parent 0cb1266f
...@@ -188,12 +188,23 @@ ${scripts} ...@@ -188,12 +188,23 @@ ${scripts}
* Created by rockyl on 2019-12-20. * 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 processManager = new ProcessManager();
const scriptManager = new ScriptManager(); const scriptManager = new ScriptManager();
const customManager = new CustomManager(); 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 =====*/ /*=====START process =====*/
//console.log(TAG, 'start process'); //console.log(TAG, 'start process');
...@@ -203,7 +214,7 @@ async function divideCode(data, {debug, compile, uglify, getPackages}) { ...@@ -203,7 +214,7 @@ async function divideCode(data, {debug, compile, uglify, getPackages}) {
let bProcessIDs = processIDs; let bProcessIDs = processIDs;
while (true) { while (true) {
let newPids = await addBuiltinProcesses(builtinProcesses, bProcessIDs, getPackages, dependencies); let newPids = await addBuiltinProcesses(builtinProcesses, bProcessIDs, getPackagesTrans, dependencies);
bProcessIDs = []; bProcessIDs = [];
for (let id of newPids) { for (let id of newPids) {
if (!processIDs.includes(id)) { if (!processIDs.includes(id)) {
...@@ -257,7 +268,8 @@ async function divideCode(data, {debug, compile, uglify, getPackages}) { ...@@ -257,7 +268,8 @@ async function divideCode(data, {debug, compile, uglify, getPackages}) {
//let scriptsContainer = data.scripts = {}; //let scriptsContainer = data.scripts = {};
//let scriptsCode = ''; //let scriptsCode = '';
if (scriptIDs.length > 0) { 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) { for (let scriptData of scripts) {
let script = typeof scriptData === 'string' ? JSON.parse(scriptData) : scriptData; let script = typeof scriptData === 'string' ? JSON.parse(scriptData) : scriptData;
//scriptsContainer[id] = code; //scriptsContainer[id] = code;
...@@ -278,7 +290,8 @@ async function divideCode(data, {debug, compile, uglify, getPackages}) { ...@@ -278,7 +290,8 @@ async function divideCode(data, {debug, compile, uglify, getPackages}) {
//data.customs = []; //data.customs = [];
const customs = data.customs; const customs = data.customs;
if (customs && customs.length > 0) { 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 => { data.customs = customMetas.map(item => {
const custom = typeof item === 'string' ? JSON.parse(item) : item; const custom = typeof item === 'string' ? JSON.parse(item) : item;
customManager.deal(custom); customManager.deal(custom);
...@@ -339,14 +352,11 @@ function findDepPidsBat(list, processes) { ...@@ -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 newPids = [];
let schema = {};
if (ids.length > 0) { if (ids.length > 0) {
for(let id of ids){ let schema = idsToSchema(ids, dependencies);
schema[id] = dependencies[id]; let processes = await getPackagesTrans(schema, 1);
}
let processes = await getPackages(schema);
for (let processData of processes) { for (let processData of processes) {
let process = typeof processData === 'string' ? JSON.parse(processData) : processData; let process = typeof processData === 'string' ? JSON.parse(processData) : processData;
list.push(process); list.push(process);
...@@ -365,5 +375,17 @@ function traverseNode(root, callback) { ...@@ -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 }; export { divideCode };
//# sourceMappingURL=index.es.js.map //# sourceMappingURL=index.es.js.map
This diff is collapsed.
...@@ -194,12 +194,23 @@ ${scripts} ...@@ -194,12 +194,23 @@ ${scripts}
* Created by rockyl on 2019-12-20. * 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 processManager = new ProcessManager();
const scriptManager = new ScriptManager(); const scriptManager = new ScriptManager();
const customManager = new CustomManager(); 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 =====*/ /*=====START process =====*/
//console.log(TAG, 'start process'); //console.log(TAG, 'start process');
...@@ -209,7 +220,7 @@ async function divideCode(data, {debug, compile, uglify, getPackages}) { ...@@ -209,7 +220,7 @@ async function divideCode(data, {debug, compile, uglify, getPackages}) {
let bProcessIDs = processIDs; let bProcessIDs = processIDs;
while (true) { while (true) {
let newPids = await addBuiltinProcesses(builtinProcesses, bProcessIDs, getPackages, dependencies); let newPids = await addBuiltinProcesses(builtinProcesses, bProcessIDs, getPackagesTrans, dependencies);
bProcessIDs = []; bProcessIDs = [];
for (let id of newPids) { for (let id of newPids) {
if (!processIDs.includes(id)) { if (!processIDs.includes(id)) {
...@@ -263,7 +274,8 @@ async function divideCode(data, {debug, compile, uglify, getPackages}) { ...@@ -263,7 +274,8 @@ async function divideCode(data, {debug, compile, uglify, getPackages}) {
//let scriptsContainer = data.scripts = {}; //let scriptsContainer = data.scripts = {};
//let scriptsCode = ''; //let scriptsCode = '';
if (scriptIDs.length > 0) { 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) { for (let scriptData of scripts) {
let script = typeof scriptData === 'string' ? JSON.parse(scriptData) : scriptData; let script = typeof scriptData === 'string' ? JSON.parse(scriptData) : scriptData;
//scriptsContainer[id] = code; //scriptsContainer[id] = code;
...@@ -284,7 +296,8 @@ async function divideCode(data, {debug, compile, uglify, getPackages}) { ...@@ -284,7 +296,8 @@ async function divideCode(data, {debug, compile, uglify, getPackages}) {
//data.customs = []; //data.customs = [];
const customs = data.customs; const customs = data.customs;
if (customs && customs.length > 0) { 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 => { data.customs = customMetas.map(item => {
const custom = typeof item === 'string' ? JSON.parse(item) : item; const custom = typeof item === 'string' ? JSON.parse(item) : item;
customManager.deal(custom); customManager.deal(custom);
...@@ -345,14 +358,11 @@ function findDepPidsBat(list, processes) { ...@@ -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 newPids = [];
let schema = {};
if (ids.length > 0) { if (ids.length > 0) {
for(let id of ids){ let schema = idsToSchema(ids, dependencies);
schema[id] = dependencies[id]; let processes = await getPackagesTrans(schema, 1);
}
let processes = await getPackages(schema);
for (let processData of processes) { for (let processData of processes) {
let process = typeof processData === 'string' ? JSON.parse(processData) : processData; let process = typeof processData === 'string' ? JSON.parse(processData) : processData;
list.push(process); list.push(process);
...@@ -371,5 +381,17 @@ function traverseNode(root, callback) { ...@@ -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; exports.divideCode = divideCode;
//# sourceMappingURL=index.js.map //# sourceMappingURL=index.js.map
This diff is collapsed.
...@@ -193,12 +193,23 @@ ${scripts} ...@@ -193,12 +193,23 @@ ${scripts}
* Created by rockyl on 2019-12-20. * 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 processManager = new ProcessManager();
const scriptManager = new ScriptManager(); const scriptManager = new ScriptManager();
const customManager = new CustomManager(); 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 =====*/ /*=====START process =====*/
//console.log(TAG, 'start process'); //console.log(TAG, 'start process');
...@@ -208,7 +219,7 @@ ${scripts} ...@@ -208,7 +219,7 @@ ${scripts}
let bProcessIDs = processIDs; let bProcessIDs = processIDs;
while (true) { while (true) {
let newPids = await addBuiltinProcesses(builtinProcesses, bProcessIDs, getPackages, dependencies); let newPids = await addBuiltinProcesses(builtinProcesses, bProcessIDs, getPackagesTrans, dependencies);
bProcessIDs = []; bProcessIDs = [];
for (let id of newPids) { for (let id of newPids) {
if (!processIDs.includes(id)) { if (!processIDs.includes(id)) {
...@@ -262,7 +273,8 @@ ${scripts} ...@@ -262,7 +273,8 @@ ${scripts}
//let scriptsContainer = data.scripts = {}; //let scriptsContainer = data.scripts = {};
//let scriptsCode = ''; //let scriptsCode = '';
if (scriptIDs.length > 0) { 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) { for (let scriptData of scripts) {
let script = typeof scriptData === 'string' ? JSON.parse(scriptData) : scriptData; let script = typeof scriptData === 'string' ? JSON.parse(scriptData) : scriptData;
//scriptsContainer[id] = code; //scriptsContainer[id] = code;
...@@ -283,7 +295,8 @@ ${scripts} ...@@ -283,7 +295,8 @@ ${scripts}
//data.customs = []; //data.customs = [];
const customs = data.customs; const customs = data.customs;
if (customs && customs.length > 0) { 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 => { data.customs = customMetas.map(item => {
const custom = typeof item === 'string' ? JSON.parse(item) : item; const custom = typeof item === 'string' ? JSON.parse(item) : item;
customManager.deal(custom); customManager.deal(custom);
...@@ -344,14 +357,11 @@ ${scripts} ...@@ -344,14 +357,11 @@ ${scripts}
} }
} }
async function addBuiltinProcesses(list, ids, getPackages, dependencies) { async function addBuiltinProcesses(list, ids, getPackagesTrans, dependencies) {
let newPids = []; let newPids = [];
let schema = {};
if (ids.length > 0) { if (ids.length > 0) {
for(let id of ids){ let schema = idsToSchema(ids, dependencies);
schema[id] = dependencies[id]; let processes = await getPackagesTrans(schema, 1);
}
let processes = await getPackages(schema);
for (let processData of processes) { for (let processData of processes) {
let process = typeof processData === 'string' ? JSON.parse(processData) : processData; let process = typeof processData === 'string' ? JSON.parse(processData) : processData;
list.push(process); list.push(process);
...@@ -370,6 +380,18 @@ ${scripts} ...@@ -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; exports.divideCode = divideCode;
Object.defineProperty(exports, '__esModule', { value: true }); Object.defineProperty(exports, '__esModule', { value: true });
......
This diff is collapsed.
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
"props-compute": "http://gitlab2.dui88.com/laoqifeng/props-compute.git" "props-compute": "http://gitlab2.dui88.com/laoqifeng/props-compute.git"
}, },
"scripts": { "scripts": {
"dev": "rollup -c -w",
"build": "rollup -c" "build": "rollup -c"
} }
} }
...@@ -9,12 +9,23 @@ import {compute} from "props-compute"; ...@@ -9,12 +9,23 @@ import {compute} from "props-compute";
const TAG = 'zeroing-code-divider'; 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 processManager = new ProcessManager();
const scriptManager = new ScriptManager(); const scriptManager = new ScriptManager();
const customManager = new CustomManager(); 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 =====*/ /*=====START process =====*/
//console.log(TAG, 'start process'); //console.log(TAG, 'start process');
...@@ -24,7 +35,7 @@ export async function divideCode(data, {debug, compile, uglify, getPackages}) { ...@@ -24,7 +35,7 @@ export async function divideCode(data, {debug, compile, uglify, getPackages}) {
let bProcessIDs = processIDs; let bProcessIDs = processIDs;
while (true) { while (true) {
let newPids = await addBuiltinProcesses(builtinProcesses, bProcessIDs, getPackages, dependencies); let newPids = await addBuiltinProcesses(builtinProcesses, bProcessIDs, getPackagesTrans, dependencies);
bProcessIDs = []; bProcessIDs = [];
for (let id of newPids) { for (let id of newPids) {
if (!processIDs.includes(id)) { if (!processIDs.includes(id)) {
...@@ -78,7 +89,8 @@ export async function divideCode(data, {debug, compile, uglify, getPackages}) { ...@@ -78,7 +89,8 @@ export async function divideCode(data, {debug, compile, uglify, getPackages}) {
//let scriptsContainer = data.scripts = {}; //let scriptsContainer = data.scripts = {};
//let scriptsCode = ''; //let scriptsCode = '';
if (scriptIDs.length > 0) { 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) { for (let scriptData of scripts) {
let script = typeof scriptData === 'string' ? JSON.parse(scriptData) : scriptData; let script = typeof scriptData === 'string' ? JSON.parse(scriptData) : scriptData;
//scriptsContainer[id] = code; //scriptsContainer[id] = code;
...@@ -99,7 +111,8 @@ export async function divideCode(data, {debug, compile, uglify, getPackages}) { ...@@ -99,7 +111,8 @@ export async function divideCode(data, {debug, compile, uglify, getPackages}) {
//data.customs = []; //data.customs = [];
const customs = data.customs; const customs = data.customs;
if (customs && customs.length > 0) { 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 => { data.customs = customMetas.map(item => {
const custom = typeof item === 'string' ? JSON.parse(item) : item; const custom = typeof item === 'string' ? JSON.parse(item) : item;
customManager.deal(custom); customManager.deal(custom);
...@@ -160,14 +173,11 @@ function findDepPidsBat(list, processes) { ...@@ -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 newPids = [];
let schema = {};
if (ids.length > 0) { if (ids.length > 0) {
for(let id of ids){ let schema = idsToSchema(ids, dependencies);
schema[id] = dependencies[id]; let processes = await getPackagesTrans(schema, 1);
}
let processes = await getPackages(schema);
for (let processData of processes) { for (let processData of processes) {
let process = typeof processData === 'string' ? JSON.parse(processData) : processData; let process = typeof processData === 'string' ? JSON.parse(processData) : processData;
list.push(process); list.push(process);
...@@ -185,3 +195,15 @@ function traverseNode(root, callback) { ...@@ -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