Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
zeroing-pack
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-pack
Commits
d38c4004
Commit
d38c4004
authored
Nov 23, 2019
by
劳工
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' into 'master'
修复没有序列化custom的问题 See merge request
!3
parents
238212f9
cd25a6b9
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
31 additions
and
11 deletions
+31
-11
index.es.js
dist/index.es.js
+7
-2
index.es.js.map
dist/index.es.js.map
+1
-1
index.js
dist/index.js
+7
-2
index.js.map
dist/index.js.map
+1
-1
index.umd.js
dist/index.umd.js
+7
-2
index.umd.js.map
dist/index.umd.js.map
+1
-1
index.js
src/index.js
+7
-2
No files found.
dist/index.es.js
View file @
d38c4004
...
...
@@ -73,13 +73,18 @@ async function packData(data, {getProcesses, getScripts, getCustoms}) {
}
}
newData
.
customs
=
data
.
customs
&&
data
.
customs
.
length
>
0
?
await
getCustoms
(
data
.
customs
)
:
[];
newData
.
customs
=
[];
if
(
data
.
customs
&&
data
.
customs
.
length
>
0
)
{
newData
.
customs
=
await
getCustoms
(
data
.
customs
).
map
(
item
=>
{
return
JSON
.
parse
(
item
);
});
}
return
JSON
.
stringify
(
newData
);
}
function
findDepPids
(
list
,
process
)
{
if
(
process
.
sub
)
{
if
(
process
.
sub
)
{
for
(
let
key
in
process
.
sub
)
{
let
p
=
process
.
sub
[
key
];
if
(
!
list
.
includes
(
p
.
meta
))
{
...
...
dist/index.es.js.map
View file @
d38c4004
{
"version"
:
3
,
"file"
:
"index.es.js"
,
"sources"
:
[
"../src/index.js"
],
"sourcesContent"
:
[
"/**
\n
* Created by rockyl on 2019-11-13.
\n
*
\n
* 项目打包
\n
*/
\n\n
const camelcase = require('camelcase');
\n\n
const replaceFields = ['page_title', 'container_id', 'version'];
\n\n
export async function pack(project, options) {\n
\t
let version = Date.now() + Math.floor(Math.random() * 1000);
\n\t
let data = JSON.parse(project.data);
\n\t
const newTpl = await pageTemplate(data, options, version);
\n\t
const newData = await packData(data, options);
\n\n\t
return {\n
\t\t
version,
\n\t\t
data: newData,
\n\t\t
tpl: newTpl,
\n\t
}
\n
}
\n\n
async function packData(data, {getProcesses, getScripts, getCustoms}) {\n
\t
let newData = {};
\n\t
newData.options = data.options;
\n\t
delete newData.options.tpl;
\n\t
newData.views = data.views;
\n\t
newData.assets = data.assets;
\n\t
newData.dataMapping = data.dataMapping;
\n\t
newData.processes = data.processes;
\n\n\t
let scriptIDs = [];
\n\t
for (let view of newData.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 = newData.scripts = {};
\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 {id, code} = JSON.parse(scriptData);
\n\t\t\t
scriptsContainer[id] = code;
\n\t\t
}
\n\t\t
//console.log('scripts:', scriptsContainer);
\n\t
}
\n\n\t
let processIDs = [];
\n\t
findDepPidsBat(processIDs, newData.processes);
\n\t
//console.log('processIDs:', processIDs);
\n\t
let builtinProcesses = newData.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
newData.customs = data.customs && data.customs.length > 0 ? await getCustoms(data.customs) : [];
\n\n\t
return JSON.stringify(newData);
\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\t
//console.log('processes:', data.processes);
\n\t
}
\n\t
return newPids;
\n
}
\n\n
async function pageTemplate(data, options, version) {\n
\t
const
{
tpl,
}
= data.options;
\n\t
let newTpl = tpl;
\n\t
let newOptions = Object.assign(data.options,
{
\n\t\tversion,\n\t
}
);
\n\t
delete newOptions.tpl;
\n\t
for (let field of replaceFields) {\n
\t\t
const key = camelcase(field);
\n\t\t
newTpl = newTpl.replace(new RegExp(`
\\\\
$${field.toUpperCase()}
\\\\
$`, 'g'), newOptions[key]);
\n\t
}
\n\t
return newTpl;
\n
}
\n\n
function traverseNode(root, callback) {\n
\t
callback(root);
\n\t
if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CAAC,CAAC;GACtC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;GACnB,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;GAC9B;;EAED;CACD,OAAO,OAAO,CAAC;CACf;;AAED,eAAe,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE;CACnD,MAAM,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;CAC5B,IAAI,MAAM,GAAG,GAAG,CAAC;CACjB,IAAI,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE;EAC5C,OAAO;EACP,CAAC,CAAC;CACH,OAAO,UAAU,CAAC,GAAG,CAAC;CACtB,KAAK,IAAI,KAAK,IAAI,aAAa,EAAE;EAChC,MAAM,GAAG,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;EAC7B,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,WAAW,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;EAC1F;CACD,OAAO,MAAM,CAAC;CACd;;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/index.js"
],
"sourcesContent"
:
[
"/**
\n
* Created by rockyl on 2019-11-13.
\n
*
\n
* 项目打包
\n
*/
\n\n
const camelcase = require('camelcase');
\n\n
const replaceFields = ['page_title', 'container_id', 'version'];
\n\n
export async function pack(project, options) {\n
\t
let version = Date.now() + Math.floor(Math.random() * 1000);
\n\t
let data = JSON.parse(project.data);
\n\t
const newTpl = await pageTemplate(data, options, version);
\n\t
const newData = await packData(data, options);
\n\n\t
return {\n
\t\t
version,
\n\t\t
data: newData,
\n\t\t
tpl: newTpl,
\n\t
}
\n
}
\n\n
async function packData(data, {getProcesses, getScripts, getCustoms}) {\n
\t
let newData = {};
\n\t
newData.options = data.options;
\n\t
delete newData.options.tpl;
\n\t
newData.views = data.views;
\n\t
newData.assets = data.assets;
\n\t
newData.dataMapping = data.dataMapping;
\n\t
newData.processes = data.processes;
\n\n\t
let scriptIDs = [];
\n\t
for (let view of newData.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 = newData.scripts = {};
\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 {id, code} = JSON.parse(scriptData);
\n\t\t\t
scriptsContainer[id] = code;
\n\t\t
}
\n\t\t
//console.log('scripts:', scriptsContainer);
\n\t
}
\n\n\t
let processIDs = [];
\n\t
findDepPidsBat(processIDs, newData.processes);
\n\t
//console.log('processIDs:', processIDs);
\n\t
let builtinProcesses = newData.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
newData.customs = [];
\n\t
if (data.customs && data.customs.length > 0) {\n
\t\t
newData.customs = await getCustoms(data.customs).map(item => {\n
\t\t\t
return JSON.parse(item);
\n\t\t
})
\n\t
}
\n\n\t
return JSON.stringify(newData);
\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\t
//console.log('processes:', data.processes);
\n\t
}
\n\t
return newPids;
\n
}
\n\n
async function pageTemplate(data, options, version) {\n
\t
const
{
tpl,
}
= data.options;
\n\t
let newTpl = tpl;
\n\t
let newOptions = Object.assign(data.options,
{
\n\t\tversion,\n\t
}
);
\n\t
delete newOptions.tpl;
\n\t
for (let field of replaceFields) {\n
\t\t
const key = camelcase(field);
\n\t\t
newTpl = newTpl.replace(new RegExp(`
\\\\
$${field.toUpperCase()}
\\\\
$`, 'g'), newOptions[key]);
\n\t
}
\n\t
return newTpl;
\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
"
],
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AG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;GACtC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;GACnB,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;GAC9B;;EAED;CACD,OAAO,OAAO,CAAC;CACf;;AAED,eAAe,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE;CACnD,MAAM,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;CAC5B,IAAI,MAAM,GAAG,GAAG,CAAC;CACjB,IAAI,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE;EAC5C,OAAO;EACP,CAAC,CAAC;CACH,OAAO,UAAU,CAAC,GAAG,CAAC;CACtB,KAAK,IAAI,KAAK,IAAI,aAAa,EAAE;EAChC,MAAM,GAAG,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;EAC7B,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,WAAW,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;EAC1F;CACD,OAAO,MAAM,CAAC;CACd;;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 @
d38c4004
...
...
@@ -77,13 +77,18 @@ async function packData(data, {getProcesses, getScripts, getCustoms}) {
}
}
newData
.
customs
=
data
.
customs
&&
data
.
customs
.
length
>
0
?
await
getCustoms
(
data
.
customs
)
:
[];
newData
.
customs
=
[];
if
(
data
.
customs
&&
data
.
customs
.
length
>
0
)
{
newData
.
customs
=
await
getCustoms
(
data
.
customs
).
map
(
item
=>
{
return
JSON
.
parse
(
item
);
});
}
return
JSON
.
stringify
(
newData
);
}
function
findDepPids
(
list
,
process
)
{
if
(
process
.
sub
)
{
if
(
process
.
sub
)
{
for
(
let
key
in
process
.
sub
)
{
let
p
=
process
.
sub
[
key
];
if
(
!
list
.
includes
(
p
.
meta
))
{
...
...
dist/index.js.map
View file @
d38c4004
{
"version"
:
3
,
"file"
:
"index.js"
,
"sources"
:
[
"../src/index.js"
],
"sourcesContent"
:
[
"/**
\n
* Created by rockyl on 2019-11-13.
\n
*
\n
* 项目打包
\n
*/
\n\n
const camelcase = require('camelcase');
\n\n
const replaceFields = ['page_title', 'container_id', 'version'];
\n\n
export async function pack(project, options) {\n
\t
let version = Date.now() + Math.floor(Math.random() * 1000);
\n\t
let data = JSON.parse(project.data);
\n\t
const newTpl = await pageTemplate(data, options, version);
\n\t
const newData = await packData(data, options);
\n\n\t
return {\n
\t\t
version,
\n\t\t
data: newData,
\n\t\t
tpl: newTpl,
\n\t
}
\n
}
\n\n
async function packData(data, {getProcesses, getScripts, getCustoms}) {\n
\t
let newData = {};
\n\t
newData.options = data.options;
\n\t
delete newData.options.tpl;
\n\t
newData.views = data.views;
\n\t
newData.assets = data.assets;
\n\t
newData.dataMapping = data.dataMapping;
\n\t
newData.processes = data.processes;
\n\n\t
let scriptIDs = [];
\n\t
for (let view of newData.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 = newData.scripts = {};
\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 {id, code} = JSON.parse(scriptData);
\n\t\t\t
scriptsContainer[id] = code;
\n\t\t
}
\n\t\t
//console.log('scripts:', scriptsContainer);
\n\t
}
\n\n\t
let processIDs = [];
\n\t
findDepPidsBat(processIDs, newData.processes);
\n\t
//console.log('processIDs:', processIDs);
\n\t
let builtinProcesses = newData.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
newData.customs = data.customs && data.customs.length > 0 ? await getCustoms(data.customs) : [];
\n\n\t
return JSON.stringify(newData);
\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\t
//console.log('processes:', data.processes);
\n\t
}
\n\t
return newPids;
\n
}
\n\n
async function pageTemplate(data, options, version) {\n
\t
const
{
tpl,
}
= data.options;
\n\t
let newTpl = tpl;
\n\t
let newOptions = Object.assign(data.options,
{
\n\t\tversion,\n\t
}
);
\n\t
delete newOptions.tpl;
\n\t
for (let field of replaceFields) {\n
\t\t
const key = camelcase(field);
\n\t\t
newTpl = newTpl.replace(new RegExp(`
\\\\
$${field.toUpperCase()}
\\\\
$`, 'g'), newOptions[key]);
\n\t
}
\n\t
return newTpl;
\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;;;;;;AAMA,MAAM,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;;AAEvC,MAAM,aAAa,GAAG,CAAC,YAAY,EAAE,cAAc,EAAE,SAAS,CAAC,CAAC;;AAEhE,AAAO,eAAe,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE;CAC5C,IAAI,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;CAC5D,IAAI,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;CACpC,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;CAC1D,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;;CAE9C,OAAO;EACN,OAAO;EACP,IAAI,EAAE,OAAO;EACb,GAAG,EAAE,MAAM;EACX;CACD;;AAED,eAAe,QAAQ,CAAC,IAAI,EAAE,CAAC,YAAY,EAAE,UAAU,EAAE,UAAU,CAAC,EAAE;CACrE,IAAI,OAAO,GAAG,EAAE,CAAC;CACjB,O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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/index.js"
],
"sourcesContent"
:
[
"/**
\n
* Created by rockyl on 2019-11-13.
\n
*
\n
* 项目打包
\n
*/
\n\n
const camelcase = require('camelcase');
\n\n
const replaceFields = ['page_title', 'container_id', 'version'];
\n\n
export async function pack(project, options) {\n
\t
let version = Date.now() + Math.floor(Math.random() * 1000);
\n\t
let data = JSON.parse(project.data);
\n\t
const newTpl = await pageTemplate(data, options, version);
\n\t
const newData = await packData(data, options);
\n\n\t
return {\n
\t\t
version,
\n\t\t
data: newData,
\n\t\t
tpl: newTpl,
\n\t
}
\n
}
\n\n
async function packData(data, {getProcesses, getScripts, getCustoms}) {\n
\t
let newData = {};
\n\t
newData.options = data.options;
\n\t
delete newData.options.tpl;
\n\t
newData.views = data.views;
\n\t
newData.assets = data.assets;
\n\t
newData.dataMapping = data.dataMapping;
\n\t
newData.processes = data.processes;
\n\n\t
let scriptIDs = [];
\n\t
for (let view of newData.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 = newData.scripts = {};
\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 {id, code} = JSON.parse(scriptData);
\n\t\t\t
scriptsContainer[id] = code;
\n\t\t
}
\n\t\t
//console.log('scripts:', scriptsContainer);
\n\t
}
\n\n\t
let processIDs = [];
\n\t
findDepPidsBat(processIDs, newData.processes);
\n\t
//console.log('processIDs:', processIDs);
\n\t
let builtinProcesses = newData.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
newData.customs = [];
\n\t
if (data.customs && data.customs.length > 0) {\n
\t\t
newData.customs = await getCustoms(data.customs).map(item => {\n
\t\t\t
return JSON.parse(item);
\n\t\t
})
\n\t
}
\n\n\t
return JSON.stringify(newData);
\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\t
//console.log('processes:', data.processes);
\n\t
}
\n\t
return newPids;
\n
}
\n\n
async function pageTemplate(data, options, version) {\n
\t
const
{
tpl,
}
= data.options;
\n\t
let newTpl = tpl;
\n\t
let newOptions = Object.assign(data.options,
{
\n\t\tversion,\n\t
}
);
\n\t
delete newOptions.tpl;
\n\t
for (let field of replaceFields) {\n
\t\t
const key = camelcase(field);
\n\t\t
newTpl = newTpl.replace(new RegExp(`
\\\\
$${field.toUpperCase()}
\\\\
$`, 'g'), newOptions[key]);
\n\t
}
\n\t
return newTpl;
\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;;;;;;AAMA,MAAM,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;;AAEvC,MAAM,aAAa,GAAG,CAAC,YAAY,EAAE,cAAc,EAAE,SAAS,CAAC,CAAC;;AAEhE,AAAO,eAAe,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE;CAC5C,IAAI,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;CAC5D,IAAI,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;CACpC,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;CAC1D,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;;CAE9C,OAAO;EACN,OAAO;EACP,IAAI,EAAE,OAAO;EACb,GAAG,EAAE,MAAM;EACX;CACD;;AAED,eAAe,QAAQ,CAAC,IAAI,EAAE,CAAC,YAAY,EAAE,UAAU,EAAE,UAAU,CAAC,EAAE;CACrE,IAAI,OAAO,GAAG,EAAE,CAAC;CACjB,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;CAC/B,OAAO,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC;CAC3B,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C,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 @
d38c4004
...
...
@@ -79,13 +79,18 @@
}
}
newData
.
customs
=
data
.
customs
&&
data
.
customs
.
length
>
0
?
await
getCustoms
(
data
.
customs
)
:
[];
newData
.
customs
=
[];
if
(
data
.
customs
&&
data
.
customs
.
length
>
0
)
{
newData
.
customs
=
await
getCustoms
(
data
.
customs
).
map
(
item
=>
{
return
JSON
.
parse
(
item
);
});
}
return
JSON
.
stringify
(
newData
);
}
function
findDepPids
(
list
,
process
)
{
if
(
process
.
sub
)
{
if
(
process
.
sub
)
{
for
(
let
key
in
process
.
sub
)
{
let
p
=
process
.
sub
[
key
];
if
(
!
list
.
includes
(
p
.
meta
))
{
...
...
dist/index.umd.js.map
View file @
d38c4004
{
"version"
:
3
,
"file"
:
"index.umd.js"
,
"sources"
:
[
"../src/index.js"
],
"sourcesContent"
:
[
"/**
\n
* Created by rockyl on 2019-11-13.
\n
*
\n
* 项目打包
\n
*/
\n\n
const camelcase = require('camelcase');
\n\n
const replaceFields = ['page_title', 'container_id', 'version'];
\n\n
export async function pack(project, options) {\n
\t
let version = Date.now() + Math.floor(Math.random() * 1000);
\n\t
let data = JSON.parse(project.data);
\n\t
const newTpl = await pageTemplate(data, options, version);
\n\t
const newData = await packData(data, options);
\n\n\t
return {\n
\t\t
version,
\n\t\t
data: newData,
\n\t\t
tpl: newTpl,
\n\t
}
\n
}
\n\n
async function packData(data, {getProcesses, getScripts, getCustoms}) {\n
\t
let newData = {};
\n\t
newData.options = data.options;
\n\t
delete newData.options.tpl;
\n\t
newData.views = data.views;
\n\t
newData.assets = data.assets;
\n\t
newData.dataMapping = data.dataMapping;
\n\t
newData.processes = data.processes;
\n\n\t
let scriptIDs = [];
\n\t
for (let view of newData.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 = newData.scripts = {};
\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 {id, code} = JSON.parse(scriptData);
\n\t\t\t
scriptsContainer[id] = code;
\n\t\t
}
\n\t\t
//console.log('scripts:', scriptsContainer);
\n\t
}
\n\n\t
let processIDs = [];
\n\t
findDepPidsBat(processIDs, newData.processes);
\n\t
//console.log('processIDs:', processIDs);
\n\t
let builtinProcesses = newData.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
newData.customs = data.customs && data.customs.length > 0 ? await getCustoms(data.customs) : [];
\n\n\t
return JSON.stringify(newData);
\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\t
//console.log('processes:', data.processes);
\n\t
}
\n\t
return newPids;
\n
}
\n\n
async function pageTemplate(data, options, version) {\n
\t
const
{
tpl,
}
= data.options;
\n\t
let newTpl = tpl;
\n\t
let newOptions = Object.assign(data.options,
{
\n\t\tversion,\n\t
}
);
\n\t
delete newOptions.tpl;
\n\t
for (let field of replaceFields) {\n
\t\t
const key = camelcase(field);
\n\t\t
newTpl = newTpl.replace(new RegExp(`
\\\\
$${field.toUpperCase()}
\\\\
$`, 'g'), newOptions[key]);
\n\t
}
\n\t
return newTpl;
\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;CACA;CACA;;CAEA,MAAM,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;;CAEvC,MAAM,aAAa,GAAG,CAAC,YAAY,EAAE,cAAc,EAAE,SAAS,CAAC,CAAC;;AAEhE,CAAO,eAAe,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE;CAC7C,CAAC,IAAI,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;CAC7D,CAAC,IAAI,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;CACrC,CAAC,MAAM,MAAM,GAA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13.
\n
*
\n
* 项目打包
\n
*/
\n\n
const camelcase = require('camelcase');
\n\n
const replaceFields = ['page_title', 'container_id', 'version'];
\n\n
export async function pack(project, options) {\n
\t
let version = Date.now() + Math.floor(Math.random() * 1000);
\n\t
let data = JSON.parse(project.data);
\n\t
const newTpl = await pageTemplate(data, options, version);
\n\t
const newData = await packData(data, options);
\n\n\t
return {\n
\t\t
version,
\n\t\t
data: newData,
\n\t\t
tpl: newTpl,
\n\t
}
\n
}
\n\n
async function packData(data, {getProcesses, getScripts, getCustoms}) {\n
\t
let newData = {};
\n\t
newData.options = data.options;
\n\t
delete newData.options.tpl;
\n\t
newData.views = data.views;
\n\t
newData.assets = data.assets;
\n\t
newData.dataMapping = data.dataMapping;
\n\t
newData.processes = data.processes;
\n\n\t
let scriptIDs = [];
\n\t
for (let view of newData.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 = newData.scripts = {};
\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 {id, code} = JSON.parse(scriptData);
\n\t\t\t
scriptsContainer[id] = code;
\n\t\t
}
\n\t\t
//console.log('scripts:', scriptsContainer);
\n\t
}
\n\n\t
let processIDs = [];
\n\t
findDepPidsBat(processIDs, newData.processes);
\n\t
//console.log('processIDs:', processIDs);
\n\t
let builtinProcesses = newData.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
newData.customs = [];
\n\t
if (data.customs && data.customs.length > 0) {\n
\t\t
newData.customs = await getCustoms(data.customs).map(item => {\n
\t\t\t
return JSON.parse(item);
\n\t\t
})
\n\t
}
\n\n\t
return JSON.stringify(newData);
\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\t
//console.log('processes:', data.processes);
\n\t
}
\n\t
return newPids;
\n
}
\n\n
async function pageTemplate(data, options, version) {\n
\t
const
{
tpl,
}
= data.options;
\n\t
let newTpl = tpl;
\n\t
let newOptions = Object.assign(data.options,
{
\n\t\tversion,\n\t
}
);
\n\t
delete newOptions.tpl;
\n\t
for (let field of replaceFields) {\n
\t\t
const key = camelcase(field);
\n\t\t
newTpl = newTpl.replace(new RegExp(`
\\\\
$${field.toUpperCase()}
\\\\
$`, 'g'), newOptions[key]);
\n\t
}
\n\t
return newTpl;
\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) {\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CAAC,CAAC;CAC/B,EAAE,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,WAAW,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;CAC5F,EAAE;CACF,CAAC,OAAO,MAAM,CAAC;CACf,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
src/index.js
View file @
d38c4004
...
...
@@ -73,13 +73,18 @@ async function packData(data, {getProcesses, getScripts, getCustoms}) {
}
}
newData
.
customs
=
data
.
customs
&&
data
.
customs
.
length
>
0
?
await
getCustoms
(
data
.
customs
)
:
[];
newData
.
customs
=
[];
if
(
data
.
customs
&&
data
.
customs
.
length
>
0
)
{
newData
.
customs
=
await
getCustoms
(
data
.
customs
).
map
(
item
=>
{
return
JSON
.
parse
(
item
);
})
}
return
JSON
.
stringify
(
newData
);
}
function
findDepPids
(
list
,
process
)
{
if
(
process
.
sub
)
{
if
(
process
.
sub
)
{
for
(
let
key
in
process
.
sub
)
{
let
p
=
process
.
sub
[
key
];
if
(
!
list
.
includes
(
p
.
meta
))
{
...
...
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