tyhuynh-laya-cmd 1.0.0
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.
- package/dist/index.js +2 -0
- package/package.json +44 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";const path=require("path"),fs=require("fs-extra"),{program:program}=require("commander");require("colors");const{loadProjectConfig:loadProjectConfig}=require("./src/config/ProjectConfig"),{loadStyles:loadStyles,invalidateCache:invalidateStyles}=require("./src/parsers/StylesParser"),{loadPageStyles:loadPageStyles,invalidateCache:invalidatePages}=require("./src/parsers/PageParser"),{generateUICode:generateUICode}=require("./src/generators/UICodeGen"),{generateAtlas:generateAtlas}=require("./src/generators/AtlasGen"),{collectFiles:collectFiles}=require("./src/utils/FileUtils");async function runUI(e){const{project:o,atlas:a,code:t,clear:n,watch:r}=e,l=t||!a&&!t,c=a||!a&&!t,s=path.resolve(o);fs.existsSync(s)||(console.error(`[ERROR] Project directory not found: ${s}`.red),process.exit(1)),console.log(`\n${"⚡ Custom LayaAir2 Build Tool".cyan.bold}`),console.log(` Project: ${s.gray}`),console.log(` Mode: ${[l&&"CODE",c&&"ATLAS"].filter(Boolean).join(" + ").yellow}`),n&&console.log(` Cache: ${"CLEARED".red}`),r&&console.log(` Watch: ${"ENABLED".green}`),console.log(""),await build(s,{doCode:l,doAtlas:c,clear:n}),r&&await startWatchMode(s,{doCode:l,doAtlas:c})}async function build(e,{doCode:o,doAtlas:a,clear:t,hint:n={}}){const r=Date.now();let l;try{l=loadProjectConfig(e)}catch(e){return void console.error(`[ERROR] Cannot load .laya config: ${e.message}`.red)}const c=path.dirname(e),s=path.join(e,"pages"),i=path.join(c,l.codeExportPath,"layaMaxUI.ts"),d=path.join(e,".custom-cmd-cache"),g=path.join(d,"code-cache.json"),h=path.join(d,"atlas-cache.json"),p=o&&!n.atlasOnly,u=a&&!n.codeOnly,y=[];p&&y.push(generateUICode({pagesDir:s,outputPath:i,cachePath:g,projectPath:c,resExportPath:path.join(c,l.resExportPath),clear:t,changedScenes:n.changedScenes||null,log:e=>console.log(` ${e}`)}).then(e=>{console.log(` ${"UI Code".green}: ${e.built} built, ${e.skipped} skipped`)}).catch(e=>{console.error(` ${"[CODE ERROR]".red} ${e.message}`)})),u&&y.push((async()=>{try{const o=path.join(e,"styles.xml"),a=loadStyles(o);await generateAtlas({styleMap:a,projectConfig:l,assetDir:path.join(e,"assets"),outputDir:path.join(c,l.resExportPath),cachePath:h,clear:t,changedDirs:n.changedDirs||null,log:e=>console.log(` ${e}`)}),console.log(` ${"Atlas".green}: done`)}catch(e){console.error(` ${"[ATLAS ERROR]".red} ${e.message}`)}})()),await Promise.all(y);const m=((Date.now()-r)/1e3).toFixed(2);console.log(`\n ${"✓ Build complete".green.bold} in ${m}s\n`)}async function startWatchMode(e,{doCode:o,doAtlas:a}){let t;try{t=require("chokidar")}catch{console.error("[WATCH] chokidar not installed. Run: npm install chokidar".red),process.exit(1)}const n=path.join(e,"pages"),r=path.join(e,"assets"),l=path.join(e,"styles.xml"),c=path.join(e,"pageStyles.xml");console.log(`${"👀 Watching for changes...".cyan} (Ctrl+C to stop)\n`),console.log(" .scene → UI code rebuild only"),console.log(" images → Atlas rebuild (affected dir only)"),console.log(" *.xml → Full rebuild\n");let s=null,i=new Set,d=new Set,g=!1;function h(){clearTimeout(s),s=setTimeout(async()=>{const t=[...i],n=[...d],c=g;i.clear(),d.clear(),g=!1;const s=[...t,...n,...c?[l]:[]];if(0===s.length)return;if(console.log(`\n${"⟳ Changed".yellow}: `+s.map(o=>path.relative(e,o)).join(", ")),c)return void await build(e,{doCode:o,doAtlas:a,clear:!1,hint:{}});const h=o&&t.length>0,p=a&&n.length>0;if(!h&&!p)return;let u=null;p&&(u=new Set(n.map(e=>path.relative(r,path.dirname(e)).replace(/\\/g,"/"))),console.log(` ${"Atlas scope".cyan}: ${[...u].join(", ")}`));let y=null;h&&(y=new Set(t)),await build(e,{doCode:o,doAtlas:a,clear:!1,hint:{codeOnly:h&&!p,atlasOnly:p&&!h,changedDirs:u,changedScenes:y}})},300)}function p(e){i.add(e),h()}function u(e){d.add(e),h()}function y(e){e===l&&invalidateStyles(),e===c&&invalidatePages(),g=!0,h()}const m={ignoreInitial:!0,usePolling:!1};o&&t.watch(path.join(n,"**","*.scene"),m).on("add",p).on("change",p).on("unlink",p).on("error",e=>console.error(`[WATCH ERROR] ${e}`.red)),a&&t.watch([`${r}/**/*.png`,`${r}/**/*.jpg`],m).on("add",u).on("change",u).on("unlink",u).on("error",e=>console.error(`[WATCH ERROR] ${e}`.red)),t.watch([l,c],m).on("add",y).on("change",y).on("error",e=>console.error(`[WATCH ERROR] ${e}`.red))}program.name("custom-cmd").description("Custom LayaAir 2 fast incremental UI build tool").version("1.0.0"),program.command("ui").description("Export UI code and/or atlas").option("-p, --project <dir>","Path to laya/ project directory",process.cwd()).option("-a, --atlas","Generate atlas sprite sheets",!1).option("-d, --code","Generate TypeScript UI code",!1).option("-c, --clear","Clear cache (force full rebuild)",!1).option("-w, --watch","Watch mode",!1).action(async e=>{await runUI(e)}),program.parse(process.argv);
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tyhuynh-laya-cmd",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Custom LayaAir 2 UI build tool - fast incremental atlas and UI code generation",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"tyhuynh-laya-cmd": "./dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"prepublishOnly": "node build-dist.js",
|
|
11
|
+
"build": "node index.js ui -p ../../client/laya -a -d",
|
|
12
|
+
"build:clean": "node index.js ui -p ../../client/laya -a -d -c",
|
|
13
|
+
"build:ui": "node index.js ui -p ../../client/laya -d",
|
|
14
|
+
"build:atlas": "node index.js ui -p ../../client/laya -a",
|
|
15
|
+
"watch": "node index.js ui -p ../../client/laya -a -d -w",
|
|
16
|
+
"migrate": "node scripts/migrate-stray-assets.js -p ../../client/laya",
|
|
17
|
+
"migrate:dry": "node scripts/migrate-stray-assets.js --dry-run -p ../../client/laya"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"layaair",
|
|
21
|
+
"layaair2",
|
|
22
|
+
"ui",
|
|
23
|
+
"atlas",
|
|
24
|
+
"build-tool",
|
|
25
|
+
"game"
|
|
26
|
+
],
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"chokidar": "^3.6.0",
|
|
29
|
+
"colors": "^1.4.0",
|
|
30
|
+
"commander": "^11.0.0",
|
|
31
|
+
"fast-xml-parser": "^4.3.0",
|
|
32
|
+
"fs-extra": "^11.1.1",
|
|
33
|
+
"image-size": "^2.0.2",
|
|
34
|
+
"maxrects-packer": "^2.7.3",
|
|
35
|
+
"sharp": "^0.33.0"
|
|
36
|
+
},
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=16.0.0"
|
|
39
|
+
},
|
|
40
|
+
"license": "ISC",
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"terser": "^5.46.1"
|
|
43
|
+
}
|
|
44
|
+
}
|