adamantite 0.4.0 → 0.5.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.
Files changed (2) hide show
  1. package/dist/index.js +2 -2
  2. package/package.json +4 -3
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import{Command as e}from"commander";import t from"process";import{execSync as n}from"child_process";import{access as r,readFile as i,writeFile as a}from"fs/promises";import{join as o}from"path";import{cancel as s,confirm as c,intro as l,isCancel as u,log as d,multiselect as f,outro as p,select as m,spinner as h}from"@clack/prompts";import g from"defu";import{parse as _}from"jsonc-parser";import{readFileSync as v}from"fs";async function y(e=process.cwd()){try{let t=await S(e),n=t.devDependencies?.[`@biomejs/biome`];if(!n)throw Error(`@biomejs/biome not found in devDependencies`);return n}catch(e){throw Error(`Failed to get Biome version: ${e instanceof Error?e.message:`Unknown error`}`)}}function b(e,t=[],r={}){let i=`${e} ${t.join(` `)}`;n(i,{...r,stdio:`inherit`})}async function x(e){try{return await r(e),!0}catch{return!1}}async function S(e=process.cwd()){let t=o(e,`package.json`);if(!await x(t))throw Error(`package.json not found in the current directory`);try{let e=await i(t,`utf-8`),n=JSON.parse(e);return n}catch(e){throw Error(`Failed to parse package.json: ${e instanceof Error?e.message:`Unknown error`}`)}}async function C(e,t=process.cwd()){let n=o(t,`package.json`);try{await a(n,JSON.stringify(e,null,2))}catch(e){throw Error(`Failed to write package.json: ${e instanceof Error?e.message:`Unknown error`}`)}}const w=[`npm`,`yarn`,`pnpm`,`bun`];async function T(){let e=process.cwd(),t=await x(o(e,`package-lock.json`));if(t)return`npm`;let n=await x(o(e,`yarn.lock`));if(n)return`yarn`;let r=await x(o(e,`pnpm-lock.yaml`));if(r)return`pnpm`;let i=await x(o(e,`bun.lockb`))||await x(o(e,`bun.lock`));return i?`bun`:null}function E(e){switch(e){case`npm`:return`npx`;case`yarn`:return`yarn dlx`;case`pnpm`:return`pnpm dlx`;case`bun`:return`bunx`;default:return`npx`}}function D(){let e=process.stdout.columns||80;return e>=120?`
1
+ import{Command as e}from"commander";import t from"process";import{spawnSync as n}from"child_process";import{access as r,mkdir as i,readFile as a,writeFile as o}from"fs/promises";import{join as s}from"path";import{cancel as c,confirm as l,intro as u,isCancel as d,log as f,multiselect as p,outro as m,select as h,spinner as g}from"@clack/prompts";import _ from"defu";import{parse as v}from"jsonc-parser";import{readFileSync as y}from"fs";function b(e,t=[],r={}){let i=n(e,t,{...r,stdio:`inherit`});if(i.error)throw i.error;if(i.status!==0)throw Error(`Process exited with code ${i.status}`)}async function x(e){try{return await r(e),!0}catch{return!1}}async function S(e=process.cwd()){let t=s(e,`package.json`);if(!await x(t))throw Error(`package.json not found in the current directory`);try{let e=await a(t,`utf-8`),n=JSON.parse(e);return n}catch(e){throw Error(`Failed to parse package.json: ${e instanceof Error?e.message:`Unknown error`}`)}}async function C(e,t=process.cwd()){let n=s(t,`package.json`);try{await o(n,JSON.stringify(e,null,2))}catch(e){throw Error(`Failed to write package.json: ${e instanceof Error?e.message:`Unknown error`}`)}}const w=[`npm`,`yarn`,`pnpm`,`bun`];async function T(){let e=process.cwd(),t=await x(s(e,`package-lock.json`));if(t)return`npm`;let n=await x(s(e,`yarn.lock`));if(n)return`yarn`;let r=await x(s(e,`pnpm-lock.yaml`));if(r)return`pnpm`;let i=await x(s(e,`bun.lockb`))||await x(s(e,`bun.lock`));return i?`bun`:null}function E(e){switch(e){case`npm`:return`npx`;case`yarn`:return`yarn dlx`;case`pnpm`:return`pnpm dlx`;case`bun`:return`bunx`;default:return`npx`}}function D(){let e=process.stdout.columns||80;return e>=120?`
2
2
  █████ █████ ███ █████
3
3
  ░░███ ░░███ ░░░ ░░███
4
4
  ██████ ███████ ██████ █████████████ ██████ ████████ ███████ ████ ███████ ██████
@@ -11,4 +11,4 @@ import{Command as e}from"commander";import t from"process";import{execSync as n}
11
11
  ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
12
12
  ┃ ADAMANTITE ┃
13
13
  ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
14
- `}async function O(e,n){try{let t=await T(),r=E(t),i=[`@biomejs/biome`,`check`,`--write`];n.unsafe&&i.push(`--unsafe`),e.length>0&&i.push(...e),b(r,i)}catch(e){let n=e instanceof Error?e.message:`An unknown error occurred`;console.error(`Failed to run Adamantite:`,n),t.exit(1)}}const k={config:{extends:`adamantite/presets/tsconfig.json`},async exists(){return await x(o(process.cwd(),`tsconfig.json`))},async create(){await a(o(process.cwd(),`tsconfig.json`),JSON.stringify(this.config,null,2))},async update(){let e=await i(o(process.cwd(),`tsconfig.json`),`utf-8`),t=_(e),n=g(t,this.config);await a(o(process.cwd(),`tsconfig.json`),JSON.stringify(n,null,2))}},A={config:{$schema:`./node_modules/@biomejs/biome/configuration_schema.json`},async exists(){return await x(o(process.cwd(),`biome.jsonc`))},async create(){await a(o(process.cwd(),`biome.jsonc`),JSON.stringify({...this.config,extends:[`adamantite`]},null,2))},async update(){let e=await x(o(process.cwd(),`biome.jsonc`))?o(process.cwd(),`biome.jsonc`):o(process.cwd(),`biome.json`),t=await i(e,`utf-8`),n=_(t),r={...n};Array.isArray(r.extends)||(r.extends=r.extends?[r.extends]:[]),r.extends.includes(`adamantite`)||r.extends.push(`adamantite`);let s=g(r,this.config);await a(o(process.cwd(),`biome.jsonc`),JSON.stringify(s,null,2))}},j={config:{"typescript.tsdk":`node_modules/typescript/lib`,"editor.defaultFormatter":`esbenp.prettier-vscode`,"editor.formatOnSave":!0,"editor.formatOnPaste":!0,"editor.codeActionsOnSave":{"quickfix.biome":`explicit`,"source.organizeImports.biome":`explicit`,"source.fixAll.biome":`explicit`},"[javascript][typescript][javascriptreact][typescriptreact][json][jsonc][css][graphql]":{"editor.defaultFormatter":`biomejs.biome`}},async exists(){return await x(o(process.cwd(),`.vscode`,`settings.json`))},async create(){await a(o(process.cwd(),`.vscode`,`settings.json`),JSON.stringify(this.config,null,2))},async update(){let e=(await x(o(process.cwd(),`.vscode`,`settings.json`)),o(process.cwd(),`.vscode`,`settings.json`)),t=await i(e,`utf-8`),n=_(t),r=g(n,this.config);await a(o(process.cwd(),`.vscode`,`settings.json`),JSON.stringify(r,null,2))}};async function M(){let e=await m({message:`Select your package manager`,options:w.map(e=>({label:e,value:e})),initialValue:await T()});if(u(e)||e===null)throw Error(`No package manager selected`);if(e===void 0)throw Error(`Invalid package manager selected`);return e}async function N(){let e=t.cwd();if(await x(o(e,`pnpm-workspace.yaml`)))return!0;try{let e=await S();return e.workspaces!==void 0}catch{return!1}}async function P(){let e=h();await A.exists()?(e.start(`Biome config found, updating...`),await A.update(),e.stop(`Biome config updated with Adamantite preset`)):(e.start(`Biome config not found, creating...`),await A.create(),e.stop(`Biome config created with Adamantite preset`))}async function F({lint:e,format:t,monorepo:n}){let r=h();r.start("Adding scripts to your `package.json`...");try{let i=await S();i.scripts||={},e&&(i.scripts.lint=`adamantite lint`),t&&(i.scripts.format=`adamantite format`),n&&(i.scripts[`lint:monorepo`]=`adamantite monorepo`),await C(i),r.stop("Scripts added to your `package.json`")}catch(e){throw r.stop(`Failed to add scripts`),Error(`Failed to modify package.json: ${e instanceof Error?e.message:`Unknown error`}`)}}async function I(){let e=h();await k.exists()?(e.start("`tsconfig.json` found, updating..."),await k.update(),e.stop("Updated `tsconfig.json` with preset")):(e.start("`tsconfig.json` not found, creating..."),await k.create(),e.stop("Created `tsconfig.json` with preset"))}async function L(){let e=await f({message:`Which editors do you want to configure (recommended)?`,options:[{label:`VSCode / Cursor / Windsurf`,value:`vscode`},{label:`Zed (coming soon)`,value:`zed`}],required:!1});if(u(e))throw Error(`Operation cancelled`);return e}async function R(e){if(!e||e.length===0)return;let t=h();e.includes(`vscode`)&&(await j.exists()?(t.start(`VSCode settings found, updating...`),await j.update(),t.stop(`VSCode settings updated with Adamantite preset`)):(t.start(`VSCode settings not found, creating...`),await j.create(),t.stop(`VSCode settings created with Adamantite preset`))),e.includes(`zed`)&&(t.start(`Zed configuration coming soon...`),t.stop(`Zed configuration coming soon...`))}async function z(e){let t=await c({message:e});if(u(t))throw Error(`Operation cancelled`);return t}async function B(e,t){let n=h();n.start(`Installing dependencies...`);try{let r=await y(),i=[`adamantite`,`@biomejs/biome@^${r}`];switch(t?.monorepo&&i.push(`sherif@1.6.1`),e){case`npm`:b(`npm`,[`install`,`--save-dev`,`--exact`,...i]);break;case`yarn`:b(`yarn`,[`add`,`--dev`,`--exact`,...i]);break;case`pnpm`:b(`pnpm`,[`add`,`--save-dev`,`--save-exact`,...i]);break;case`bun`:b(`bun`,[`add`,`--dev`,`--exact`,...i]);break;default:throw Error(`Invalid package manager: ${e}`)}n.stop(`Dependencies installed successfully`)}catch(e){throw n.stop(`Failed to install dependencies`),Error(`Failed to install dependencies: ${e instanceof Error?e.message:`Unknown error`}`)}}async function V(){l(D());try{let e=await M(),t=await N(),n=await z("Do you want to add the `format` and `lint` scripts to your `package.json`?"),r=t?await z(`We've detected a monorepo setup in your project. Would you like to install monorepo linting scripts?`):!1,i=await z(`Adamantite provides a TypeScript preset to enforce strict type-safety. Would you like to install it?`),a=await L();await B(e,{monorepo:r}),await P(),(n||r)&&await F({lint:n,format:n,monorepo:r}),i&&await I(),await R(a),p(`💠 Adamantite initialized successfully!`)}catch(e){d.error(`${e instanceof Error?e.message:`Unknown error`}`),s(`Failed to initialize Adamantite`)}}async function H(e){try{let t=await T(),n=E(t),r=[`@biomejs/biome`,`lint`,`--fix`];e.length>0&&r.push(...e),b(n,r)}catch(e){let n=e instanceof Error?e.message:`An unknown error occurred`;console.error(`Failed to run Adamantite:`,n),t.exit(1)}}async function U(){try{let e=await T(),t=E(e);b(t,[`sherif`,`--fix`])}catch(e){let n=e instanceof Error?e.message:`An unknown error occurred`;console.error(`Failed to run Adamantite:`,n),t.exit(1)}}function W(){let e=JSON.parse(v(o(process.cwd(),`package.json`),`utf-8`));return e.version}const G=W();var K=G;const q=new e;q.version(K),q.name(`adamantite`).description(`An opinionated set of presets for modern TypeScript applications`),q.command(`init`).description(`Initialize Adamantite in the current directory`).action(V),q.command(`lint`).description(`Run Biome linter and fix files`).argument(`[files...]`,`specific files to lint (optional)`).action(H),q.command(`format`).description(`Run Biome formatter and fix files`).argument(`[files...]`,`specific files to format (optional)`).option(`--unsafe`,`apply unsafe fixes`).action(O),q.command(`monorepo`).description(`Lint and automatically fix monorepo-specific issues using Sherif`).action(U),q.parse();
14
+ `}async function O(e,n){try{let t=await T(),r=E(t),i=[`@biomejs/biome`,`check`,`--write`];n.unsafe&&i.push(`--unsafe`),e.length>0&&i.push(...e),b(r,i)}catch(e){let n=e instanceof Error?e.message:`An unknown error occurred`;console.error(`Failed to run Adamantite:`,n),t.exit(1)}}const k={config:{extends:`adamantite/presets/tsconfig.json`},async exists(){return await x(s(process.cwd(),`tsconfig.json`))},async create(){await o(s(process.cwd(),`tsconfig.json`),JSON.stringify(this.config,null,2))},async update(){let e=await a(s(process.cwd(),`tsconfig.json`),`utf-8`),t=v(e),n=_(this.config,t);await o(s(process.cwd(),`tsconfig.json`),JSON.stringify(n,null,2))}},A={version:`2.1.4`,config:{$schema:`./node_modules/@biomejs/biome/configuration_schema.json`},async exists(){return await x(s(process.cwd(),`biome.jsonc`))},async create(){await o(s(process.cwd(),`biome.jsonc`),JSON.stringify({...this.config,extends:[`adamantite`]},null,2))},async update(){let e=await x(s(process.cwd(),`biome.jsonc`))?s(process.cwd(),`biome.jsonc`):s(process.cwd(),`biome.json`),t=await a(e,`utf-8`),n=v(t),r={...n};Array.isArray(r.extends)||(r.extends=r.extends?[r.extends]:[]),r.extends.includes(`adamantite`)||r.extends.push(`adamantite`);let i=_(this.config,r);await o(s(process.cwd(),`biome.jsonc`),JSON.stringify(i,null,2))}},j={config:{"typescript.tsdk":`node_modules/typescript/lib`,"editor.defaultFormatter":`esbenp.prettier-vscode`,"editor.formatOnSave":!0,"editor.formatOnPaste":!0,"editor.codeActionsOnSave":{"quickfix.biome":`explicit`,"source.organizeImports.biome":`explicit`,"source.fixAll.biome":`explicit`},"[javascript][typescript][javascriptreact][typescriptreact][json][jsonc][css][graphql]":{"editor.defaultFormatter":`biomejs.biome`}},async exists(){return await x(s(process.cwd(),`.vscode`,`settings.json`))},async create(){let e=s(process.cwd(),`.vscode`);await i(e,{recursive:!0}),await o(s(e,`settings.json`),JSON.stringify(this.config,null,2))},async update(){let e=(await x(s(process.cwd(),`.vscode`,`settings.json`)),s(process.cwd(),`.vscode`,`settings.json`)),t=await a(e,`utf-8`),n=v(t),r=_(this.config,n);await o(s(process.cwd(),`.vscode`,`settings.json`),JSON.stringify(r,null,2))}},M={version:`1.6.1`};async function N(){let e=await h({message:`Select your package manager`,options:w.map(e=>({label:e,value:e})),initialValue:await T()});if(d(e)||e===null)throw Error(`No package manager selected`);if(e===void 0)throw Error(`Invalid package manager selected`);return e}async function P(){let e=t.cwd();if(await x(s(e,`pnpm-workspace.yaml`)))return!0;try{let e=await S();return e.workspaces!==void 0}catch{return!1}}async function F(){let e=g();await A.exists()?(e.start(`Biome config found, updating...`),await A.update(),e.stop(`Biome config updated with Adamantite preset`)):(e.start(`Biome config not found, creating...`),await A.create(),e.stop(`Biome config created with Adamantite preset`))}async function I({lint:e,format:t,monorepo:n}){let r=g();r.start("Adding scripts to your `package.json`...");try{let i=await S();i.scripts||={},e&&(i.scripts.lint=`adamantite lint`),t&&(i.scripts.format=`adamantite format`),n&&(i.scripts[`lint:monorepo`]=`adamantite monorepo`),await C(i),r.stop("Scripts added to your `package.json`")}catch(e){throw r.stop(`Failed to add scripts`),Error(`Failed to modify package.json: ${e instanceof Error?e.message:`Unknown error`}`)}}async function L(){let e=g();await k.exists()?(e.start("`tsconfig.json` found, updating..."),await k.update(),e.stop("Updated `tsconfig.json` with preset")):(e.start("`tsconfig.json` not found, creating..."),await k.create(),e.stop("Created `tsconfig.json` with preset"))}async function R(){let e=await p({message:`Which editors do you want to configure (recommended)?`,options:[{label:`VSCode / Cursor / Windsurf`,value:`vscode`},{label:`Zed (coming soon)`,value:`zed`}],required:!1});if(d(e))throw Error(`Operation cancelled`);return e}async function z(e){if(!e||e.length===0)return;let t=g();e.includes(`vscode`)&&(await j.exists()?(t.start(`VSCode settings found, updating...`),await j.update(),t.stop(`VSCode settings updated with Adamantite preset`)):(t.start(`VSCode settings not found, creating...`),await j.create(),t.stop(`VSCode settings created with Adamantite preset`))),e.includes(`zed`)&&(t.start(`Zed configuration coming soon...`),t.stop(`Zed configuration coming soon...`))}async function B(e){let t=await l({message:e});if(d(t))throw Error(`Operation cancelled`);return t}function V(e,t){let n=g();n.start(`Installing dependencies...`);try{let r=A.version,i=[`adamantite`,`@biomejs/biome@^${r}`];switch(t?.monorepo&&i.push(`sherif@${M.version}`),e){case`npm`:b(`npm`,[`install`,`--save-dev`,`--exact`,...i]);break;case`yarn`:b(`yarn`,[`add`,`--dev`,`--exact`,...i]);break;case`pnpm`:b(`pnpm`,[`add`,`--save-dev`,`--save-exact`,...i]);break;case`bun`:b(`bun`,[`add`,`--dev`,`--exact`,...i]);break;default:throw Error(`Invalid package manager: ${e}`)}n.stop(`Dependencies installed successfully`)}catch(e){throw n.stop(`Failed to install dependencies`),Error(`Failed to install dependencies: ${e instanceof Error?e.message:`Unknown error`}`)}}async function H(){u(D());try{let e=await N(),t=await P(),n=await B("Do you want to add the `format` and `lint` scripts to your `package.json`?"),r=t?await B(`We've detected a monorepo setup in your project. Would you like to install monorepo linting scripts?`):!1,i=await B(`Adamantite provides a TypeScript preset to enforce strict type-safety. Would you like to install it?`),a=await R();V(e,{monorepo:r}),await F(),(n||r)&&await I({lint:n,format:n,monorepo:r}),i&&await L(),await z(a),m(`💠 Adamantite initialized successfully!`)}catch(e){f.error(`${e instanceof Error?e.message:`Unknown error`}`),c(`Failed to initialize Adamantite`)}}async function U(e){try{let t=await T(),n=E(t),r=[`@biomejs/biome`,`lint`,`--fix`];e.length>0&&r.push(...e),b(n,r)}catch(e){let n=e instanceof Error?e.message:`An unknown error occurred`;console.error(`Failed to run Adamantite:`,n),t.exit(1)}}async function W(){try{let e=await T(),t=E(e);b(t,[`sherif`,`--fix`])}catch(e){let n=e instanceof Error?e.message:`An unknown error occurred`;console.error(`Failed to run Adamantite:`,n),t.exit(1)}}async function G(){let e=[];try{let t=await S(),n=t.devDependencies?.[`@biomejs/biome`];n&&n!==A.version&&e.push({name:`@biomejs/biome`,currentVersion:n,targetVersion:A.version,isDevDependency:!0});let r=t.devDependencies?.sherif;return r&&r!==M.version&&e.push({name:`sherif`,currentVersion:r,targetVersion:M.version,isDevDependency:!0}),e}catch(e){throw Error(`Failed to read package.json: ${e instanceof Error?e.message:`Unknown error`}`)}}function K(e,t){let n=g();n.start(`Updating dependencies...`);try{let r=t.map(e=>`${e.name}@${e.targetVersion}`);switch(e){case`npm`:b(`npm`,[`install`,`--save-dev`,`--save-exact`,...r]);break;case`yarn`:b(`yarn`,[`add`,`--dev`,`--exact`,...r]);break;case`pnpm`:b(`pnpm`,[`add`,`--save-dev`,`--save-exact`,...r]);break;case`bun`:b(`bun`,[`add`,`--dev`,`--exact`,...r]);break;default:throw Error(`Invalid package manager: ${e}`)}n.stop(`Dependencies updated successfully`)}catch(e){throw n.stop(`Failed to update dependencies`),Error(`Failed to update dependencies: ${e instanceof Error?e.message:`Unknown error`}`)}}async function q(e){f.message(`The following dependencies will be updated:`),f.message(``);for(let t of e)f.message(` ${t.name}: ${t.currentVersion} → ${t.targetVersion}`);f.message(``);let t=await l({message:`Do you want to proceed with these updates?`});if(d(t))throw Error(`Operation cancelled`);return t}async function J(){u(D());try{let e=await T();if(!e)throw Error(`Unable to detect package manager. Please ensure you have a lock file (package-lock.json, yarn.lock, pnpm-lock.yaml, or bun.lock/bun.lockb) in your project.`);let t=await G();if(t.length===0){f.success(`All adamantite dependencies are already up to date!`),m(`💠 No updates needed`);return}let n=await q(t);if(!n){m(`💠 Update cancelled`);return}K(e,t),m(`💠 Dependencies updated successfully!`)}catch(e){f.error(`${e instanceof Error?e.message:`Unknown error`}`),c(`Failed to update dependencies`)}}function Y(){let e=JSON.parse(y(s(process.cwd(),`package.json`),`utf-8`));return e.version}const X=Y();var Z=X;const Q=new e;Q.version(Z),Q.name(`adamantite`).description(`An opinionated set of presets for modern TypeScript applications`),Q.command(`init`).description(`Initialize Adamantite in the current directory`).action(H),Q.command(`lint`).description(`Run Biome linter and fix files`).argument(`[files...]`,`specific files to lint (optional)`).action(U),Q.command(`format`).description(`Run Biome formatter and fix files`).argument(`[files...]`,`specific files to format (optional)`).option(`--unsafe`,`apply unsafe fixes`).action(O),Q.command(`monorepo`).description(`Lint and automatically fix monorepo-specific issues using Sherif`).action(W),Q.command(`update`).description(`Update adamantite dependencies to latest compatible versions`).action(J),Q.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adamantite",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "An strict and opinionated set of presets for modern TypeScript applications",
5
5
  "keywords": [
6
6
  "adamantite",
@@ -50,8 +50,9 @@
50
50
  "devDependencies": {
51
51
  "@biomejs/biome": "2.1.4",
52
52
  "@changesets/cli": "2.29.5",
53
- "@types/bun": "1.2.19",
54
- "tsdown": "0.13.5",
53
+ "@types/bun": "1.2.20",
54
+ "sherif": "1.6.1",
55
+ "tsdown": "0.14.1",
55
56
  "type-fest": "4.41.0",
56
57
  "typescript": "5.9.2"
57
58
  },