@nano191225/scriptup 1.2.0 → 1.3.1
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/README.ja.md +1 -0
- package/README.md +1 -0
- package/dist/index.js +3 -3
- package/package.json +1 -1
package/README.ja.md
CHANGED
package/README.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{Command as e,Option as t}from"commander";import n from"ora";import*as r from"node:fs";import*as i from"node:path";import a from"chalk";import{execSync as o,spawnSync as s}from"node:child_process";import{randomUUID as c}from"node:crypto";import*as l from"node:os";import{build as u,mergeConfig as d}from"tsdown";import{pathToFileURL as f}from"node:url";function p(e){console.log(`${a.blue(`[INFO]`)} ${e}`)}function m(e){console.log(`${a.gray(`[LOG]`)} ${e}`)}function h(e){console.log(`${a.yellow(`[WARN]`)} ${e}`)}function g(e){console.error(`${a.red(`[ERROR]`)} ${e}`)}function _(e){console.log(`${a.green(`[DONE]`)} ${e}`)}function v(e){return e.type===`script`}function y(e){return`module_name`in e}function b(){let e=i.resolve(`manifest.json`);r.existsSync(e)||(g(`manifest.json not found.`),process.exit(1));let t=r.readFileSync(e,`utf-8`);return JSON.parse(t)}function x(e){let t=i.resolve(`manifest.json`),n=JSON.stringify(e,null,` `);r.writeFileSync(t,n,`utf-8`)}async function S(e){let t=`https://registry.npmjs.org/${e}`,n=await fetch(t);if(!n.ok)throw Error(`Failed to fetch versions for ${e}: ${n.statusText}`);let r=await n.json(),i=Object.keys(r.versions).reverse();return i.sort((e,t)=>{let n=e=>e.includes(`stable`)?0:e.includes(`preview`)?1:2;return n(e)-n(t)}),i}function C(e){let t=e.indexOf(`-`);if(t===-1)return e;let n=e.substring(t).indexOf(`.`);if(n===-1)return e;let r=t+n+1,i=e.substring(r),a=i.indexOf(`-`);return a===-1?i:i.substring(0,a)}function w(e){let t=e.indexOf(`-`);if(t===-1)return e;let n=e.substring(t).indexOf(`.`);return n===-1?e:e.substring(0,t+n)}function T(){let e=process.cwd(),t=i.resolve(e,`package.json`);if(r.existsSync(t)){let e=JSON.parse(r.readFileSync(t,`utf-8`));if(e.packageManager){let t=e.packageManager.split(`@`)[0];if(E(t))return m(`Detected package manager from package.json: ${t}`),t}}return r.existsSync(i.resolve(e,`bun.lockb`))||r.existsSync(i.resolve(e,`bun.lock`))?(m(`Detected package manager from lock file: bun`),`bun`):r.existsSync(i.resolve(e,`pnpm-lock.yaml`))?(m(`Detected package manager from lock file: pnpm`),`pnpm`):r.existsSync(i.resolve(e,`yarn.lock`))?(m(`Detected package manager from lock file: yarn`),`yarn`):r.existsSync(i.resolve(e,`package-lock.json`))?(m(`Detected package manager from lock file: npm`),`npm`):(m(`No lock file found. Defaulting to npm.`),`npm`)}function E(e){return[`npm`,`pnpm`,`yarn`,`bun`].includes(e)}function ee(e){return e===`yarn`?`add`:`install`}function te(e){switch(e){case`npm`:return`--save-exact`;case`pnpm`:return`--save-exact`;case`yarn`:return`--exact`;case`bun`:return`--exact`}}function D(e){switch(e){case`npm`:return`--force`;case`pnpm`:return`--force`;case`yarn`:return;case`bun`:return`--force`}}function O(e,t){let n=ee(e),r=te(e),i=D(e),a=[e,n,t,e===`yarn`?`--dev`:`--save-dev`,r];i&&a.push(i),o(a.join(` `),{stdio:`pipe`,cwd:process.cwd()})}async function k(){let e=n(`Fetching Minecraft version...`).start(),t=await A();e.succeed(`Install modules for Minecraft version: ${t}`);let r=b();m(`Manifest loaded. Fetching new module versions...`);let i=T(),a=[],o=r.dependencies?.filter(y)??[];for(let e of o){let n=(await S(e.module_name)).find(e=>e.includes(t));n||(g(`No version found for ${e.module_name} matching MC ${t}`),process.exit(1)),e.version=w(n),m(`${e.module_name}: ${n}`),a.push({name:e.module_name,version:n})}x(r),m(`Module versions fetched and manifest updated.`);let s=n(`Installing modules...`).start();for(let e=0;e<a.length;e++){let t=a[e];s.text=`Installing modules... (${e+1}/${a.length}) ${t.name}`;try{O(i,`${t.name}@${t.version}`)}catch(e){s.fail(`Failed to install ${t.name}`),g(e instanceof Error?e.message:String(e)),process.exit(1)}}s.succeed(`All modules installed successfully.`)}async function A(){let e=(await S(`@minecraft/server`)).find(e=>e.includes(`-stable`));return e||(g(`No stable versions found.`),process.exit(1)),C(e)}async function j(){let e=n(`Fetching Minecraft version...`).start(),t=await M();e.succeed(`Install modules for Minecraft version: ${t}`);let r=b();m(`Manifest loaded. Fetching new module versions...`);let i=T(),a=[],o=r.dependencies?.filter(y)??[];for(let e of o){let n=(await S(e.module_name)).find(e=>e.includes(t));n||(g(`No version found for ${e.module_name} matching MC ${t}`),process.exit(1)),e.version=w(n),m(`${e.module_name}: ${n}`),a.push({name:e.module_name,version:n})}x(r),m(`Module versions fetched and manifest updated.`);let s=n(`Installing modules...`).start();for(let e=0;e<a.length;e++){let t=a[e];s.text=`Installing modules... (${e+1}/${a.length}) ${t.name}`;try{O(i,`${t.name}@${t.version}`)}catch(e){s.fail(`Failed to install ${t.name}`),g(e instanceof Error?e.message:String(e)),process.exit(1)}}s.succeed(`All modules installed successfully.`)}async function M(){let e=(await S(`@minecraft/server`)).find(e=>e.includes(`-preview`));return e||(g(`No preview versions found.`),process.exit(1)),C(e)}async function N(){let e=n(`Fetching Minecraft version...`).start(),t=await P();e.succeed(`Install modules for Minecraft version: ${t}`);let r=b();m(`Manifest loaded. Fetching new module versions...`);let i=T(),a=[],o=r.dependencies?.filter(y)??[];for(let e of o){let n=await S(e.module_name),r=n.find(e=>!e.includes(`stable`)&&!e.includes(`preview`)&&!e.includes(`internal`)&&!e.includes(`beta`)&&!e.startsWith(`0.`));r?e.version=r:(h(`No LTS versions found for ${e.module_name}. Falling back to stable.`),r=n.find(e=>e.includes(t)),r||(g(`No version found for ${e.module_name}`),process.exit(1)),e.version=C(r)),m(`${e.module_name}: ${r}`),a.push({name:e.module_name,version:r})}x(r),m(`Module versions fetched and manifest updated.`);let s=n(`Installing modules...`).start();for(let e=0;e<a.length;e++){let t=a[e];s.text=`Installing modules... (${e+1}/${a.length}) ${t.name}`;try{O(i,`${t.name}@${t.version}`)}catch(e){s.fail(`Failed to install ${t.name}`),g(e instanceof Error?e.message:String(e)),process.exit(1)}}s.succeed(`All modules installed successfully.`)}async function P(){let e=(await S(`@minecraft/server`)).find(e=>e.includes(`-stable`));return e||(g(`No stable versions found.`),process.exit(1)),C(e)}async function F(e){let t=await S(`@minecraft/server`),n=t.find(t=>t===e);if(n){p(`Found exact version: ${n}`);return}let r=t.find(t=>t.includes(e));r||(g(`Version not found: ${e}`),process.exit(1));let i=C(r);p(`Found version: ${i}`);let a=(await S(`@minecraft/server`)).find(e=>e.includes(i)),o=(await S(`@minecraft/server-ui`)).find(e=>e.includes(i));a&&p(`Server version: ${a}`),o&&p(`Server UI version: ${o}`)}const I=`1.
|
|
2
|
+
import{Command as e,Option as t}from"commander";import n from"ora";import*as r from"node:fs";import*as i from"node:path";import a from"chalk";import{execSync as o,spawnSync as s}from"node:child_process";import{randomUUID as c}from"node:crypto";import*as l from"node:os";import{build as u,mergeConfig as d}from"tsdown";import{pathToFileURL as f}from"node:url";function p(e){console.log(`${a.blue(`[INFO]`)} ${e}`)}function m(e){console.log(`${a.gray(`[LOG]`)} ${e}`)}function h(e){console.log(`${a.yellow(`[WARN]`)} ${e}`)}function g(e){console.error(`${a.red(`[ERROR]`)} ${e}`)}function _(e){console.log(`${a.green(`[DONE]`)} ${e}`)}function v(e){return e.type===`script`}function y(e){return`module_name`in e}function b(){let e=i.resolve(`manifest.json`);r.existsSync(e)||(g(`manifest.json not found.`),process.exit(1));let t=r.readFileSync(e,`utf-8`);return JSON.parse(t)}function x(e){let t=i.resolve(`manifest.json`),n=JSON.stringify(e,null,` `);r.writeFileSync(t,n,`utf-8`)}async function S(e){let t=`https://registry.npmjs.org/${e}`,n=await fetch(t);if(!n.ok)throw Error(`Failed to fetch versions for ${e}: ${n.statusText}`);let r=await n.json(),i=Object.keys(r.versions).reverse();return i.sort((e,t)=>{let n=e=>e.includes(`stable`)?0:e.includes(`preview`)?1:2;return n(e)-n(t)}),i}function C(e){let t=e.indexOf(`-`);if(t===-1)return e;let n=e.substring(t).indexOf(`.`);if(n===-1)return e;let r=t+n+1,i=e.substring(r),a=i.indexOf(`-`);return a===-1?i:i.substring(0,a)}function w(e){let t=e.indexOf(`-`);if(t===-1)return e;let n=e.substring(t).indexOf(`.`);return n===-1?e:e.substring(0,t+n)}function T(){let e=process.cwd(),t=i.resolve(e,`package.json`);if(r.existsSync(t)){let e=JSON.parse(r.readFileSync(t,`utf-8`));if(e.packageManager){let t=e.packageManager.split(`@`)[0];if(E(t))return m(`Detected package manager from package.json: ${t}`),t}}return r.existsSync(i.resolve(e,`bun.lockb`))||r.existsSync(i.resolve(e,`bun.lock`))?(m(`Detected package manager from lock file: bun`),`bun`):r.existsSync(i.resolve(e,`pnpm-lock.yaml`))?(m(`Detected package manager from lock file: pnpm`),`pnpm`):r.existsSync(i.resolve(e,`yarn.lock`))?(m(`Detected package manager from lock file: yarn`),`yarn`):r.existsSync(i.resolve(e,`package-lock.json`))?(m(`Detected package manager from lock file: npm`),`npm`):(m(`No lock file found. Defaulting to npm.`),`npm`)}function E(e){return[`npm`,`pnpm`,`yarn`,`bun`].includes(e)}function ee(e){return e===`yarn`?`add`:`install`}function te(e){switch(e){case`npm`:return`--save-exact`;case`pnpm`:return`--save-exact`;case`yarn`:return`--exact`;case`bun`:return`--exact`}}function D(e){switch(e){case`npm`:return`--force`;case`pnpm`:return`--force`;case`yarn`:return;case`bun`:return`--force`}}function O(e,t){let n=ee(e),r=te(e),i=D(e),a=[e,n,t,e===`yarn`?`--dev`:`--save-dev`,r];i&&a.push(i),o(a.join(` `),{stdio:`pipe`,cwd:process.cwd()})}async function k(){let e=n(`Fetching Minecraft version...`).start(),t=await A();e.succeed(`Install modules for Minecraft version: ${t}`);let r=b();m(`Manifest loaded. Fetching new module versions...`);let i=T(),a=[],o=r.dependencies?.filter(y)??[];for(let e of o){let n=(await S(e.module_name)).find(e=>e.includes(t));n||(g(`No version found for ${e.module_name} matching MC ${t}`),process.exit(1)),e.version=w(n),m(`${e.module_name}: ${n}`),a.push({name:e.module_name,version:n})}x(r),m(`Module versions fetched and manifest updated.`);let s=n(`Installing modules...`).start();for(let e=0;e<a.length;e++){let t=a[e];s.text=`Installing modules... (${e+1}/${a.length}) ${t.name}`;try{O(i,`${t.name}@${t.version}`)}catch(e){s.fail(`Failed to install ${t.name}`),g(e instanceof Error?e.message:String(e)),process.exit(1)}}s.succeed(`All modules installed successfully.`)}async function A(){let e=(await S(`@minecraft/server`)).find(e=>e.includes(`-stable`));return e||(g(`No stable versions found.`),process.exit(1)),C(e)}async function j(){let e=n(`Fetching Minecraft version...`).start(),t=await M();e.succeed(`Install modules for Minecraft version: ${t}`);let r=b();m(`Manifest loaded. Fetching new module versions...`);let i=T(),a=[],o=r.dependencies?.filter(y)??[];for(let e of o){let n=(await S(e.module_name)).find(e=>e.includes(t));n||(g(`No version found for ${e.module_name} matching MC ${t}`),process.exit(1)),e.version=w(n),m(`${e.module_name}: ${n}`),a.push({name:e.module_name,version:n})}x(r),m(`Module versions fetched and manifest updated.`);let s=n(`Installing modules...`).start();for(let e=0;e<a.length;e++){let t=a[e];s.text=`Installing modules... (${e+1}/${a.length}) ${t.name}`;try{O(i,`${t.name}@${t.version}`)}catch(e){s.fail(`Failed to install ${t.name}`),g(e instanceof Error?e.message:String(e)),process.exit(1)}}s.succeed(`All modules installed successfully.`)}async function M(){let e=(await S(`@minecraft/server`)).find(e=>e.includes(`-preview`));return e||(g(`No preview versions found.`),process.exit(1)),C(e)}async function N(){let e=n(`Fetching Minecraft version...`).start(),t=await P();e.succeed(`Install modules for Minecraft version: ${t}`);let r=b();m(`Manifest loaded. Fetching new module versions...`);let i=T(),a=[],o=r.dependencies?.filter(y)??[];for(let e of o){let n=await S(e.module_name),r=n.find(e=>!e.includes(`stable`)&&!e.includes(`preview`)&&!e.includes(`internal`)&&!e.includes(`beta`)&&!e.startsWith(`0.`));r?e.version=r:(h(`No LTS versions found for ${e.module_name}. Falling back to stable.`),r=n.find(e=>e.includes(t)),r||(g(`No version found for ${e.module_name}`),process.exit(1)),e.version=C(r)),m(`${e.module_name}: ${r}`),a.push({name:e.module_name,version:r})}x(r),m(`Module versions fetched and manifest updated.`);let s=n(`Installing modules...`).start();for(let e=0;e<a.length;e++){let t=a[e];s.text=`Installing modules... (${e+1}/${a.length}) ${t.name}`;try{O(i,`${t.name}@${t.version}`)}catch(e){s.fail(`Failed to install ${t.name}`),g(e instanceof Error?e.message:String(e)),process.exit(1)}}s.succeed(`All modules installed successfully.`)}async function P(){let e=(await S(`@minecraft/server`)).find(e=>e.includes(`-stable`));return e||(g(`No stable versions found.`),process.exit(1)),C(e)}async function F(e){let t=await S(`@minecraft/server`),n=t.find(t=>t===e);if(n){p(`Found exact version: ${n}`);return}let r=t.find(t=>t.includes(e));r||(g(`Version not found: ${e}`),process.exit(1));let i=C(r);p(`Found version: ${i}`);let a=(await S(`@minecraft/server`)).find(e=>e.includes(i)),o=(await S(`@minecraft/server-ui`)).find(e=>e.includes(i));a&&p(`Server version: ${a}`),o&&p(`Server UI version: ${o}`)}const I=`1.3.1`;async function L(e){let t=i.resolve(e.targetDir),n=e.projectName?.trim()||i.basename(t),a=e.lib===!0,o=e.workflow!==!1;r.mkdirSync(t,{recursive:!0});let s=V(n,await B(),o,a),c=0;for(let[e,n]of Object.entries(s)){let a=i.join(t,e);if(r.existsSync(a)){h(`Skipped existing file: ${e}`);continue}r.mkdirSync(i.dirname(a),{recursive:!0}),r.writeFileSync(a,n,`utf-8`),m(`Created ${e}`),c+=1}if(c===0){h(`No files were created.`);return}_(`Project initialized in ${t}`)}function R(e){r.existsSync(e)&&r.readdirSync(e).length>0&&(g(`Target directory is not empty: ${e}`),process.exit(1))}function z(e,t){let n=s(t,[`.`],{cwd:e,shell:!0,stdio:`inherit`});if(n.error)throw n.error;if(n.status!==0)throw Error(`${t} exited with code ${n.status??`unknown`}`)}async function B(){try{let e=(await S(`@minecraft/server`)).find(e=>e.includes(`-stable`));if(!e)throw Error(`No stable @minecraft/server version found.`);let t=C(e),n=t,r=[],i={};for(let e of[`@minecraft/server`,`@minecraft/server-ui`]){let n=(await S(e)).find(e=>e.includes(t));if(!n){h(`Skipped ${e}: no version found for Minecraft ${t}`);continue}let a=w(n);r.push({module_name:e,version:a}),i[e]=n}return{engineVersion:n,dependencies:r,packageDependencies:i}}catch(e){return h(`Failed to resolve latest ScriptAPI dependencies: ${e instanceof Error?e.message:String(e)}`),h(`Creating the project without npm dependencies. You can run scriptup stable later.`),{engineVersion:`1.20.0`,dependencies:[],packageDependencies:{}}}}function V(e,t,n,r){let i=r?ae(e):null,a=H(e,t.engineVersion,t.dependencies,r),o=U(e,t.packageDependencies,r,i),s={".gitignore":`node_modules/
|
|
3
3
|
scripts
|
|
4
4
|
dist
|
|
5
5
|
*.mcpack
|
|
@@ -237,6 +237,6 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
237
237
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
238
238
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
239
239
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
240
|
-
SOFTWARE.`}function se(e){return e.trim().toLowerCase().replace(/[^a-z0-9-_\s]/g,``).replace(/\s+/g,`-`).replace(/-+/g,`-`).replace(/^-|-$/g,``)||`scriptapi-addon`}async function ce(e=process.cwd(),t={}){let n=i.resolve(e);await L({targetDir:n,workflow:t.workflow}),le(n),ue(n),de(n),p(`Initialization complete.`)}function le(e){let t=i.join(e,`tsdown.config.ts`);if(!r.existsSync(t)){let e=[`import { defineConfig } from "tsdown";`,``,`export default defineConfig(/* */);`,``].join(`
|
|
240
|
+
SOFTWARE.`}function se(e){return e.trim().toLowerCase().replace(/[^a-z0-9-_\s]/g,``).replace(/\s+/g,`-`).replace(/-+/g,`-`).replace(/^-|-$/g,``)||`scriptapi-addon`}async function ce(e=process.cwd(),t={}){let n=i.resolve(e);await L({targetDir:n,lib:t.lib,workflow:t.workflow}),le(n),ue(n),de(n),p(`Initialization complete.`)}function le(e){let t=i.join(e,`tsdown.config.ts`);if(!r.existsSync(t)){let e=[`import { defineConfig } from "tsdown";`,``,`export default defineConfig(/* */);`,``].join(`
|
|
241
241
|
`);r.writeFileSync(t,e,`utf-8`),m(`Created tsdown.config.ts`);return}let n=r.readFileSync(t,`utf-8`),a=n.replace(/defineConfig\({([^;]*)}\);/s,(e,t)=>{let n=t.trim();return n.length===0?`defineConfig({ /* */ });`:`defineConfig({\n /* ${n} */\n});`});if(a===n){h(`Could not find defineConfig(...) in tsdown.config.ts. File was left unchanged.`);return}r.writeFileSync(t,a,`utf-8`),m(`Updated tsdown.config.ts`)}function ue(e){let t=i.join(e,`package.json`),n=JSON.parse(r.readFileSync(t,`utf-8`));n.scripts??={},n.scripts.build=`scriptup build --release`,n.scripts.watch=`scriptup build --watch`,r.writeFileSync(t,JSON.stringify(n,null,2)+`
|
|
242
|
-
`,`utf-8`),m(`Updated package.json scripts: build, watch`)}function de(e){let t=process.cwd();try{process.chdir(e),o(fe(T(),[`@nano191225/scriptup`,`tsdown`,`typescript`,`@bedrock-apis/env-types`]),{stdio:`inherit`,cwd:e}),m(`Installed required dev dependencies`)}catch(e){g(`Failed to install dependencies: ${e instanceof Error?e.message:String(e)}`),process.exit(1)}finally{process.chdir(t)}}function fe(e,t){let n=t.join(` `);switch(e){case`npm`:return`npm install --save-dev ${n}`;case`pnpm`:return`pnpm add --save-dev ${n}`;case`yarn`:return`yarn add --dev ${n}`;case`bun`:return`bun add --save-dev ${n}`}}const pe=[`code`,`code-insiders`];async function me(e,t){let n=ge(t.preview),r=he(e),a=Q(r,t,n);if(R(a),await L({targetDir:a,projectName:e,lib:t.lib,workflow:t.workflow}),t.dir&&t.link!==!1&&_e(a,i.join(n,r)),t.open){if(!pe.includes(t.open))return g(`Unsupported editor: ${t.open}`);p(`Opening project with ${t.open}...`);try{z(a,t.open)}catch(e){g(`Failed to open project: ${e instanceof Error?e.message:String(e)}`),process.exit(1)}}}function Q(e,t,n){return t.dir?i.resolve(t.dir,e):i.join(n,e)}function he(e){let t=e.trim().replace(/[\\/]+/g,`$`).replace(/[^A-Za-z0-9@$-_.]/g,``);return t.length===0&&(g(`Project name is empty after sanitizing. Use at least one of A-Z, a-z, 0-9, @, $, -, _, or .`),process.exit(1)),t}function ge(e=!1){if(process.platform===`win32`){let t=process.env.APPDATA;t||(g(`APPDATA is not available. Use --dir to specify the destination manually.`),process.exit(1));let n=e?`Minecraft Bedrock Preview`:`Minecraft Bedrock`;return i.join(t,n,`Users`,`Shared`,`games`,`com.mojang`,`development_behavior_packs`)}let t=process.env.XDG_DATA_HOME??i.join(l.homedir(),`.local`,`share`);return i.join(t,`mcpelauncher`,`games`,`com.mojang`,`development_behavior_packs`)}function _e(e,t){let n=i.resolve(e),a=i.resolve(t);if(n===a)return;if(r.mkdirSync(i.dirname(a),{recursive:!0}),r.existsSync(a)){h(`Link path already exists, skipping link creation: ${a}`);return}let o=process.platform===`win32`?`junction`:`dir`;r.symlinkSync(n,a,o),m(`Linked behavior pack: ${a} -> ${n}`)}async function ve(e={}){let t=b().modules?.filter(v).find(e=>typeof e.entry==`string`&&e.entry.length>0);t?.entry||(g(`No script module entry found in manifest.json.`),process.exit(1));let n=await Se(i.resolve(`tsdown.config.ts`)),r=be(n);r||(g(`Source entry not found. Expected src/main.ts, src/index.ts, or tsdown.config.ts entry.`),process.exit(1));let a=i.resolve(t.entry),o=i.dirname(a),s=e.bundle===!0,c=e.watch===!0,l=e.release===!0,f=d({config:!1,entry:i.relative(process.cwd(),r),outDir:i.relative(process.cwd(),o),format:`esm`,target:`es2024`,platform:`neutral`,sourcemap:!l,clean:!c,tsconfig:i.relative(process.cwd(),i.resolve(`tsconfig.json`)),outExtensions:()=>({js:`.js`}),deps:{neverBundle:/^@minecraft\/(?!math(?:\/|$)|vanilla-data(?:\/|$))/,alwaysBundle:`**/*`,onlyBundle:!1},unbundle:!l&&!s,watch:c,minify:l},n);p(`Bundling addon scripts with tsdown...`);try{await u(f),l&&await Ce()}catch(e){g(e instanceof Error?e.message:String(e)),process.exit(1)}c||ye(a),_(`Build complete: ${i.relative(process.cwd(),a)}`)}function ye(e){r.existsSync(e)||(g(`Expected build output was not found: ${e}`),process.exit(1))}function be(e){let t=i.resolve(`src/main.ts`);if(r.existsSync(t))return t;let n=i.resolve(`src/index.ts`);if(r.existsSync(n))return n;let a=xe(e.entry);if(!a)return null;let o=i.resolve(a);return r.existsSync(o)?o:null}function xe(e){return typeof e==`string`?e:Array.isArray(e)&&typeof e[0]==`string`?e[0]:null}async function Se(e){if(!r.existsSync(e))return{};let t=r.readFileSync(e,`utf-8`);if(!t.includes(`export default`)||!t.includes(`defineConfig`))return h(`tsdown.config.ts was found but could not be parsed. Using internal build defaults.`),{};try{let t=(await import(f(e).href)).default;return!t||typeof t!=`object`||Array.isArray(t)?(h(`tsdown.config.ts should export a single config object. Using internal build defaults.`),{}):t}catch(e){return h(`Failed to import tsdown.config.ts: ${e instanceof Error?e.message:String(e)}`),h(`Using internal build defaults.`),{}}}async function Ce(){let e=we(i.resolve(`package`));e.length!==0&&(p(`Building local package sources into dist/... `),await u({config:!1,entry:e.map(e=>i.relative(process.cwd(),e)),outDir:i.relative(process.cwd(),i.resolve(`dist`)),format:`esm`,target:`es2024`,platform:`neutral`,clean:!0,tsconfig:i.relative(process.cwd(),i.resolve(`tsconfig.json`)),outExtensions:()=>({js:`.js`}),unbundle:!0,dts:!0,deps:{neverBundle:/^@minecraft\/(?!math(?:\/|$)|vanilla-data(?:\/|$))/}}))}function we(e){if(!r.existsSync(e))return[];let t=[],n=[e];for(;n.length>0;){let e=n.pop();if(!e)continue;let a=r.readdirSync(e,{withFileTypes:!0});for(let r of a){if(r.name===`node_modules`||r.name.startsWith(`.`))continue;let a=i.join(e,r.name);if(r.isDirectory()){n.push(a);continue}r.isFile()&&a.endsWith(`.ts`)&&!a.endsWith(`.d.ts`)&&t.push(a)}}return t.sort()}const $=new e;$.name(`scriptup`).description(`ScriptAPI version updater for Minecraft Bedrock`).version(I).argument(`[version]`,`Manually specify a version to look up`),$.command(`stable`).description(`Install the latest stable version modules`).action(async()=>{await k()}),$.command(`preview`).description(`Install the latest preview version modules`).action(async()=>{await j()}),$.command(`lts`).description(`Install the latest LTS version modules`).action(async()=>{await N()}),$.command(`build`).description(`Bundle the current ScriptAPI project with tsdown`).option(`-b, --bundle`,`Bundle the output into a single file`).option(`-w, --watch`,`Build in watch mode`).option(`-r, --release`,`Build for release (minified, sourcemap off)`).action(async e=>{await ve(e)}),$.command(`init`).description(`Initialize a ScriptAPI project in the current directory`).option(`--no-workflow`,`Do not create the GitHub Actions workflow files`).action(async e=>{await ce(void 0,e)}),$.command(`new`).description(`Create a new ScriptAPI project`).argument(`<project-name>`,`Directory name for the new project`).addOption(new t(`-o, --open [command]`,`Open the project after creation`).preset(`code`)).option(`-p, --preview`,`Create the project in the Minecraft Bedrock Preview behavior packs directory`).option(`-d, --dir <path>`,`Create the project under a specific directory`).option(`--lib`,`Include local library scaffolding under package/`).option(`--no-link`,`Do not create a link in the behavior packs directory when --dir is used`).option(`--no-workflow`,`Do not create the GitHub Actions workflow files`).action(async(e,t)=>{await me(e,t)}),$.action(async e=>{e?await F(e):$.help()}),$.parse();export{};
|
|
242
|
+
`,`utf-8`),m(`Updated package.json scripts: build, watch`)}function de(e){let t=process.cwd();try{process.chdir(e),o(fe(T(),[`@nano191225/scriptup`,`tsdown`,`typescript`,`@bedrock-apis/env-types`]),{stdio:`inherit`,cwd:e}),m(`Installed required dev dependencies`)}catch(e){g(`Failed to install dependencies: ${e instanceof Error?e.message:String(e)}`),process.exit(1)}finally{process.chdir(t)}}function fe(e,t){let n=t.join(` `);switch(e){case`npm`:return`npm install --save-dev ${n}`;case`pnpm`:return`pnpm add --save-dev ${n}`;case`yarn`:return`yarn add --dev ${n}`;case`bun`:return`bun add --save-dev ${n}`}}const pe=[`code`,`code-insiders`];async function me(e,t){let n=ge(t.preview),r=he(e),a=Q(r,t,n);if(R(a),await L({targetDir:a,projectName:e,lib:t.lib,workflow:t.workflow}),t.dir&&t.link!==!1&&_e(a,i.join(n,r)),t.open){if(!pe.includes(t.open))return g(`Unsupported editor: ${t.open}`);p(`Opening project with ${t.open}...`);try{z(a,t.open)}catch(e){g(`Failed to open project: ${e instanceof Error?e.message:String(e)}`),process.exit(1)}}}function Q(e,t,n){return t.dir?i.resolve(t.dir,e):i.join(n,e)}function he(e){let t=e.trim().replace(/[\\/]+/g,`$`).replace(/[^A-Za-z0-9@$-_.]/g,``);return t.length===0&&(g(`Project name is empty after sanitizing. Use at least one of A-Z, a-z, 0-9, @, $, -, _, or .`),process.exit(1)),t}function ge(e=!1){if(process.platform===`win32`){let t=process.env.APPDATA;t||(g(`APPDATA is not available. Use --dir to specify the destination manually.`),process.exit(1));let n=e?`Minecraft Bedrock Preview`:`Minecraft Bedrock`;return i.join(t,n,`Users`,`Shared`,`games`,`com.mojang`,`development_behavior_packs`)}let t=process.env.XDG_DATA_HOME??i.join(l.homedir(),`.local`,`share`);return i.join(t,`mcpelauncher`,`games`,`com.mojang`,`development_behavior_packs`)}function _e(e,t){let n=i.resolve(e),a=i.resolve(t);if(n===a)return;if(r.mkdirSync(i.dirname(a),{recursive:!0}),r.existsSync(a)){h(`Link path already exists, skipping link creation: ${a}`);return}let o=process.platform===`win32`?`junction`:`dir`;r.symlinkSync(n,a,o),m(`Linked behavior pack: ${a} -> ${n}`)}async function ve(e={}){let t=b().modules?.filter(v).find(e=>typeof e.entry==`string`&&e.entry.length>0);t?.entry||(g(`No script module entry found in manifest.json.`),process.exit(1));let n=await Se(i.resolve(`tsdown.config.ts`)),r=be(n);r||(g(`Source entry not found. Expected src/main.ts, src/index.ts, or tsdown.config.ts entry.`),process.exit(1));let a=i.resolve(t.entry),o=i.dirname(a),s=e.bundle===!0,c=e.watch===!0,l=e.release===!0,f=d({config:!1,entry:i.relative(process.cwd(),r),outDir:i.relative(process.cwd(),o),format:`esm`,target:`es2024`,platform:`neutral`,sourcemap:!l,clean:!c,tsconfig:i.relative(process.cwd(),i.resolve(`tsconfig.json`)),outExtensions:()=>({js:`.js`}),deps:{neverBundle:/^@minecraft\/(?!math(?:\/|$)|vanilla-data(?:\/|$))/,alwaysBundle:`**/*`,onlyBundle:!1},unbundle:!l&&!s,watch:c,minify:l},n);p(`Bundling addon scripts with tsdown...`);try{await u(f),l&&await Ce()}catch(e){g(e instanceof Error?e.message:String(e)),process.exit(1)}c||ye(a),_(`Build complete: ${i.relative(process.cwd(),a)}`)}function ye(e){r.existsSync(e)||(g(`Expected build output was not found: ${e}`),process.exit(1))}function be(e){let t=i.resolve(`src/main.ts`);if(r.existsSync(t))return t;let n=i.resolve(`src/index.ts`);if(r.existsSync(n))return n;let a=xe(e.entry);if(!a)return null;let o=i.resolve(a);return r.existsSync(o)?o:null}function xe(e){return typeof e==`string`?e:Array.isArray(e)&&typeof e[0]==`string`?e[0]:null}async function Se(e){if(!r.existsSync(e))return{};let t=r.readFileSync(e,`utf-8`);if(!t.includes(`export default`)||!t.includes(`defineConfig`))return h(`tsdown.config.ts was found but could not be parsed. Using internal build defaults.`),{};try{let t=(await import(f(e).href)).default;return!t||typeof t!=`object`||Array.isArray(t)?(h(`tsdown.config.ts should export a single config object. Using internal build defaults.`),{}):t}catch(e){return h(`Failed to import tsdown.config.ts: ${e instanceof Error?e.message:String(e)}`),h(`Using internal build defaults.`),{}}}async function Ce(){let e=we(i.resolve(`package`));e.length!==0&&(p(`Building local package sources into dist/... `),await u({config:!1,entry:e.map(e=>i.relative(process.cwd(),e)),outDir:i.relative(process.cwd(),i.resolve(`dist`)),format:`esm`,target:`es2024`,platform:`neutral`,clean:!0,tsconfig:i.relative(process.cwd(),i.resolve(`tsconfig.json`)),outExtensions:()=>({js:`.js`}),unbundle:!0,dts:!0,deps:{neverBundle:/^@minecraft\/(?!math(?:\/|$)|vanilla-data(?:\/|$))/}}))}function we(e){if(!r.existsSync(e))return[];let t=[],n=[e];for(;n.length>0;){let e=n.pop();if(!e)continue;let a=r.readdirSync(e,{withFileTypes:!0});for(let r of a){if(r.name===`node_modules`||r.name.startsWith(`.`))continue;let a=i.join(e,r.name);if(r.isDirectory()){n.push(a);continue}r.isFile()&&a.endsWith(`.ts`)&&!a.endsWith(`.d.ts`)&&t.push(a)}}return t.sort()}const $=new e;$.name(`scriptup`).description(`ScriptAPI version updater for Minecraft Bedrock`).version(I).argument(`[version]`,`Manually specify a version to look up`),$.command(`stable`).description(`Install the latest stable version modules`).action(async()=>{await k()}),$.command(`preview`).description(`Install the latest preview version modules`).action(async()=>{await j()}),$.command(`lts`).description(`Install the latest LTS version modules`).action(async()=>{await N()}),$.command(`build`).description(`Bundle the current ScriptAPI project with tsdown`).option(`-b, --bundle`,`Bundle the output into a single file`).option(`-w, --watch`,`Build in watch mode`).option(`-r, --release`,`Build for release (minified, sourcemap off)`).action(async e=>{await ve(e)}),$.command(`init`).description(`Initialize a ScriptAPI project in the current directory`).option(`--lib`,`Include local library scaffolding under package/`).option(`--no-workflow`,`Do not create the GitHub Actions workflow files`).action(async e=>{await ce(void 0,e)}),$.command(`new`).description(`Create a new ScriptAPI project`).argument(`<project-name>`,`Directory name for the new project`).addOption(new t(`-o, --open [command]`,`Open the project after creation`).preset(`code`)).option(`-p, --preview`,`Create the project in the Minecraft Bedrock Preview behavior packs directory`).option(`-d, --dir <path>`,`Create the project under a specific directory`).option(`--lib`,`Include local library scaffolding under package/`).option(`--no-link`,`Do not create a link in the behavior packs directory when --dir is used`).option(`--no-workflow`,`Do not create the GitHub Actions workflow files`).action(async(e,t)=>{await me(e,t)}),$.action(async e=>{e?await F(e):$.help()}),$.parse();export{};
|