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
This diff is collapsed.
......@@ -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
This diff is collapsed.
......@@ -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 });
......
This diff is collapsed.
......@@ -8,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