Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
zeroing-template-fill
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-template-fill
Commits
2191ce9a
Commit
2191ce9a
authored
Jul 14, 2020
by
rockyl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
兼容混淆版本的引擎
parent
11f5cc42
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
15 additions
and
11 deletions
+15
-11
index.es.js
dist/index.es.js
+3
-2
index.es.js.map
dist/index.es.js.map
+1
-1
index.js
dist/index.js
+3
-2
index.js.map
dist/index.js.map
+1
-1
index.umd.js
dist/index.umd.js
+3
-2
index.umd.js.map
dist/index.umd.js.map
+1
-1
index.js
src/index.js
+3
-2
No files found.
dist/index.es.js
View file @
2191ce9a
...
@@ -43,7 +43,7 @@ function fillTemplate(tpl, params, analyseResult) {
...
@@ -43,7 +43,7 @@ function fillTemplate(tpl, params, analyseResult) {
return
tpl
;
return
tpl
;
}
}
async
function
generateLibraryScriptEl
(
tpl
,
dependencies
,
getPackages
,
libraryPath
)
{
async
function
generateLibraryScriptEl
(
tpl
,
dependencies
,
getPackages
,
libraryPath
,
debug
)
{
let
analyseResult
=
analyseTemplate
(
tpl
);
let
analyseResult
=
analyseTemplate
(
tpl
);
let
librariesHint
=
analyseResult
.
filter
(
item
=>
item
.
field
===
'libraries'
).
map
(
item
=>
item
.
subField
);
let
librariesHint
=
analyseResult
.
filter
(
item
=>
item
.
field
===
'libraries'
).
map
(
item
=>
item
.
subField
);
...
@@ -58,7 +58,8 @@ async function generateLibraryScriptEl(tpl, dependencies, getPackages, libraryPa
...
@@ -58,7 +58,8 @@ async function generateLibraryScriptEl(tpl, dependencies, getPackages, libraryPa
(
await
getPackages
(
schema
,
0
)).
forEach
(
item
=>
{
(
await
getPackages
(
schema
,
0
)).
forEach
(
item
=>
{
let
itemObj
=
typeof
item
.
data
===
'string'
?
JSON
.
parse
(
item
.
data
)
:
item
.
data
;
let
itemObj
=
typeof
item
.
data
===
'string'
?
JSON
.
parse
(
item
.
data
)
:
item
.
data
;
libraryScriptElMap
[
itemObj
.
id
]
=
generateJsScriptEl
(
itemObj
.
url
,
libraryPath
);
let
urlField
=
debug
&&
itemObj
.
url_dbg
?
'url_dbg'
:
'url'
;
libraryScriptElMap
[
itemObj
.
id
]
=
generateJsScriptEl
(
itemObj
[
urlField
],
libraryPath
);
});
});
}
}
...
...
dist/index.es.js.map
View file @
2191ce9a
{
"version"
:
3
,
"file"
:
"index.es.js"
,
"sources"
:
[
"../src/index.js"
],
"sourcesContent"
:
[
"/**
\n
* Created by rockyl on 2019-11-13.
\n
*
\n
* 模板填充
\n
*/
\n\n
import camelcase from 'camelcase'
\n\n
const TAG = 'zeroing-template-fill';
\n\n
const dynamicValueReg = /
\\
$[
\\
w|(
\\
.)]+
\\
$/g;
\n\n
export function analyseTemplate(tpl) {\n
\t
let result = [];
\n\t
let matchResult = tpl.match(dynamicValueReg);
\n\t
for (let matchItem of matchResult) {\n
\t\t
let hint = matchItem.substr(1, matchItem.length - 2);
\n\t\t
let arr = hint.split('.');
\n\t\t
let field = camelcase(arr[0]);
\n\n\t\t
let item = {\n
\t\t\t
source: matchItem,
\n\t\t\t
field,
\n\t\t
};
\n\t\t
if (arr[1] !== undefined) {\n
\t\t\t
item.subField = arr[1];
\n\t\t
}
\n\t\t
result.push(item)
\n\t
}
\n\t
return result;
\n
}
\n\n
export function fillTemplate(tpl, params, analyseResult) {\n
\t
analyseResult = analyseResult || analyseTemplate(tpl);
\n\t
for (let item of analyseResult) {\n
\t\t
let fieldData = params[item.field];
\n\t\t
if (fieldData && item.subField) {\n
\t\t\t
fieldData = fieldData[item.subField];
\n\t\t
}
\n\t\t
if (fieldData) {\n
\t\t\t
tpl = tpl.replace(item.source, fieldData);
\n\t\t
}
\n\t
}
\n\n\t
return tpl;
\n
}
\n\n
export async function generateLibraryScriptEl(tpl, dependencies, getPackages, libraryPath) {\n
\t
let analyseResult = analyseTemplate(tpl);
\n\t
let librariesHint = analyseResult.filter(item => item.field === 'libraries').map(item => item.subField);
\n\n\t
let libraryScriptElMap = {};
\n\t
if (librariesHint.length > 0) {\n
\t\t
let schema = {};
\n\t\t
for (let libName of librariesHint) {\n
\t\t\t
if (dependencies[libName]) {\n
\t\t\t\t
schema[libName] = dependencies[libName];
\n\t\t\t
}
\n\t\t
}
\n\n\t\t
(await getPackages(schema, 0)).forEach(item => {\n
\t\t\t
let itemObj = typeof item.data === 'string' ? JSON.parse(item.data) : item.data;
\n\t\t\t
libraryScriptElMap[itemObj.id] = generateJsScriptEl(itemObj.url, libraryPath);
\n\t\t
});
\n\t
}
\n\n\t
return
{
\n\t\tlibraryScriptElMap,\n\t\tanalyseResult,\n\t}\n
}
\n\n
export function generateJsScriptEl(file, path) {\n
\t
let url = (path || '') + file;
\n\t
return `<script crossorigin=
\"
anonymous
\"
src=
\"
${url}
\"
></script>`;
\n
}
\n
"
],
"names"
:
[],
"mappings"
:
";;AAAA;;;;;AAKA,AAIA;AACA,MAAM,eAAe,GAAG,iBAAiB,CAAC;;AAE1C,AAAO,SAAS,eAAe,CAAC,GAAG,EAAE;CACpC,IAAI,MAAM,GAAG,EAAE,CAAC;CAChB,IAAI,WAAW,GAAG,GAAG,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;CAC7C,KAAK,IAAI,SAAS,IAAI,WAAW,EAAE;EAClC,IAAI,IAAI,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;EAC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CAAC;CAC5B,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE;EAC7B,IAAI,MAAM,GAAG,EAAE,CAAC;EAChB,KAAK,IAAI,OAAO,IAAI,aAAa,EAAE;GAClC,IAAI,YAAY,CAAC,OAAO,CAAC,EAAE;IAC1B,MAAM,CAAC,OAAO,CAAC,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;IACxC;GACD;;EAED,CAAC,MAAM,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,IAAI,IAAI;GAC9C,IAAI,OAAO,GAAG,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC;GAChF,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,kBAAkB,CAAC,OAAO,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;GAC9E,CAAC,CAAC;EACH;;CAED,OAAO;EACN,kBAAkB;EAClB,aAAa;EACb;CACD;;AAED,AAAO,SAAS,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE;CAC9C,IAAI,GAAG,GAAG,CAAC,IAAI,IAAI,EAAE,IAAI,IAAI,CAAC;CAC9B,OAAO,CAAC,qCAAqC,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;CAChE;;;;"
}
{
"version"
:
3
,
"file"
:
"index.es.js"
,
"sources"
:
[
"../src/index.js"
],
"sourcesContent"
:
[
"/**
\n
* Created by rockyl on 2019-11-13.
\n
*
\n
* 模板填充
\n
*/
\n\n
import camelcase from 'camelcase'
\n\n
const TAG = 'zeroing-template-fill';
\n\n
const dynamicValueReg = /
\\
$[
\\
w|(
\\
.)]+
\\
$/g;
\n\n
export function analyseTemplate(tpl) {\n
\t
let result = [];
\n\t
let matchResult = tpl.match(dynamicValueReg);
\n\t
for (let matchItem of matchResult) {\n
\t\t
let hint = matchItem.substr(1, matchItem.length - 2);
\n\t\t
let arr = hint.split('.');
\n\t\t
let field = camelcase(arr[0]);
\n\n\t\t
let item = {\n
\t\t\t
source: matchItem,
\n\t\t\t
field,
\n\t\t
};
\n\t\t
if (arr[1] !== undefined) {\n
\t\t\t
item.subField = arr[1];
\n\t\t
}
\n\t\t
result.push(item)
\n\t
}
\n\t
return result;
\n
}
\n\n
export function fillTemplate(tpl, params, analyseResult) {\n
\t
analyseResult = analyseResult || analyseTemplate(tpl);
\n\t
for (let item of analyseResult) {\n
\t\t
let fieldData = params[item.field];
\n\t\t
if (fieldData && item.subField) {\n
\t\t\t
fieldData = fieldData[item.subField];
\n\t\t
}
\n\t\t
if (fieldData) {\n
\t\t\t
tpl = tpl.replace(item.source, fieldData);
\n\t\t
}
\n\t
}
\n\n\t
return tpl;
\n
}
\n\n
export async function generateLibraryScriptEl(tpl, dependencies, getPackages, libraryPath, debug) {\n
\t
let analyseResult = analyseTemplate(tpl);
\n\t
let librariesHint = analyseResult.filter(item => item.field === 'libraries').map(item => item.subField);
\n\n\t
let libraryScriptElMap = {};
\n\t
if (librariesHint.length > 0) {\n
\t\t
let schema = {};
\n\t\t
for (let libName of librariesHint) {\n
\t\t\t
if (dependencies[libName]) {\n
\t\t\t\t
schema[libName] = dependencies[libName];
\n\t\t\t
}
\n\t\t
}
\n\n\t\t
(await getPackages(schema, 0)).forEach(item => {\n
\t\t\t
let itemObj = typeof item.data === 'string' ? JSON.parse(item.data) : item.data;
\n\t\t\t
let urlField = debug && itemObj.url_dbg ? 'url_dbg' : 'url';
\n\t\t\t
libraryScriptElMap[itemObj.id] = generateJsScriptEl(itemObj[urlField], libraryPath);
\n\t\t
});
\n\t
}
\n\n\t
return
{
\n\t\tlibraryScriptElMap,\n\t\tanalyseResult,\n\t}\n
}
\n\n
export function generateJsScriptEl(file, path) {\n
\t
let url = (path || '') + file;
\n\t
return `<script crossorigin=
\"
anonymous
\"
src=
\"
${url}
\"
></script>`;
\n
}
\n
"
],
"names"
:
[],
"mappings"
:
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AAI,IAAI,CAAC;CAC9B,OAAO,CAAC,qCAAqC,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;CAChE;;;;"
}
\ No newline at end of file
\ No newline at end of file
dist/index.js
View file @
2191ce9a
...
@@ -49,7 +49,7 @@ function fillTemplate(tpl, params, analyseResult) {
...
@@ -49,7 +49,7 @@ function fillTemplate(tpl, params, analyseResult) {
return
tpl
;
return
tpl
;
}
}
async
function
generateLibraryScriptEl
(
tpl
,
dependencies
,
getPackages
,
libraryPath
)
{
async
function
generateLibraryScriptEl
(
tpl
,
dependencies
,
getPackages
,
libraryPath
,
debug
)
{
let
analyseResult
=
analyseTemplate
(
tpl
);
let
analyseResult
=
analyseTemplate
(
tpl
);
let
librariesHint
=
analyseResult
.
filter
(
item
=>
item
.
field
===
'libraries'
).
map
(
item
=>
item
.
subField
);
let
librariesHint
=
analyseResult
.
filter
(
item
=>
item
.
field
===
'libraries'
).
map
(
item
=>
item
.
subField
);
...
@@ -64,7 +64,8 @@ async function generateLibraryScriptEl(tpl, dependencies, getPackages, libraryPa
...
@@ -64,7 +64,8 @@ async function generateLibraryScriptEl(tpl, dependencies, getPackages, libraryPa
(
await
getPackages
(
schema
,
0
)).
forEach
(
item
=>
{
(
await
getPackages
(
schema
,
0
)).
forEach
(
item
=>
{
let
itemObj
=
typeof
item
.
data
===
'string'
?
JSON
.
parse
(
item
.
data
)
:
item
.
data
;
let
itemObj
=
typeof
item
.
data
===
'string'
?
JSON
.
parse
(
item
.
data
)
:
item
.
data
;
libraryScriptElMap
[
itemObj
.
id
]
=
generateJsScriptEl
(
itemObj
.
url
,
libraryPath
);
let
urlField
=
debug
&&
itemObj
.
url_dbg
?
'url_dbg'
:
'url'
;
libraryScriptElMap
[
itemObj
.
id
]
=
generateJsScriptEl
(
itemObj
[
urlField
],
libraryPath
);
});
});
}
}
...
...
dist/index.js.map
View file @
2191ce9a
{
"version"
:
3
,
"file"
:
"index.js"
,
"sources"
:
[
"../src/index.js"
],
"sourcesContent"
:
[
"/**
\n
* Created by rockyl on 2019-11-13.
\n
*
\n
* 模板填充
\n
*/
\n\n
import camelcase from 'camelcase'
\n\n
const TAG = 'zeroing-template-fill';
\n\n
const dynamicValueReg = /
\\
$[
\\
w|(
\\
.)]+
\\
$/g;
\n\n
export function analyseTemplate(tpl) {\n
\t
let result = [];
\n\t
let matchResult = tpl.match(dynamicValueReg);
\n\t
for (let matchItem of matchResult) {\n
\t\t
let hint = matchItem.substr(1, matchItem.length - 2);
\n\t\t
let arr = hint.split('.');
\n\t\t
let field = camelcase(arr[0]);
\n\n\t\t
let item = {\n
\t\t\t
source: matchItem,
\n\t\t\t
field,
\n\t\t
};
\n\t\t
if (arr[1] !== undefined) {\n
\t\t\t
item.subField = arr[1];
\n\t\t
}
\n\t\t
result.push(item)
\n\t
}
\n\t
return result;
\n
}
\n\n
export function fillTemplate(tpl, params, analyseResult) {\n
\t
analyseResult = analyseResult || analyseTemplate(tpl);
\n\t
for (let item of analyseResult) {\n
\t\t
let fieldData = params[item.field];
\n\t\t
if (fieldData && item.subField) {\n
\t\t\t
fieldData = fieldData[item.subField];
\n\t\t
}
\n\t\t
if (fieldData) {\n
\t\t\t
tpl = tpl.replace(item.source, fieldData);
\n\t\t
}
\n\t
}
\n\n\t
return tpl;
\n
}
\n\n
export async function generateLibraryScriptEl(tpl, dependencies, getPackages, libraryPath) {\n
\t
let analyseResult = analyseTemplate(tpl);
\n\t
let librariesHint = analyseResult.filter(item => item.field === 'libraries').map(item => item.subField);
\n\n\t
let libraryScriptElMap = {};
\n\t
if (librariesHint.length > 0) {\n
\t\t
let schema = {};
\n\t\t
for (let libName of librariesHint) {\n
\t\t\t
if (dependencies[libName]) {\n
\t\t\t\t
schema[libName] = dependencies[libName];
\n\t\t\t
}
\n\t\t
}
\n\n\t\t
(await getPackages(schema, 0)).forEach(item => {\n
\t\t\t
let itemObj = typeof item.data === 'string' ? JSON.parse(item.data) : item.data;
\n\t\t\t
libraryScriptElMap[itemObj.id] = generateJsScriptEl(itemObj.url, libraryPath);
\n\t\t
});
\n\t
}
\n\n\t
return
{
\n\t\tlibraryScriptElMap,\n\t\tanalyseResult,\n\t}\n
}
\n\n
export function generateJsScriptEl(file, path) {\n
\t
let url = (path || '') + file;
\n\t
return `<script crossorigin=
\"
anonymous
\"
src=
\"
${url}
\"
></script>`;
\n
}
\n
"
],
"names"
:
[],
"mappings"
:
";;;;;;;;AAAA;;;;;AAKA,AAIA;AACA,MAAM,eAAe,GAAG,iBAAiB,CAAC;;AAE1C,AAAO,SAAS,eAAe,CAAC,GAAG,EAAE;CACpC,IAAI,MAAM,GAAG,EAAE,CAAC;CAChB,IAAI,WAAW,GAAG,GAAG,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;CAC7C,KAAK,IAAI,SAAS,IAAI,WAAW,EAAE;EAClC,IAAI,IAAI,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;EACrD,IAAI,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;EAC1B,IAAI,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;;EAE9B,IAAI,IAAI,GAAG;GACV,MAAM,EAAE,SAAS;GACjB,KAAK;GACL,CAAC;EACF,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE;GACzB,IAAI,CAAC,QAAQ,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;GACvB;EACD,MAAM,CAAC,IAAI,CAAC,IAAI,EAAC;EACjB;CACD,OAAO,MAAM,CAAC;CACd;;AAED,AAAO,SAAS,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,aAAa,EAAE;CACxD,aAAa,GAAG,aAAa,IAAI,eAAe,CAAC,GAAG,CAAC,CAAC;CACtD,KAAK,IAAI,IAAI,IAAI,aAAa,EAAE;EAC/B,IAAI,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,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;EACN,kBAAkB;EAClB,aAAa;EACb;CACD;;AAED,AAAO,SAAS,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE;CAC9C,IAAI,GAAG,GAAG,CAAC,IAAI,IAAI,EAAE,IAAI,IAAI,CAAC;CAC9B,OAAO,CAAC,qCAAqC,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;CAChE;;;;;;;"
}
{
"version"
:
3
,
"file"
:
"index.js"
,
"sources"
:
[
"../src/index.js"
],
"sourcesContent"
:
[
"/**
\n
* Created by rockyl on 2019-11-13.
\n
*
\n
* 模板填充
\n
*/
\n\n
import camelcase from 'camelcase'
\n\n
const TAG = 'zeroing-template-fill';
\n\n
const dynamicValueReg = /
\\
$[
\\
w|(
\\
.)]+
\\
$/g;
\n\n
export function analyseTemplate(tpl) {\n
\t
let result = [];
\n\t
let matchResult = tpl.match(dynamicValueReg);
\n\t
for (let matchItem of matchResult) {\n
\t\t
let hint = matchItem.substr(1, matchItem.length - 2);
\n\t\t
let arr = hint.split('.');
\n\t\t
let field = camelcase(arr[0]);
\n\n\t\t
let item = {\n
\t\t\t
source: matchItem,
\n\t\t\t
field,
\n\t\t
};
\n\t\t
if (arr[1] !== undefined) {\n
\t\t\t
item.subField = arr[1];
\n\t\t
}
\n\t\t
result.push(item)
\n\t
}
\n\t
return result;
\n
}
\n\n
export function fillTemplate(tpl, params, analyseResult) {\n
\t
analyseResult = analyseResult || analyseTemplate(tpl);
\n\t
for (let item of analyseResult) {\n
\t\t
let fieldData = params[item.field];
\n\t\t
if (fieldData && item.subField) {\n
\t\t\t
fieldData = fieldData[item.subField];
\n\t\t
}
\n\t\t
if (fieldData) {\n
\t\t\t
tpl = tpl.replace(item.source, fieldData);
\n\t\t
}
\n\t
}
\n\n\t
return tpl;
\n
}
\n\n
export async function generateLibraryScriptEl(tpl, dependencies, getPackages, libraryPath, debug) {\n
\t
let analyseResult = analyseTemplate(tpl);
\n\t
let librariesHint = analyseResult.filter(item => item.field === 'libraries').map(item => item.subField);
\n\n\t
let libraryScriptElMap = {};
\n\t
if (librariesHint.length > 0) {\n
\t\t
let schema = {};
\n\t\t
for (let libName of librariesHint) {\n
\t\t\t
if (dependencies[libName]) {\n
\t\t\t\t
schema[libName] = dependencies[libName];
\n\t\t\t
}
\n\t\t
}
\n\n\t\t
(await getPackages(schema, 0)).forEach(item => {\n
\t\t\t
let itemObj = typeof item.data === 'string' ? JSON.parse(item.data) : item.data;
\n\t\t\t
let urlField = debug && itemObj.url_dbg ? 'url_dbg' : 'url';
\n\t\t\t
libraryScriptElMap[itemObj.id] = generateJsScriptEl(itemObj[urlField], libraryPath);
\n\t\t
});
\n\t
}
\n\n\t
return
{
\n\t\tlibraryScriptElMap,\n\t\tanalyseResult,\n\t}\n
}
\n\n
export function generateJsScriptEl(file, path) {\n
\t
let url = (path || '') + file;
\n\t
return `<script crossorigin=
\"
anonymous
\"
src=
\"
${url}
\"
></script>`;
\n
}
\n
"
],
"names"
:
[],
"mappings"
:
";;;;;;;;AAAA;;;;;AAKA,AAIA;AACA,MAAM,eAAe,GAAG,iBAAiB,CAAC;;AAE1C,AAAO,SAAS,eAAe,CAAC,GAAG,EAAE;CACpC,IAAI,MAAM,GAAG,EAAE,CAAC;CAChB,IAAI,WAAW,GAAG,GAAG,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;CAC7C,KAAK,IAAI,SAAS,IAAI,WAAW,EAAE;EAClC,IAAI,IAAI,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;EACrD,IAAI,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;EAC1B,IAAI,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;;EAE9B,IAAI,IAAI,GAAG;GACV,MAAM,EAAE,SAAS;GACjB,KAAK;GACL,CAAC;EACF,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE;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ACD;;EAED,CAAC,MAAM,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,IAAI,IAAI;GAC9C,IAAI,OAAO,GAAG,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC;GAChF,IAAI,QAAQ,GAAG,KAAK,IAAI,OAAO,CAAC,OAAO,GAAG,SAAS,GAAG,KAAK,CAAC;GAC5D,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,kBAAkB,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,WAAW,CAAC,CAAC;GACpF,CAAC,CAAC;EACH;;CAED,OAAO;EACN,kBAAkB;EAClB,aAAa;EACb;CACD;;AAED,AAAO,SAAS,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE;CAC9C,IAAI,GAAG,GAAG,CAAC,IAAI,IAAI,EAAE,IAAI,IAAI,CAAC;CAC9B,OAAO,CAAC,qCAAqC,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;CAChE;;;;;;;"
}
\ No newline at end of file
\ No newline at end of file
dist/index.umd.js
View file @
2191ce9a
...
@@ -49,7 +49,7 @@
...
@@ -49,7 +49,7 @@
return
tpl
;
return
tpl
;
}
}
async
function
generateLibraryScriptEl
(
tpl
,
dependencies
,
getPackages
,
libraryPath
)
{
async
function
generateLibraryScriptEl
(
tpl
,
dependencies
,
getPackages
,
libraryPath
,
debug
)
{
let
analyseResult
=
analyseTemplate
(
tpl
);
let
analyseResult
=
analyseTemplate
(
tpl
);
let
librariesHint
=
analyseResult
.
filter
(
item
=>
item
.
field
===
'libraries'
).
map
(
item
=>
item
.
subField
);
let
librariesHint
=
analyseResult
.
filter
(
item
=>
item
.
field
===
'libraries'
).
map
(
item
=>
item
.
subField
);
...
@@ -64,7 +64,8 @@
...
@@ -64,7 +64,8 @@
(
await
getPackages
(
schema
,
0
)).
forEach
(
item
=>
{
(
await
getPackages
(
schema
,
0
)).
forEach
(
item
=>
{
let
itemObj
=
typeof
item
.
data
===
'string'
?
JSON
.
parse
(
item
.
data
)
:
item
.
data
;
let
itemObj
=
typeof
item
.
data
===
'string'
?
JSON
.
parse
(
item
.
data
)
:
item
.
data
;
libraryScriptElMap
[
itemObj
.
id
]
=
generateJsScriptEl
(
itemObj
.
url
,
libraryPath
);
let
urlField
=
debug
&&
itemObj
.
url_dbg
?
'url_dbg'
:
'url'
;
libraryScriptElMap
[
itemObj
.
id
]
=
generateJsScriptEl
(
itemObj
[
urlField
],
libraryPath
);
});
});
}
}
...
...
dist/index.umd.js.map
View file @
2191ce9a
{
"version"
:
3
,
"file"
:
"index.umd.js"
,
"sources"
:
[
"../src/index.js"
],
"sourcesContent"
:
[
"/**
\n
* Created by rockyl on 2019-11-13.
\n
*
\n
* 模板填充
\n
*/
\n\n
import camelcase from 'camelcase'
\n\n
const TAG = 'zeroing-template-fill';
\n\n
const dynamicValueReg = /
\\
$[
\\
w|(
\\
.)]+
\\
$/g;
\n\n
export function analyseTemplate(tpl) {\n
\t
let result = [];
\n\t
let matchResult = tpl.match(dynamicValueReg);
\n\t
for (let matchItem of matchResult) {\n
\t\t
let hint = matchItem.substr(1, matchItem.length - 2);
\n\t\t
let arr = hint.split('.');
\n\t\t
let field = camelcase(arr[0]);
\n\n\t\t
let item = {\n
\t\t\t
source: matchItem,
\n\t\t\t
field,
\n\t\t
};
\n\t\t
if (arr[1] !== undefined) {\n
\t\t\t
item.subField = arr[1];
\n\t\t
}
\n\t\t
result.push(item)
\n\t
}
\n\t
return result;
\n
}
\n\n
export function fillTemplate(tpl, params, analyseResult) {\n
\t
analyseResult = analyseResult || analyseTemplate(tpl);
\n\t
for (let item of analyseResult) {\n
\t\t
let fieldData = params[item.field];
\n\t\t
if (fieldData && item.subField) {\n
\t\t\t
fieldData = fieldData[item.subField];
\n\t\t
}
\n\t\t
if (fieldData) {\n
\t\t\t
tpl = tpl.replace(item.source, fieldData);
\n\t\t
}
\n\t
}
\n\n\t
return tpl;
\n
}
\n\n
export async function generateLibraryScriptEl(tpl, dependencies, getPackages, libraryPath) {\n
\t
let analyseResult = analyseTemplate(tpl);
\n\t
let librariesHint = analyseResult.filter(item => item.field === 'libraries').map(item => item.subField);
\n\n\t
let libraryScriptElMap = {};
\n\t
if (librariesHint.length > 0) {\n
\t\t
let schema = {};
\n\t\t
for (let libName of librariesHint) {\n
\t\t\t
if (dependencies[libName]) {\n
\t\t\t\t
schema[libName] = dependencies[libName];
\n\t\t\t
}
\n\t\t
}
\n\n\t\t
(await getPackages(schema, 0)).forEach(item => {\n
\t\t\t
let itemObj = typeof item.data === 'string' ? JSON.parse(item.data) : item.data;
\n\t\t\t
libraryScriptElMap[itemObj.id] = generateJsScriptEl(itemObj.url, libraryPath);
\n\t\t
});
\n\t
}
\n\n\t
return
{
\n\t\tlibraryScriptElMap,\n\t\tanalyseResult,\n\t}\n
}
\n\n
export function generateJsScriptEl(file, path) {\n
\t
let url = (path || '') + file;
\n\t
return `<script crossorigin=
\"
anonymous
\"
src=
\"
${url}
\"
></script>`;
\n
}
\n
"
],
"names"
:
[],
"mappings"
:
";;;;;;;;CAAA;CACA;CACA;CACA;CACA;AACA,AAIA;CACA,MAAM,eAAe,GAAG,iBAAiB,CAAC;;AAE1C,CAAO,SAAS,eAAe,CAAC,GAAG,EAAE;CACrC,CAAC,IAAI,MAAM,GAAG,EAAE,CAAC;CACjB,CAAC,IAAI,WAAW,GAAG,GAAG,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;CAC9C,CAAC,KAAK,IAAI,SAAS,IAAI,WAAW,EAAE;CACpC,EAAE,IAAI,IAAI,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;CACvD,EAAE,IAAI,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;CAC5B,EAAE,IAAI,KAAK,GAA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\n\n
const TAG = 'zeroing-template-fill';
\n\n
const dynamicValueReg = /
\\
$[
\\
w|(
\\
.)]+
\\
$/g;
\n\n
export function analyseTemplate(tpl) {\n
\t
let result = [];
\n\t
let matchResult = tpl.match(dynamicValueReg);
\n\t
for (let matchItem of matchResult) {\n
\t\t
let hint = matchItem.substr(1, matchItem.length - 2);
\n\t\t
let arr = hint.split('.');
\n\t\t
let field = camelcase(arr[0]);
\n\n\t\t
let item = {\n
\t\t\t
source: matchItem,
\n\t\t\t
field,
\n\t\t
};
\n\t\t
if (arr[1] !== undefined) {\n
\t\t\t
item.subField = arr[1];
\n\t\t
}
\n\t\t
result.push(item)
\n\t
}
\n\t
return result;
\n
}
\n\n
export function fillTemplate(tpl, params, analyseResult) {\n
\t
analyseResult = analyseResult || analyseTemplate(tpl);
\n\t
for (let item of analyseResult) {\n
\t\t
let fieldData = params[item.field];
\n\t\t
if (fieldData && item.subField) {\n
\t\t\t
fieldData = fieldData[item.subField];
\n\t\t
}
\n\t\t
if (fieldData) {\n
\t\t\t
tpl = tpl.replace(item.source, fieldData);
\n\t\t
}
\n\t
}
\n\n\t
return tpl;
\n
}
\n\n
export async function generateLibraryScriptEl(tpl, dependencies, getPackages, libraryPath, debug) {\n
\t
let analyseResult = analyseTemplate(tpl);
\n\t
let librariesHint = analyseResult.filter(item => item.field === 'libraries').map(item => item.subField);
\n\n\t
let libraryScriptElMap = {};
\n\t
if (librariesHint.length > 0) {\n
\t\t
let schema = {};
\n\t\t
for (let libName of librariesHint) {\n
\t\t\t
if (dependencies[libName]) {\n
\t\t\t\t
schema[libName] = dependencies[libName];
\n\t\t\t
}
\n\t\t
}
\n\n\t\t
(await getPackages(schema, 0)).forEach(item => {\n
\t\t\t
let itemObj = typeof item.data === 'string' ? JSON.parse(item.data) : item.data;
\n\t\t\t
let urlField = debug && itemObj.url_dbg ? 'url_dbg' : 'url';
\n\t\t\t
libraryScriptElMap[itemObj.id] = generateJsScriptEl(itemObj[urlField], libraryPath);
\n\t\t
});
\n\t
}
\n\n\t
return
{
\n\t\tlibraryScriptElMap,\n\t\tanalyseResult,\n\t}\n
}
\n\n
export function generateJsScriptEl(file, path) {\n
\t
let url = (path || '') + file;
\n\t
return `<script crossorigin=
\"
anonymous
\"
src=
\"
${url}
\"
></script>`;
\n
}
\n
"
],
"names"
:
[],
"mappings"
:
";;;;;;;;CAAA;CACA;CACA;CACA;CACA;AACA,AAIA;CACA,MAAM,eAAe,GAAG,iBAAiB,CAAC;;AAE1C,CAAO,SAAS,eAAe,CAAC,GAAG,EAAE;CACrC,CAAC,IAAI,MAAM,GAAG,EAAE,CAAC;CACjB,CAAC,IAAI,WAAW,GAAG,GAAG,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;CAC9C,CAAC,KAAK,IAAI,SAAS,IAAI,WAAW,EAAE;CACpC,EAAE,IAAI,IAAI,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;CACvD,EAAE,IAAI,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;CAC5B,EAAE,IAAI,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;;CAEhC,EAAE,IAAI,IAAI,GAAG;CACb,GAAG,MAAM,EAAE,SAAS;CACpB,GAAG,KAAK;CACR,GAAG,CAAC;CACJ,EAAE,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE;CAC5B,GAAG,IAAI,CAAC,QAAQ,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;CAC1B,GAAG;CACH,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,EAAC;CACnB,EAAE;CACF,CAAC,OAAO,MAAM,CAAC;CACf,CAAC;;AAED,CAAO,SAAS,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,aAAa,EAAE;CACzD,CAAC,aAAa,GAAG,aAAa,IAAI,eAAe,CAAC,GAAG,CAAC,CAA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AI,CAAC,IAAI,KAAK,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC;CACnF,GAAG,IAAI,QAAQ,GAAG,KAAK,IAAI,OAAO,CAAC,OAAO,GAAG,SAAS,GAAG,KAAK,CAAC;CAC/D,GAAG,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,kBAAkB,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,WAAW,CAAC,CAAC;CACvF,GAAG,CAAC,CAAC;CACL,EAAE;;CAEF,CAAC,OAAO;CACR,EAAE,kBAAkB;CACpB,EAAE,aAAa;CACf,EAAE;CACF,CAAC;;AAED,CAAO,SAAS,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE;CAC/C,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,IAAI,EAAE,IAAI,IAAI,CAAC;CAC/B,CAAC,OAAO,CAAC,qCAAqC,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;CACjE,CAAC;;;;;;;;;;;;;;;"
}
\ No newline at end of file
\ No newline at end of file
src/index.js
View file @
2191ce9a
...
@@ -45,7 +45,7 @@ export function fillTemplate(tpl, params, analyseResult) {
...
@@ -45,7 +45,7 @@ export function fillTemplate(tpl, params, analyseResult) {
return
tpl
;
return
tpl
;
}
}
export
async
function
generateLibraryScriptEl
(
tpl
,
dependencies
,
getPackages
,
libraryPath
)
{
export
async
function
generateLibraryScriptEl
(
tpl
,
dependencies
,
getPackages
,
libraryPath
,
debug
)
{
let
analyseResult
=
analyseTemplate
(
tpl
);
let
analyseResult
=
analyseTemplate
(
tpl
);
let
librariesHint
=
analyseResult
.
filter
(
item
=>
item
.
field
===
'libraries'
).
map
(
item
=>
item
.
subField
);
let
librariesHint
=
analyseResult
.
filter
(
item
=>
item
.
field
===
'libraries'
).
map
(
item
=>
item
.
subField
);
...
@@ -60,7 +60,8 @@ export async function generateLibraryScriptEl(tpl, dependencies, getPackages, li
...
@@ -60,7 +60,8 @@ export async function generateLibraryScriptEl(tpl, dependencies, getPackages, li
(
await
getPackages
(
schema
,
0
)).
forEach
(
item
=>
{
(
await
getPackages
(
schema
,
0
)).
forEach
(
item
=>
{
let
itemObj
=
typeof
item
.
data
===
'string'
?
JSON
.
parse
(
item
.
data
)
:
item
.
data
;
let
itemObj
=
typeof
item
.
data
===
'string'
?
JSON
.
parse
(
item
.
data
)
:
item
.
data
;
libraryScriptElMap
[
itemObj
.
id
]
=
generateJsScriptEl
(
itemObj
.
url
,
libraryPath
);
let
urlField
=
debug
&&
itemObj
.
url_dbg
?
'url_dbg'
:
'url'
;
libraryScriptElMap
[
itemObj
.
id
]
=
generateJsScriptEl
(
itemObj
[
urlField
],
libraryPath
);
});
});
}
}
...
...
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