@tochii/build 1.0.1 → 1.0.3

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.md ADDED
@@ -0,0 +1,88 @@
1
+ # @tochi/build
2
+
3
+ This package provides a CLI for bundling your projects optionally with **no config** in Node.js with extended features like **configuration file** generation.
4
+
5
+ ## Why make this?
6
+
7
+ I once permanently deleted my entire project when attempting to build a single file with the output directory as my project directory, and I hadn't pushed my progress to github for more than 1 week (no need to tell me...) which almost resulted in despair. I forgot to uncheck the `clean` option that cleans the entire output directory before the build process begins.
8
+
9
+ How did I forgot to uncheck that critical option? Well my project had multiple config files for different purposes, so I just copied an existing config file instead of manually creating a new one.
10
+
11
+ Luckily I was able to get my files back by building a script [@tochii/vscode-file-recovery](https://www.npmjs.com/package/@tochii/vscode-file-recovery) to restore the entire project while maintaining the folder structure.
12
+
13
+ I wished that there were a safer way to define the options in a bundler config file, so I created some utilities with typesafety that requires the developer to be more aware of critical options such as the `clean` option.
14
+
15
+ Other than that, the utilities eliminates redundant actions such as:
16
+ - Manually creating a config file for each project/package/file to be built.
17
+ - Removes the need to copy/paste an existing config file and will automatically disable critical options that could lead to unwanted results.
18
+
19
+ ## Utilities
20
+
21
+ #### NodeBundlerUtils
22
+
23
+ This class provides several utilities when using the `node` bundler such as:
24
+ - Only bundle entry files (eg. index.js|ts)
25
+ - Automatically bundle common files (eg. any files ending with .js or .ts)
26
+ - Ignore commonly ignored files and folders (eg. node_modules, .d.ts definition files)
27
+ - And more...
28
+
29
+ ## CLI Usage
30
+
31
+ You can use the CLI by running the following command:
32
+
33
+ ```bash
34
+ tochibuild <command>
35
+ ```
36
+
37
+ ### Commands
38
+
39
+ #### node
40
+
41
+ ```bash
42
+ tochibuild node [...args]
43
+ ```
44
+
45
+ - Uses `tsup` under the hood which is powered by `esbuild`.
46
+ - the passed **...args** are compatible with `tsup` (https://tsup.egoist.dev/#usage)
47
+
48
+ #### config
49
+
50
+ ```bash
51
+ tochibuild config [options] <bundler>
52
+ ```
53
+
54
+ Quickly generate a configuration file for the specified bundler
55
+
56
+ #### config options
57
+
58
+ `--ext <string>`
59
+
60
+ the file extension to use (defaults to the common one for the bundler)
61
+
62
+ ```bash
63
+ tochibuild config --ext .ts node
64
+ ```
65
+
66
+ `-f <string> or --file <string>`
67
+
68
+ the file name to use excluding the file extension (defaults to the common one for the bundler)
69
+
70
+ ```bash
71
+ tochibuild config -f tsup.config node
72
+ ```
73
+
74
+ `-o or --overwrite`
75
+
76
+ whether to overwrite the config file if it already exists (defaults to false)
77
+
78
+ ```bash
79
+ tochibuild config -o node
80
+ ```
81
+
82
+ ### Bundlers
83
+
84
+ These are the only available bundlers for now.
85
+
86
+ **node**
87
+ - Uses tsup under the hood (https://tsup.egoist.dev) which is powered by esbuild
88
+ - Supports both javascript and typescript eg. `.js`, `.json`, `.mjs`, `.ts` and `tsx`. CSS support is experimental.
@@ -1 +1 @@
1
- import{b as t}from"./chunk-3XJZVPOC.mjs";import{defineConfig as n}from"tsup";var p={Utils:t,defineConfigTsup:n,defineConfig:o,defineConfigIndexEntries:i,defineConfigCommonEntrie:r};function o(...e){return n(t.defaultOptions(...e))}function i(...e){return n(t.defaultOptionsIndexEntries(...e))}function r(...e){return n(t.defaultOptionsCommonEntries(...e))}export{n as a,p as b,o as c,i as d,r as e};
1
+ import{b as t}from"./chunk-QFYOHOZF.mjs";import{defineConfig as n}from"tsup";var p={Utils:t,defineConfigTsup:n,defineConfig:o,defineConfigIndexEntries:i,defineConfigCommonEntrie:r};function o(...e){return n(t.defaultOptions(...e))}function i(...e){return n(t.defaultOptionsIndexEntries(...e))}function r(...e){return n(t.defaultOptionsCommonEntries(...e))}export{n as a,p as b,o as c,i as d,r as e};
@@ -0,0 +1 @@
1
+ var t=class t{};t.ignoredEntries=["!node_modules","!**/*/node_modules","!*.d.ts","!**/*/*.d.ts","!tsup.config*","!**/*/tsup.config*"],t.entriesCommon=["*.js","*.ts","**/*/*.js","**/*/*.ts"],t.entriesIndex=["index.js","index.ts","**/*/index.js","**/*/index.ts"],t.defaultEntriesIndex=[...t.entriesIndex,...t.ignoredEntries],t.defaultEntriesCommon=[...t.entriesCommon,...t.ignoredEntries],t.defaultOptions=n=>({tsconfig:"tsconfig.json",dts:!0,format:["esm"],minify:!0,...n,entry:r(n.entry,"ignoredEntries")}),t.defaultOptionsIndexEntries=n=>({entry:r(n.entry,"defaultEntriesIndex"),tsconfig:"tsconfig.json",dts:!0,format:["esm"],minify:!0,...n}),t.defaultOptionsCommonEntries=n=>({entry:r(n.entry,"defaultEntriesCommon"),tsconfig:"tsconfig.json",dts:!0,format:["esm"],minify:!0,...n});var e=t,a=e;function r(i,n){if(Array.isArray(i))return[...i,...e[n]];let o={};return e[n].forEach(s=>o[s]=s),{...i,...o}}export{e as a,a as b};
package/dist/cli.mjs CHANGED
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
- import s from"chalk";import f from"fs";import m from"path";import{Command as h}from"commander";import{spawn as b}from"child_process";var a={name:"@tochii/build",version:"1.0.0",description:"Tools for bundling your projects in Node.js",repository:"https://github.com/tochiResources/project/packages/build.git",license:"MIT",bin:{tochibuild:"./dist/cli.mjs"},scripts:{build:"tsup-node",dev:"tsx cli.ts"},dependencies:{chalk:"^5.4.1",commander:"^13.1.0"},devDependencies:{"@types/node":"^22.15.17",tsup:"^8.4.0",tsx:"^4.19.4",typescript:"^5.8.3"},engines:{node:">=18.17.0"},files:["dist"]};var u={node:"tsup-node"},d=s.cyan("tochibuild"),p=new h("tochibuild").name("tochibuild <command>").description("Tools for bundling your projects in Node.js").allowUnknownOption(!0).version(a.version);p.command("node").description("bundle a Node.js project using tsup (https://tsup.egoist.dev)").allowUnknownOption(!0).argument("[...args]","arguments to pass to tsup").action(async e=>y("node",e));p.command("config").description("generate config files for the selected bundler").argument("<bundler>","bundler to generate config for").option("--ext <string>","the file extension to use (defaults to the common one for the bundler)","").option("-f, --file <string>","the file name to use (defaults to the common one for the bundler)","").option("-o, --overwrite","whether to overwrite the config file if it already exists (defaults to false)",!1).action((e,n)=>w(e,n));p.parseAsync(process.argv);async function y(e,n){return new Promise((r,i)=>{try{console.log(d,`running ${s.magenta(e)}...`),setTimeout(()=>{let o=b(u[e],n,{stdio:"inherit",shell:!0,cwd:process.cwd(),env:process.env});o.on("exit",c=>{process.exit(c??1)}),process.on("SIGINT",()=>{i(),o.kill("SIGINT")}),process.on("SIGTERM",()=>{i(),o.kill("SIGTERM")}),r()},3e3)}catch(o){i(o)}})}function w(e,n){switch(u[e]){case"tsup-node":x(n);break}}function x(e){let n=process.cwd(),r=e.ext||".ts",i=e.file||"tsup.config",o=m.join(n,`${i}${r}`),c=f.existsSync(o);!e?.overwrite&&c&&(console.warn(d,s.yellow("the tsup config file already exists for this project.")),process.exit(1));let l=" ",t="";t+=`import build from '@tochii/build';
2
+ import s from"chalk";import u from"fs";import m from"path";import{Command as h}from"commander";import{spawn as b}from"child_process";var a={name:"@tochii/build",version:"1.0.3",description:"Tools for bundling your projects in Node.js",repository:"https://github.com/tochiResources/project/packages/build.git",license:"MIT",bin:{tochibuild:"./dist/cli.mjs"},scripts:{build:"tsup-node",dev:"tsx cli.ts"},dependencies:{chalk:"^5.4.1",commander:"^13.1.0",tsup:"^8.4.0"},devDependencies:{"@tochii/build":"^1.0.1","@types/node":"^22.15.17",tsx:"^4.19.4",typescript:"^5.8.3"},engines:{node:">=18.17.0"},files:["dist"]};var f={node:"tsup-node"},d=s.cyan("tochibuild"),p=new h("tochibuild").name("tochibuild <command>").description("Tools for bundling your projects in Node.js").allowUnknownOption(!0).version(a.version);p.command("node").description("bundle a Node.js project using tsup (https://tsup.egoist.dev)").allowUnknownOption(!0).argument("[...args]","arguments to pass to tsup").action(async e=>y("node",e));p.command("config").description("generate config files for the selected bundler").argument("<bundler>","bundler to generate config for").option("--ext <string>","the file extension to use excluding the file extension (defaults to the common one for the bundler)","").option("-f, --file <string>","the file name to use (defaults to the common one for the bundler)","").option("-o, --overwrite","whether to overwrite the config file if it already exists (defaults to false)",!1).action((e,n)=>w(e,n));p.parseAsync(process.argv);async function y(e,n){return new Promise((r,i)=>{try{console.log(d,`running ${s.magenta(e)}...`),setTimeout(()=>{let o=b(`${f[e]}`,n,{stdio:"inherit",shell:!0,cwd:process.cwd(),env:process.env});o.on("exit",c=>{process.exit(c??1)}),process.on("SIGINT",()=>{i(),o.kill("SIGINT")}),process.on("SIGTERM",()=>{i(),o.kill("SIGTERM")}),r()},3e3)}catch(o){i(o)}})}function w(e,n){switch(f[e]){case"tsup-node":x(n);break}}function x(e){let n=process.cwd(),r=e.ext||".ts",i=e.file||"tsup.config",o=m.join(n,`${i}${r}`),c=u.existsSync(o);!e?.overwrite&&c&&(console.warn(d,s.yellow("the tsup config file already exists for this project.")),process.exit(1));let l=" ",t="";t+=`import build from '@tochii/build';
3
3
 
4
4
  `,t+=`export default build.node.defineConfig({
5
5
  `,t+=`${l}entry: ['index.ts'],
6
6
  `,t+=`${l}clean: false,
7
7
  `,t+=`${l}splitting: false,
8
8
  `,t+=`});
9
- `,f.writeFileSync(o,t),console.log(s.green(d,"the tsup config file has been created at:"),s.gray(o))}
9
+ `,u.writeFileSync(o,t),console.log(s.green(d,"the tsup config file has been created at:"),s.gray(o))}
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{b as o}from"./chunk-OBDH5LJC.mjs";import"./chunk-3XJZVPOC.mjs";var r={node:o};export{r as default,o as node};
1
+ import{b as o}from"./chunk-LTYPVCKJ.mjs";import"./chunk-QFYOHOZF.mjs";var r={node:o};export{r as default,o as node};
@@ -1 +1 @@
1
- import{a as b,b as c,c as d,d as e,e as f}from"../chunk-OBDH5LJC.mjs";import{b as a}from"../chunk-3XJZVPOC.mjs";export{a as Utils,c as default,d as defineConfig,f as defineConfigCommonEntrie,e as defineConfigIndexEntries,b as defineConfigTsup};
1
+ import{a as b,b as c,c as d,d as e,e as f}from"../chunk-LTYPVCKJ.mjs";import{b as a}from"../chunk-QFYOHOZF.mjs";export{a as Utils,c as default,d as defineConfig,f as defineConfigCommonEntrie,e as defineConfigIndexEntries,b as defineConfigTsup};
@@ -1 +1 @@
1
- import{a,b}from"../chunk-3XJZVPOC.mjs";export{a as NodeBundlerUtils,b as default};
1
+ import{a,b}from"../chunk-QFYOHOZF.mjs";export{a as NodeBundlerUtils,b as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tochii/build",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Tools for bundling your projects in Node.js",
5
5
  "repository": "https://github.com/tochiResources/project/packages/build.git",
6
6
  "license": "MIT",
@@ -13,11 +13,12 @@
13
13
  },
14
14
  "dependencies": {
15
15
  "chalk": "^5.4.1",
16
- "commander": "^13.1.0"
16
+ "commander": "^13.1.0",
17
+ "tsup": "^8.4.0"
17
18
  },
18
19
  "devDependencies": {
20
+ "@tochii/build": "^1.0.1",
19
21
  "@types/node": "^22.15.17",
20
- "tsup": "^8.4.0",
21
22
  "tsx": "^4.19.4",
22
23
  "typescript": "^5.8.3"
23
24
  },
@@ -1 +0,0 @@
1
- var t=class t{};t.ignoredEntries=["!node_modules","!**/*/node_modules","!*.d.ts","!**/*/*.d.ts","!tsup.config*","!**/*/tsup.config*"],t.entriesCommon=["*.ts","**/*/*.ts"],t.entriesIndex=["index.ts","**/*/index.ts"],t.defaultEntriesIndex=[...t.entriesIndex,...t.ignoredEntries],t.defaultEntriesCommon=[...t.entriesCommon,...t.ignoredEntries],t.defaultOptions=n=>({tsconfig:"tsconfig.json",dts:!0,format:["esm"],minify:!0,...n,entry:r(n.entry,"ignoredEntries")}),t.defaultOptionsIndexEntries=n=>({entry:r(n.entry,"defaultEntriesIndex"),tsconfig:"tsconfig.json",dts:!0,format:["esm"],minify:!0,...n}),t.defaultOptionsCommonEntries=n=>({entry:r(n.entry,"defaultEntriesCommon"),tsconfig:"tsconfig.json",dts:!0,format:["esm"],minify:!0,...n});var i=t,a=i;function r(s,n){if(Array.isArray(s)){let e=[...s,...i[n]];return console.log("entries:",e),e}let o={};return i[n].forEach(e=>o[e]=e),{...s,...o}}export{i as a,a as b};