@a35hie/ts-pkg 0.3.1 → 0.4.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/README.md +3 -1
- package/dist/cli.js +27 -18
- package/images/ts-pkg-icon.png +0 -0
- package/package.json +8 -7
package/README.md
CHANGED
package/dist/cli.js
CHANGED
|
@@ -1,18 +1,31 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
-
import{createRequire as
|
|
3
|
-
`),console.log(`✨ Generated ${
|
|
4
|
-
${
|
|
2
|
+
import{createRequire as i}from"node:module";var g=i(import.meta.url);var l={typescript:{build:"tsc","build:watch":"tsc --watch",typecheck:"tsc --noEmit"},react:{dev:"vite",build:"vite build",preview:"vite preview"},node:{start:"node dist/index.js",dev:"tsx watch src/index.ts",build:"tsup src/index.ts --format esm,cjs --dts"},testing:{test:"vitest","test:watch":"vitest watch","test:coverage":"vitest --coverage"},prettier:{format:"prettier --write .","format:check":"prettier --check ."},eslint:{lint:"eslint .","lint:fix":"eslint . --fix"}};function V(S){let R={};for(let z of S){let G=l[z];if(G)Object.assign(R,G)}return R}function j(S,R){return{...S,...R}}function p(S){if(typeof S==="string"){let G=S.lastIndexOf("@");if(G>0)return{name:S.slice(0,G),version:S.slice(G+1)};return{name:S}}let[R,z]=Object.entries(S)[0];return{name:R,version:z}}async function c(S){let R=`https://registry.npmjs.org/${encodeURIComponent(S)}`,z=await fetch(R,{headers:{Accept:"application/json"}});if(!z.ok)throw Error(`Failed to fetch ${S}: ${z.statusText}`);return(await z.json())["dist-tags"].latest}var D=new Map;async function N(S){if(!S)return{};if(!Array.isArray(S))return S;if(S.length===0)return{};let R=[];for(let z of S){let{name:G,version:K}=p(z);if(K){R.push([G,K]);continue}let Q=D.get(G);if(!Q)Q=`^${await c(G)}`,D.set(G,Q);R.push([G,Q])}return Object.fromEntries(R)}function O(S,R){let z={...S};for(let G of Object.keys(R)){let K=R[G],Q=S[G];if(K===void 0)continue;if(typeof K==="object"&&K!==null&&!Array.isArray(K)&&typeof Q==="object"&&Q!==null&&!Array.isArray(Q))z[G]=O(Q,K);else z[G]=K}return z}function F(S,R){if(!S&&!R)return;if(!S)return R;if(!R)return S;if(Array.isArray(S)&&Array.isArray(R))return[...S,...R];if(!Array.isArray(S)&&!Array.isArray(R))return{...S,...R};let z=Array.isArray(S)?{}:S,G=Array.isArray(R)?{}:R,K=Array.isArray(S)?S:[],Q=Array.isArray(R)?R:[];return[...K,...Q,{...z,...G}]}async function W(S){if(!S.extends)return S;let R;if(typeof S.extends==="string"){let K=await import(S.extends);R=K.default??K}else R=S.extends;R=await W(R);let{extends:z,...G}=S;return{...R,...G,dependencies:F(R.dependencies,G.dependencies),devDependencies:F(R.devDependencies,G.devDependencies),peerDependencies:F(R.peerDependencies,G.peerDependencies),scripts:{...R.scripts,...G.scripts},scriptPresets:[...R.scriptPresets??[],...G.scriptPresets??[]]}}function d(){return{env:"development",platform:process.platform,nodeVersion:process.version,ci:process.env.CI==="true"||process.env.CI==="1"}}function a(S,R){if(S.env!==void 0&&R.env!==S.env)return!1;if(S.platform!==void 0&&R.platform!==S.platform)return!1;if(S.ci!==void 0&&R.ci!==S.ci)return!1;if(S.nodeVersion!==void 0){if(!R.nodeVersion.startsWith(S.nodeVersion))return!1}return!0}function k(S,R){if(!R||R.length===0)return S;let z=d(),G={...S};for(let K of R)if(a(K.when,z))G=O(G,K.set);return G}async function P(S,R={}){let{indent:z=2}=R,G=await W(S),K=G.scriptPresets?V(G.scriptPresets):{},Q=j(K,G.scripts),[L,X,$]=await Promise.all([N(G.dependencies),N(G.devDependencies),N(G.peerDependencies)]),_={name:G.name,...G.version&&{version:G.version},...G.description&&{description:G.description},...G.keywords?.length&&{keywords:G.keywords},...G.homepage&&{homepage:G.homepage},...G.bugs&&{bugs:G.bugs},...G.license&&{license:G.license},...G.author&&{author:G.author},...G.contributors?.length&&{contributors:G.contributors},...G.repository&&{repository:G.repository},...G.type&&{type:G.type},...G.main&&{main:G.main},...G.module&&{module:G.module},...G.types&&{types:G.types},...G.exports&&{exports:G.exports},...G.bin&&{bin:G.bin},...G.files?.length&&{files:G.files},...Object.keys(Q).length&&{scripts:Q},...Object.keys(L).length&&{dependencies:L},...Object.keys(X).length&&{devDependencies:X},...Object.keys($).length&&{peerDependencies:$},...G.optionalDependencies&&{optionalDependencies:G.optionalDependencies},...G.engines&&{engines:G.engines},...G.os?.length&&{os:G.os},...G.cpu?.length&&{cpu:G.cpu},...G.private!==void 0&&{private:G.private},...G.publishConfig&&{publishConfig:G.publishConfig},...G.workspaces?.length&&{workspaces:G.workspaces}},Z=k(_,G.conditions);return JSON.stringify(Z,null,z)}async function I(S,R={}){let{outputPath:z="package.json"}=R,G=await P(S,R),{writeFile:K}=await import("node:fs/promises");await K(z,G+`
|
|
3
|
+
`),console.log(`✨ Generated ${z}`)}import{readFile as y,writeFile as r}from"node:fs/promises";import{resolve as C}from"node:path";function w(S){if(!S)return[];return Object.keys(S).sort()}function m(S,R=" "){if(S.length===0)return"[]";if(S.length===1)return`['${S[0]}']`;return`[
|
|
4
|
+
${S.map((z)=>`${R}'${z}',`).join(`
|
|
5
5
|
`)}
|
|
6
|
-
]`}function
|
|
7
|
-
${
|
|
6
|
+
]`}function s(S,R=" "){let z=Object.entries(S).sort(([G],[K])=>G.localeCompare(K));if(z.length===0)return"{}";return`{
|
|
7
|
+
${z.map(([G,K])=>`${R}'${G}': '${K}',`).join(`
|
|
8
8
|
`)}
|
|
9
|
-
}`}async function
|
|
10
|
-
`)
|
|
11
|
-
`)
|
|
12
|
-
${
|
|
13
|
-
`+
|
|
14
|
-
$1$2`)}}}return
|
|
15
|
-
|
|
9
|
+
}`}async function b(S={}){let{packageJsonPath:R="package.json",configPath:z="package.ts",quiet:G=!1,delay:K=0}=S;if(K>0)await new Promise((Y)=>setTimeout(Y,K));let Q=C(process.cwd(),R),L=C(process.cwd(),z),X;try{let Y=await y(Q,"utf-8");X=JSON.parse(Y)}catch(Y){if(Y.code==="ENOENT")console.error(`× package.json not found: ${R}`),process.exit(1);throw Y}let $;try{$=await y(L,"utf-8")}catch(Y){if(Y.code==="ENOENT")console.error(`× Config file not found: ${z}`),console.error("Run ts-pkg init first to create a package.ts"),process.exit(1);throw Y}let _=w(X.dependencies),Z=w(X.devDependencies),U=w(X.peerDependencies),q=$;if(q=x(q,"dependencies",_,X.dependencies),q=x(q,"devDependencies",Z,X.devDependencies),q=x(q,"peerDependencies",U,X.peerDependencies),await r(L,q),!G){if(console.log(`✨ Synced dependencies to ${z}`),_.length)console.log(` dependencies: ${_.length} packages`);if(Z.length)console.log(` devDependencies: ${Z.length} packages`);if(U.length)console.log(` peerDependencies: ${U.length} packages`)}}function T(S,R,z,G){let K=0;for(let Q=R;Q<S.length;Q++)if(S[Q]===z)K++;else if(S[Q]===G){if(K--,K===0)return Q}return-1}function x(S,R,z,G){let Q=new RegExp(`(${R}:\\s*)\\[`).exec(S);if(Q&&Q[1]){let $=m(z),_=Q.index+Q[1].length,Z=T(S,_,"[","]");if(Z!==-1)return S.slice(0,_)+$+S.slice(Z+1)}let X=new RegExp(`(${R}:\\s*)\\{`).exec(S);if(X&&X[1]){let $=s(G||{}),_=X.index+X[1].length,Z=T(S,_,"{","}");if(Z!==-1)return S.slice(0,_)+$+S.slice(Z+1)}if(z.length>0){let $=m(z),_=[{pattern:/peerDependencies:\s*[\[{]/,after:!0},{pattern:/devDependencies:\s*[\[{]/,after:!0},{pattern:/dependencies:\s*[\[{]/,after:!0},{pattern:/(\n\s*)(conditions:\s*\[)/,before:!0},{pattern:/(\n\s*)(engines:\s*\{)/,before:!0}];for(let{pattern:Z,after:U,before:q}of _){let Y=Z.exec(S);if(Y){if(U){let A=S[Y.index+Y[0].length-1]==="[",u=Y.index+Y[0].length-1,E=T(S,u,A?"[":"{",A?"]":"}");if(E!==-1){let H=E+1,B=S[H];while(H<S.length&&B&&/[,\s]/.test(B)&&B!==`
|
|
10
|
+
`)H++,B=S[H];if(S[H]===`
|
|
11
|
+
`)H++;return S.slice(0,H)+`
|
|
12
|
+
${R}: ${$},
|
|
13
|
+
`+S.slice(H)}}else if(q)return S.replace(Z,`$1${R}: ${$},
|
|
14
|
+
$1$2`)}}}return S}import{resolve as t}from"node:path";import{pathToFileURL as n}from"node:url";function f(S){return S}var h=`
|
|
15
|
+
▄██████████████▄
|
|
16
|
+
██████████████████
|
|
17
|
+
██████████████████
|
|
18
|
+
█████▒▒▒▒▒██▒▒▒███ ███ █ █ ██
|
|
19
|
+
███████▒███▒██████ █ █ █ █ █
|
|
20
|
+
███████▒████▒▒▒██▒▒ █ █ ██ █
|
|
21
|
+
███████▒███████▒██ ███ █ █ █ █
|
|
22
|
+
███████▒████▒▒▒███ █ █ █ ██
|
|
23
|
+
▀██████████████▀
|
|
24
|
+
`,M=f({name:"@a35hie/ts-pkg",version:"0.4.0",description:"TypeScript-based package.json with magical features.",type:"module",license:"Apache-2.0",repository:"https://github.com/a35hie/TsPkg",keywords:["typescript","package-json","npm","bun","monorepo-tooling","nodejs"],main:"dist/main.js",module:"dist/main.js",types:"dist/main.d.ts",bin:{"ts-pkg":"./dist/cli.js"},files:["dist","images"],scriptPresets:["typescript","prettier"],scripts:{build:"bun run build.ts",generate:"bun run src/cli.ts"},devDependencies:{"@types/bun":"^1.3.8","bun-plugin-dts":"^0.3.0",prettier:"^3.8.1",typescript:"^6.0.0-beta"},peerDependencies:{typescript:"^6.0.0-beta"},conditions:[{when:{env:"production"},set:{private:!1}},{when:{ci:!0},set:{scripts:{test:"vitest run --reporter=verbose"}}}],engines:{node:">=22",bun:">=1.3.5"}});function v(){console.log(`
|
|
25
|
+
${h}
|
|
26
|
+
${M.description}
|
|
27
|
+
Version: ${M.version}
|
|
28
|
+
`)}function o(){v(),console.log(`
|
|
16
29
|
|
|
17
30
|
Usage:
|
|
18
31
|
ts-pkg [configPath] [outputPath] Generate package.json from config
|
|
@@ -28,11 +41,7 @@ Examples:
|
|
|
28
41
|
ts-pkg my.config.ts # Generate from custom config
|
|
29
42
|
ts-pkg sync # Sync deps to package.ts
|
|
30
43
|
ts-pkg sync package.ts package.json
|
|
31
|
-
|
|
32
|
-
Postinstall setup:
|
|
33
|
-
Add to your package.json scripts:
|
|
34
|
-
"postinstall": "ts-pkg sync"
|
|
35
|
-
`)}async function s(z,K){let Q=d(process.cwd(),z);try{let R=await import(a(Q).href),X=R.default??R;await D(X,{outputPath:K})}catch(R){let X=R;if(X.code==="ERR_MODULE_NOT_FOUND"||X.code==="ENOENT")console.error(`× Config file not found: ${z}`),console.error(`
|
|
44
|
+
`)}async function e(S,R){let z=t(process.cwd(),S);try{let G=await import(n(z).href),K=G.default??G;await I(K,{outputPath:R})}catch(G){let K=G;if(K.code==="ERR_MODULE_NOT_FOUND"||K.code==="ENOENT")v(),console.error(`× Config file not found: ${S}`),console.error(`
|
|
36
45
|
Create a package.ts file with:`),console.error(`
|
|
37
46
|
import { definePackage } from '@a35hie/ts-pkg'
|
|
38
47
|
|
|
@@ -43,4 +52,4 @@ export default definePackage({
|
|
|
43
52
|
dependencies: ['lodash', 'zod'],
|
|
44
53
|
devDependencies: ['typescript', 'vitest'],
|
|
45
54
|
})
|
|
46
|
-
`),process.exit(1);console.error("× Error:",
|
|
55
|
+
`),process.exit(1);console.error("× Error:",K.message),process.exit(1)}}async function SS(S,R){let z=process.env.npm_lifecycle_event==="postinstall";await b({configPath:S,packageJsonPath:R,delay:z?100:0})}async function GS(){let S=process.argv.slice(2),R=S[0];if(R==="help"||R==="--help"||R==="-h"){o();return}if(R==="sync"){let K=S[1]??"package.ts",Q=S[2]??"package.json";await SS(K,Q);return}let z=S[0]??"package.ts",G=S[1]??"package.json";await e(z,G)}GS();
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@a35hie/ts-pkg",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "TypeScript-based package.json with magical features",
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "TypeScript-based package.json with magical features.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
7
7
|
"package-json",
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
"ts-pkg": "./dist/cli.js"
|
|
21
21
|
},
|
|
22
22
|
"files": [
|
|
23
|
-
"dist"
|
|
23
|
+
"dist",
|
|
24
|
+
"images"
|
|
24
25
|
],
|
|
25
26
|
"scripts": {
|
|
26
27
|
"build": "bun run build.ts",
|
|
@@ -34,13 +35,13 @@
|
|
|
34
35
|
"@types/bun": "^1.3.8",
|
|
35
36
|
"bun-plugin-dts": "^0.3.0",
|
|
36
37
|
"prettier": "^3.8.1",
|
|
37
|
-
"typescript": "^
|
|
38
|
+
"typescript": "^6.0.0-beta"
|
|
38
39
|
},
|
|
39
40
|
"peerDependencies": {
|
|
40
|
-
"typescript": "^
|
|
41
|
+
"typescript": "^6.0.0-beta"
|
|
41
42
|
},
|
|
42
43
|
"engines": {
|
|
43
|
-
"node": ">=
|
|
44
|
-
"bun": ">=1.
|
|
44
|
+
"node": ">=22",
|
|
45
|
+
"bun": ">=1.3.5"
|
|
45
46
|
}
|
|
46
47
|
}
|