tyhuynh-laya-cmd 1.0.10 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const path=require("path"),fs=require("fs-extra"),{writeIfChanged:writeIfChanged}=require("../utils/FileUtils"),{resolveStyle:resolveStyle}=require("../parsers/StylesParser"),EDITOR_KEYS=["searchKey","nodeParent","maxID","label","isOpen","isDirectory","isAniNode","hasChild","selectedBox","switchAble","removeAble","$HIDDEN","$LOCKED","selecteID","x","y"],ASSET_REF_RE=/\"([^\"]+\.(?:png|jpg|jpeg|sk|ani))\"/gi;function stripEditorKeys(e,s){if(e&&"object"==typeof e){for(const s of EDITOR_KEYS)delete e[s];if("Script"===e.type&&e.source){e.props||(e.props={});let s=e.source;s.startsWith("src/")&&(s=s.substring(4)),e.props.runtime=s,delete e.source}if(s&&e.props&&e.props.skin){const t=resolveStyle(s,e.props.skin);t&&t.propsMap&&(e.props=Object.assign({},t.propsMap,e.props))}if("Button"===e.type&&e.props&&void 0===e.props.stateNum&&(e.props.stateNum=1),"UIView"===e.type&&e.source){const s=path.basename(e.source,".scene");if(e.type=s,e.props||(e.props={}),e.props.runtime)e.props.runtime.startsWith("src/")&&(e.props.runtime=e.props.runtime.substring(4));else{const t="ui."+e.source.substring(0,e.source.lastIndexOf("/")).replace(/\\/g,"/").replace(/\//g,".");e.props.runtime=`${t}.${s}UI`}delete e.source}if(Array.isArray(e.child))if(0===e.child.length)delete e.child;else for(const t of e.child)stripEditorKeys(t,s)}}function
|
|
1
|
+
"use strict";const path=require("path"),fs=require("fs-extra"),{writeIfChanged:writeIfChanged}=require("../utils/FileUtils"),{resolveStyle:resolveStyle}=require("../parsers/StylesParser"),EDITOR_KEYS=["searchKey","nodeParent","maxID","label","isOpen","isDirectory","isAniNode","hasChild","selectedBox","switchAble","removeAble","$HIDDEN","$LOCKED","selecteID","x","y"],ASSET_REF_RE=/\"([^\"]+\.(?:png|jpg|jpeg|sk|ani|scene))\"/gi;function stripEditorKeys(e,s){if(e&&"object"==typeof e){for(const s of EDITOR_KEYS)delete e[s];if("Script"===e.type&&e.source){e.props||(e.props={});let s=e.source;s.startsWith("src/")&&(s=s.substring(4)),e.props.runtime=s,delete e.source}if(s&&e.props&&e.props.skin){const t=resolveStyle(s,e.props.skin);t&&t.propsMap&&(e.props=Object.assign({},t.propsMap,e.props))}if("Button"===e.type&&e.props&&void 0===e.props.stateNum&&(e.props.stateNum=1),"UIView"===e.type&&e.source){const s=path.basename(e.source,".scene");if(e.type=s,e.props||(e.props={}),e.props.runtime)e.props.runtime.startsWith("src/")&&(e.props.runtime=e.props.runtime.substring(4));else{const t="ui."+e.source.substring(0,e.source.lastIndexOf("/")).replace(/\\/g,"/").replace(/\//g,".");e.props.runtime=`${t}.${s}UI`}delete e.source}if(Array.isArray(e.child))if(0===e.child.length)delete e.child;else for(const t of e.child)stripEditorKeys(t,s)}}function collectSceneRefs(e,s={}){if(!e||"object"!=typeof e)return Object.keys(s);if("UIView"===e.type&&"string"==typeof e.source&&(s[e.source]=!0),Array.isArray(e.child))for(const t of e.child)collectSceneRefs(t,s);return Object.keys(s)}function buildLoadList(e,s=[]){const t=JSON.stringify(e),n={};let r;for(ASSET_REF_RE.lastIndex=0;null!==(r=ASSET_REF_RE.exec(t));)n[r[1]]=!0;for(const e of s)n[e]=!0;return Object.keys(n)}function buildSceneJson(e,s){const t=collectSceneRefs(e),n=JSON.parse(JSON.stringify(e));return stripEditorKeys(n,s),n.loadList=buildLoadList(n,t),n.loadList3D=[],n}async function exportSceneJsonFiles(e){const{resExportPath:s,scenes:t,separatedScenes:n=new Set,styleMap:r,log:o=console.log}=e,i={};let c=0;for(const{relPath:e,parsed:l}of t){const t=buildSceneJson(l.rawJson,r),p=e.replace(/\.scene$/i,".json"),a=path.join(s,p);if(n.has(e))i[p]=t,fs.existsSync(a)&&(fs.unlinkSync(a),o(`[SceneJsonGen] ✗ Removed stale standalone: ${p}`));else{fs.ensureDirSync(path.dirname(a));writeIfChanged(a,JSON.stringify(t))&&o(`[SceneJsonGen] ✓ Written: ${p}`),c++}}const l=path.join(s,"ui.json");return Object.keys(i).length>0?(fs.ensureDirSync(path.dirname(l)),writeIfChanged(l,JSON.stringify(i)),o(`[SceneJsonGen] ✓ Bundled ${Object.keys(i).length} scenes → ui.json`)):fs.existsSync(l)&&(fs.unlinkSync(l),o("[SceneJsonGen] ✓ Deleted empty ui.json")),{bundled:Object.keys(i).length,standalone:c}}module.exports={stripEditorKeys:stripEditorKeys,collectSceneRefs:collectSceneRefs,buildLoadList:buildLoadList,buildSceneJson:buildSceneJson,exportSceneJsonFiles:exportSceneJsonFiles};
|