create-arkstack 0.10.5 → 0.10.6

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/bin/run.js +2 -2
  2. package/package.json +1 -1
package/bin/run.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import{AbortPromptError as e,ExitPromptError as t}from"@inquirer/core";import n,{basename as r,join as i,relative as a}from"node:path";import{copyFile as o,cp as s,readFile as c,readdir as l,rename as u,rm as d,unlink as f,writeFile as p}from"node:fs/promises";import{Logger as m,Resolver as h}from"@h3ravel/shared";import{Str as g}from"@h3ravel/support";import{chdir as _}from"node:process";import{detectPackageManager as v}from"@antfu/install-pkg";import{downloadTemplate as y}from"giget";import{existsSync as b}from"node:fs";import{spawnSync as x}from"node:child_process";import{Command as S,Kernel as C}from"@h3ravel/musket";import w from"inquirer";async function T(e){let t=n.join(e,`templates`),r=await l(e);await s(t,e,{recursive:!0}),await Promise.all(r.filter(e=>e!==`templates`).map(t=>d(n.join(e,t),{recursive:!0,force:!0}))),await d(t,{recursive:!0,force:!0})}async function E(e,t){let r=await l(e);for(let i of r)i!==t&&await d(n.join(e,i),{recursive:!0,force:!0})}async function D(e,t){let r=n.isAbsolute(t)?t:n.join(process.cwd(),t),i=n.isAbsolute(e)?e:n.join(process.cwd(),e);if(!r.startsWith(i))throw Error(`Source must be inside the parent directory`);let a=await l(r);for(let e of a)await u(n.join(r,e),n.join(i,e));await d(r,{recursive:!0})}const O=[{name:`Express`,alias:`express`,hint:`Arkstack application running on Express`,source:`github:arkstack-tmp/arkstack`},{name:`H3`,alias:`h3`,hint:`Arkstack application running on H3`,source:`github:arkstack-tmp/arkstack`}],k=[{name:`Lean`,hint:`A minimal Arkstack application running on {template}`,lean:!0},{name:`Full`,hint:`Full Arkstack experience on {template}`,lean:!1}],A=[`src/app`,`src/app/http/controllers`,`src/app/http/resources`,`src/models`,`src/app/models`,`database`,`src/routes/api.ts`,`src/database`,`src/core/database.ts`,`src/config/filesystem.ts`,`src/config/notifications.ts`,`prisma`,`prisma.config.ts`,`arkorm.config.ts`,`arkormx.config.ts`,`arkorm.config.js`,`arkormx.config.js`,`arkorm.config.mjs`,`arkormx.config.mjs`],j=[`@types/pg`,`@prisma/client`,`@prisma/adapter-pg`,`@arkstack/auth`,`@arkstack/database`,`@arkstack/filesystem`,`@arkstack/notifications`,`pg`,`kysely`,`prisma`,`arkormx`],M=[],N={"@arkstack/auth":`^0.10.5`,"@arkstack/common":`^0.10.5`,"@arkstack/console":`^0.10.5`,"@arkstack/contract":`^0.10.5`,"@arkstack/database":`^0.10.5`,"@arkstack/driver-express":`^0.10.5`,"@arkstack/driver-h3":`^0.10.5`,"@arkstack/filesystem":`^0.10.5`,"@arkstack/http":`^0.10.5`,"@arkstack/view":`^0.10.5`,"@arkstack/notifications":`^0.10.5`},P={min:[`APP_URL`,`APP_PORT`],max:[`JWT_SECRET`,`JWT_EXPIRES_IN`,`DATABASE_URL`]};var F=class{location;appName;description;skipInstallation;packageJson={};pkgPath;constructor(e,t,n){this.location=e,this.appName=t,this.description=n,this.location||=i(process.cwd(),`.temp`)}async pm(){return await v()??`npm`}async runCmd(e=!1){if(e)return`npx`;let t=await this.pm();return t===`npm`?`npm run`:t}async download(e,t=!1,n,r=!1){return this.location?.includes(`.temp`)||r&&b(this.location)?await d(this.location,{force:!0,recursive:!0}):b(this.location)&&(await l(this.location??`./`))?.length>0&&(console.log(`
2
+ import{AbortPromptError as e,ExitPromptError as t}from"@inquirer/core";import n,{basename as r,join as i,relative as a}from"node:path";import{copyFile as o,cp as s,readFile as c,readdir as l,rename as u,rm as d,unlink as f,writeFile as p}from"node:fs/promises";import{Logger as m,Resolver as h}from"@h3ravel/shared";import{Str as g}from"@h3ravel/support";import{chdir as _}from"node:process";import{detectPackageManager as v}from"@antfu/install-pkg";import{downloadTemplate as y}from"giget";import{existsSync as b}from"node:fs";import{spawnSync as x}from"node:child_process";import{Command as S,Kernel as C}from"@h3ravel/musket";import w from"inquirer";async function T(e){let t=n.join(e,`templates`),r=await l(e);await s(t,e,{recursive:!0}),await Promise.all(r.filter(e=>e!==`templates`).map(t=>d(n.join(e,t),{recursive:!0,force:!0}))),await d(t,{recursive:!0,force:!0})}async function E(e,t){let r=await l(e);for(let i of r)i!==t&&await d(n.join(e,i),{recursive:!0,force:!0})}async function D(e,t){let r=n.isAbsolute(t)?t:n.join(process.cwd(),t),i=n.isAbsolute(e)?e:n.join(process.cwd(),e);if(!r.startsWith(i))throw Error(`Source must be inside the parent directory`);let a=await l(r);for(let e of a)await u(n.join(r,e),n.join(i,e));await d(r,{recursive:!0})}const O=[{name:`Express`,alias:`express`,hint:`Arkstack application running on Express`,source:`github:arkstack-tmp/arkstack`},{name:`H3`,alias:`h3`,hint:`Arkstack application running on H3`,source:`github:arkstack-tmp/arkstack`}],k=[{name:`Lean`,hint:`A minimal Arkstack application running on {template}`,lean:!0},{name:`Full`,hint:`Full Arkstack experience on {template}`,lean:!1}],A=[`src/app`,`src/app/http/controllers`,`src/app/http/resources`,`src/models`,`src/app/models`,`database`,`src/routes/api.ts`,`src/database`,`src/core/database.ts`,`src/config/filesystem.ts`,`src/config/notifications.ts`,`prisma`,`prisma.config.ts`,`arkorm.config.ts`,`arkormx.config.ts`,`arkorm.config.js`,`arkormx.config.js`,`arkorm.config.mjs`,`arkormx.config.mjs`],j=[`@types/pg`,`@prisma/client`,`@prisma/adapter-pg`,`@arkstack/auth`,`@arkstack/database`,`@arkstack/filesystem`,`@arkstack/notifications`,`pg`,`kysely`,`prisma`,`arkormx`],M=[],N={"@arkstack/auth":`^0.10.6`,"@arkstack/common":`^0.10.6`,"@arkstack/console":`^0.10.6`,"@arkstack/contract":`^0.10.6`,"@arkstack/database":`^0.10.6`,"@arkstack/driver-express":`^0.10.6`,"@arkstack/driver-h3":`^0.10.6`,"@arkstack/filesystem":`^0.10.6`,"@arkstack/http":`^0.10.6`,"@arkstack/view":`^0.10.6`,"@arkstack/notifications":`^0.10.6`},P={min:[`APP_URL`,`APP_PORT`],max:[`JWT_SECRET`,`JWT_EXPIRES_IN`,`DATABASE_URL`]};var F=class{location;appName;description;skipInstallation;packageJson={};pkgPath;constructor(e,t,n){this.location=e,this.appName=t,this.description=n,this.location||=i(process.cwd(),`.temp`)}async pm(){return await v()??`npm`}async runCmd(e=!1){if(e)return`npx`;let t=await this.pm();return t===`npm`?`npm run`:t}async download(e,t=!1,n,r=!1){return this.location?.includes(`.temp`)||r&&b(this.location)?await d(this.location,{force:!0,recursive:!0}):b(this.location)&&(await l(this.location??`./`))?.length>0&&(console.log(`
3
3
  `),m.parse([[` ERROR `,`bgRed`],[this.location,[`gray`,`italic`]],[`is not empty.`,`white`]],` `),console.log(``),process.exit(0)),this.skipInstallation=!t,this.removeLockFile(),await y(e,{dir:this.location,auth:n,provider:`github`,registry:await this.pm(),forceClean:!1})}async installPackage(e,t=[]){let n=await h.getPakageInstallCommand()+(e?` ${e}`:``),r=n?.split(` `)[0];n.includes(` `)&&t.unshift(...n.split(` `).slice(1));let i=x(r,t,{cwd:process.cwd(),stdio:`ignore`});return i.error?i.status:0}async complete(e=!1){let t=!1;e&&(t=await this.installPackage()===0),console.log(``);let r=`./`+a(process.cwd(),this.location);try{_(n.join(process.cwd(),r))}catch{}m.success(`Your Arkstack project has been created successfully`),m.parse([[`cd`,`cyan`],[r,`yellow`],r===process.cwd()?[`✔`,`green`]:[``,`green`]],` `),t||m.parse([[await h.getPakageInstallCommand(),`cyan`]]),m.parse([[await this.runCmd(),`cyan`],[`dev`,`yellow`]],` `),m.parse([[`Open`,`cyan`],[`http://localhost:3000`,`yellow`]]),console.log(``),m.parse([[`Have any questions`,`white`]]),m.parse([[`Join our Discord server -`,`white`],[`https://discord.gg/jmQybxKQ7R`,`yellow`]]),m.parse([[`Checkout our other projects -`,`white`],[`https://toneflix.net/open-source`,`yellow`]])}async removeLockFile(){this.skipInstallation&&await Promise.allSettled([f(i(this.location,`package-lock.json`)),f(i(this.location,`yarn.lock`)),f(i(this.location,`pnpm-lock.yaml`))])}async getBanner(){return await c(i(process.cwd(),`./logo.txt`),`utf-8`)}async createDotEnv(e=`max`){let t=i(this.location,`.env`),n=i(this.location,`.env.example`),r=e===`max`?[...P.max,...P.min]:P.min;if(b(n)){let e=(await c(n,`utf-8`)).split(/\r?\n/);for(let t=0;t<e.length;t++){let n=e[t],i=n.split(`=`).at(0)??``;i===``||n===``||n.trim().startsWith(`#`)||r.includes(i)||delete e[t]}e=e.slice(e.findIndex(e=>e),e.findLastIndex(e=>e)+1),await p(n,e.join(`
4
4
  `)),await o(n,t)}}async saveProfile(){this.pkgPath&&await p(this.pkgPath,JSON.stringify(this.packageJson,null,2))}async makeProfile(){let e=i(this.location,`package.json`);if(b(e)){this.pkgPath=e,this.packageJson=await c(e,`utf-8`).then(JSON.parse);for(let[e]of Object.entries(this.packageJson.dependencies))e.includes(`@arkstack/`)&&delete this.packageJson.dependencies[e];let t=Object.fromEntries([...Object.entries(N),...Object.entries(this.packageJson.dependencies)]);this.packageJson.dependencies=t}else this.packageJson={}}async makeFullProfile(e){if(await this.makeProfile(),this.pkgPath)for(let e of M)delete this.packageJson.dependencies?.[e],delete this.packageJson.devDependencies?.[e]}async makeLeanProfile(e){if(await Promise.allSettled(A.map(e=>d(i(this.location,e),{force:!0,recursive:!0}))),await this.makeProfile(),this.pkgPath)for(let e of j)delete this.packageJson.dependencies?.[e],delete this.packageJson.devDependencies?.[e];for(let e of[`src/core/app.ts`,`src/core/router.ts`,`src/core/bootstrap.ts`]){let t=i(this.location,e);if(!b(t))continue;let n=await c(t,`utf-8`);n=n.replace(`import { ValidatorDBDriver } from '@arkstack/database'
5
5
  `,``).replace(`import { ModelNotFoundException } from 'arkormx'
@@ -31,4 +31,4 @@ import{AbortPromptError as e,ExitPromptError as t}from"@inquirer/core";import n,
31
31
  {--l|lean: Make a lean project.}
32
32
  {--p|pre: Download prerelease version if available.}
33
33
  {--o|overwrite: Overwrite the installation directory if it is not empty.}
34
- `;description=`Display a personalized greeting.`;async handle(){let n=this.options(),a=this.argument(`location`);console.log(I,`font-family: monospace`);let{template:o}=await w.prompt([{type:`list`,name:`template`,message:`Choose Runtime:`,choices:O.map(e=>({name:`${e.name} - ${e.hint}`,value:e.alias,disabled:e.source?!1:`(Unavailable at this time)`})),default:`full`,when:()=>!n.kit}]).catch(n=>((n instanceof e||n instanceof t)&&(this.info(`Thanks for trying out Arkstack.`),process.exit(0)),n)),{lean:s,appName:c,description:l}=await w.prompt([{type:`list`,name:`lean`,message:`Project Scope:`,choices:k.map(e=>({name:`${e.name} - ${e.hint.replace(`{template}`,g.title(o))}`,value:e.lean})),default:`full`,when:()=>!n.lean},{type:`input`,name:`appName`,message:`What is the name of your project:`,default:`arkstack-${o}`,when:()=>!n.name},{type:`input`,name:`description`,message:`Project Description:`,default:`Simple ${g.of(o).ucfirst()}.js project created with Arkstack.`,when:()=>!n.desc}]).catch(n=>((n instanceof e||n instanceof t)&&(this.info(`Thanks for trying out Arkstack.`),process.exit(0)),n)),{location:u}=await w.prompt([{type:`input`,name:`location`,message:`Installation location relative to the current dir:`,default:g.slugify(n.name??c??r(process.cwd()),`-`),when:()=>!a}]).catch(n=>((n instanceof e||n instanceof t)&&(this.info(`Thanks for trying out Arkstack.`),process.exit(0)),n)),d=O.find(e=>e.alias===(n.kit||o));d.lean=n.lean||s||!1;let{install:f,token:p,pre:h}=await w.prompt([{type:`confirm`,name:`pre`,message:`An alpha version of the ${d.name.replace(/\s*template$/i,``).trim()} template is available. Would you like to use it instead?`,default:!1,when:()=>d.prereleaseSource&&!n.pre},{type:`input`,name:`token`,message:`Authentication token:`,when:()=>n.kit&&!n.token},{type:`confirm`,name:`install`,message:`Would you like to install node_modules right away?:`,default:!0,when:()=>!n.install}]).catch(n=>((n instanceof e||n instanceof t)&&(this.info(`Thanks for trying out Arkstack.`),process.exit(0)),n));h=n.pre??h,p=n.token??p,c=n.name??c,f=n.install??f,o=n.kit??o,u=a??u,l=n.description??l,d&&!d.source&&(this.error(`ERROR: The ${d.name} kit is not currently available`),process.exit(1));let _=(d.baseAlias??d.alias).replace(/-lean$/i,``),v=h&&d.prereleaseSource?d.prereleaseSource:d.source,y=new F(i(process.cwd(),u),c,l),b=this.spinner(`Loading Template...`).start(),x=await y.download(v,f,p,n.overwrite);x.dir&&_&&(await T(x.dir),await E(x.dir,_),await D(x.dir,i(x.dir,_))),d.lean?(b.info(m.parse([[`Applying lean profile...`,`green`]],``,!1)).start(),await y.makeLeanProfile(_)):await y.makeFullProfile(_),b.info(m.parse([[`Cleaning Up...`,`green`]],``,!1)).start(),await y.cleanup(_),b.info(m.parse([[`Initializing Project...`,`green`]],``,!1)).start(),await y.createDotEnv(d.lean?`min`:`max`),await y.complete(f),b.succeed(m.parse([[`Project initialization complete!`,`green`]],``,!1))}},R=class{};C.init(new R,{rootCommand:L,exceptionHandler:e=>{m.error(`ERROR: ${e.message}`)}});export{};
34
+ `;description=`Display a personalized greeting.`;async handle(){let n=this.options(),a=this.argument(`location`);console.log(I,`font-family: monospace`);let{template:o}=await w.prompt([{type:`list`,name:`template`,message:`Choose Runtime:`,choices:O.map(e=>({name:`${e.name} - ${e.hint}`,value:e.alias,disabled:e.source?!1:`(Unavailable at this time)`})),default:`full`,when:()=>!n.kit}]).catch(n=>((n instanceof e||n instanceof t)&&(this.info(`Thanks for trying out Arkstack.`),process.exit(0)),n)),{lean:s,appName:c,description:l}=await w.prompt([{type:`list`,name:`lean`,message:`Project Scope:`,choices:k.map(e=>({name:`${e.name} - ${e.hint.replace(`{template}`,g.title(n.kit||o))}`,value:e.lean})),default:`full`,when:()=>!n.lean},{type:`input`,name:`appName`,message:`What is the name of your project:`,default:`arkstack-${n.kit||o}`,when:()=>!n.name},{type:`input`,name:`description`,message:`Project Description:`,default:`Simple ${g.of(n.kit||o).ucfirst()}.js project created with Arkstack.`,when:()=>!n.desc}]).catch(n=>((n instanceof e||n instanceof t)&&(this.info(`Thanks for trying out Arkstack.`),process.exit(0)),n)),{location:u}=await w.prompt([{type:`input`,name:`location`,message:`Installation location relative to the current dir:`,default:g.slugify(n.name??c??r(process.cwd()),`-`),when:()=>!a}]).catch(n=>((n instanceof e||n instanceof t)&&(this.info(`Thanks for trying out Arkstack.`),process.exit(0)),n)),d=O.find(e=>e.alias===(n.kit||o));d.lean=n.lean||s||!1;let{install:f,token:p,pre:h}=await w.prompt([{type:`confirm`,name:`pre`,message:`An alpha version of the ${d.name.replace(/\s*template$/i,``).trim()} template is available. Would you like to use it instead?`,default:!1,when:()=>d.prereleaseSource&&!n.pre},{type:`input`,name:`token`,message:`Authentication token:`,when:()=>n.kit&&!n.token},{type:`confirm`,name:`install`,message:`Would you like to install node_modules right away?:`,default:!0,when:()=>!n.install}]).catch(n=>((n instanceof e||n instanceof t)&&(this.info(`Thanks for trying out Arkstack.`),process.exit(0)),n));h=n.pre??h,p=n.token??p,c=n.name??c,f=n.install??f,o=n.kit??o,u=a??u,l=n.description??l,d&&!d.source&&(this.error(`ERROR: The ${d.name} kit is not currently available`),process.exit(1));let _=(d.baseAlias??d.alias).replace(/-lean$/i,``),v=h&&d.prereleaseSource?d.prereleaseSource:d.source,y=new F(i(process.cwd(),u),c,l),b=this.spinner(`Loading Template...`).start(),x=await y.download(v,f,p,n.overwrite);x.dir&&_&&(await T(x.dir),await E(x.dir,_),await D(x.dir,i(x.dir,_))),d.lean?(b.info(m.parse([[`Applying lean profile...`,`green`]],``,!1)).start(),await y.makeLeanProfile(_)):await y.makeFullProfile(_),b.info(m.parse([[`Cleaning Up...`,`green`]],``,!1)).start(),await y.cleanup(_),b.info(m.parse([[`Initializing Project...`,`green`]],``,!1)).start(),await y.createDotEnv(d.lean?`min`:`max`),await y.complete(f),b.succeed(m.parse([[`Project initialization complete!`,`green`]],``,!1))}},R=class{};C.init(new R,{rootCommand:L,exceptionHandler:e=>{m.error(`ERROR: ${e.message}`)}});export{};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "create-arkstack",
3
3
  "type": "module",
4
- "version": "0.10.5",
4
+ "version": "0.10.6",
5
5
  "description": "Create new Arkstack framework applications on Express or H3 runtime drivers",
6
6
  "homepage": "https://arkstack.toneflix.net",
7
7
  "repository": {