create-pluto 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.
package/README.md CHANGED
@@ -1,11 +1,17 @@
1
1
  # create-pluto
2
2
 
3
- A command-line tool to quickly set up a new Pluto CMS project with your preferred configurations.
3
+ A command-line tool to quickly set up a new Pluto project with your preferred configurations.
4
4
 
5
5
  ## Usage
6
6
 
7
7
  ```bash
8
8
  npm create pluto@latest
9
+
10
+ # or
11
+ pnpm create pluto@latest
12
+
13
+ # or
14
+ bun create pluto@latest
9
15
  ```
10
16
 
11
17
  You can also pass a target directory and preselect a template shortcut.
package/dist/index.mjs CHANGED
@@ -1,2 +1,4 @@
1
- import e from"node:fs";import t from"node:path";import{cancel as n,confirm as r,isCancel as i,log as a,select as o,spinner as s,text as c}from"@clack/prompts";import{downloadTemplate as l}from"giget";const u=/^postgres(?:ql)?:\/\//i;function d(e){return URL.canParse(e)}function f(e){return u.test(e)}async function p(){let e,t,r;for(;!e;){let t=await c({message:`Type/Paste your Supabase URL:`});if(i(t)&&(n(`Operation cancelled.`),process.exit(0)),!t||!d(t)){a.error(`Enter a valid Supabase URL, like https://xxxxx.supabase.co.`);continue}e=t}for(;!t;){let e=await c({message:`Type/Paste your Supabase Key:`});if(i(e)&&(n(`Operation cancelled.`),process.exit(0)),!e){a.error(`Supabase Key is required.`);continue}t=e}for(a.info(`Now find your database connection string: open your Supabase project, go to Project Settings > Database > Connection string, and copy the URI (the pooler connection works too).`);!r;){let e=await c({message:`Type/Paste your Supabase database connection string:`});if(i(e)&&(n(`Operation cancelled.`),process.exit(0)),!e||!f(e)){a.error(`Enter a valid Postgres connection string, starting with postgres:// or postgresql://.`);continue}r=e}return{supabaseUrl:e,supabaseKey:t,databaseUrl:r}}function m(e,t,n){let r={};return r.SUPABASE_URL=e?.toString()??``,r.SUPABASE_KEY=t?.toString()??``,r.DATABASE_URL=n?.toString()??``,{envVars:r}}const h=process.cwd(),g={blue:e=>`\x1B[34m${e}\x1B[0m`,green:e=>`\x1B[32m${e}\x1B[0m`},_={databases:[{value:`supabase`,label:`Supabase`,hint:`Hosted Postgres Database`}],templates:[{value:`shop`,label:`Shop (e-commerce)`,hint:`A full-featured online store template`},{value:`blog`,label:`Blog`,hint:`A simple blog template with a rich text editor`}]};function v(e){let t={};for(let n=0;n<e.length;n+=1){let r=e[n];if(r===`-t`||r===`--template`){t.templateShortcut=e[n+1],n+=1;continue}if(r?.startsWith(`--template=`)){t.templateShortcut=r.split(`=`)[1];continue}!r?.startsWith(`-`)&&!t.projectDir&&(t.projectDir=r)}return t}function y(e){let[t,n]=e.split(`-`,2),r=_.databases.some(e=>e.value===t),i=_.templates.some(e=>e.value===n);if(!r||!i){let t=_.databases.flatMap(e=>_.templates.map(t=>`${e.value}-${t.value}`));a.error(`Unknown template \"${e}\". Available options: ${t.join(`, `)}`),process.exit(1)}return{databaseProvider:t,templateChoice:n}}const b=v(process.argv.slice(2)),x=b.templateShortcut?y(b.templateShortcut):void 0,S=b.projectDir?b.projectDir:await c({message:`Where do you want to create your Pluto project?`,placeholder:`./my-pluto-project`,defaultValue:`my-pluto-project`});i(S)&&(n(`Operation cancelled.`),process.exit(0));const C=t.resolve(h,S);e.existsSync(C)||e.mkdirSync(C,{recursive:!0});const w=await c({message:`Website title:`,placeholder:`My Awesome Website`,defaultValue:`My Awesome Website`});i(w)&&(n(`Operation cancelled.`),process.exit(0));const T=x?x.databaseProvider:await o({message:`Pick a database provider.`,options:_.databases});i(T)&&(n(`Operation cancelled.`),process.exit(0));let E,D,O;if(T===`supabase`){a.warn(`You must have a Supabase project set up. If you do not have one, please create it at:\n${g.blue(`https://database.new/`)}.`);let{supabaseUrl:e,supabaseKey:t,databaseUrl:n}=await p();(!e||!t||!n)&&(a.error(`Supabase setup failed.`),process.exit(1)),E=e,D=t,O=n}const k=s();e.existsSync(`${h}/nuxt.config.ts`)&&(await r({message:`Nuxt project detected. Do you want to add Pluto environment variables?`})||process.exit(0));const A=x?x.templateChoice:await o({message:`Select a template to use. You can add more layers as needed.`,options:_.templates});i(A)&&(n(`Operation cancelled.`),process.exit(0)),e.readdirSync(C).length>0&&(await r({message:`The folder ${g.green(S)} is not empty. Do you want to continue and potentially overwrite existing files?`})||(n(`Operation cancelled.`),process.exit(0))),k.start(`Downloading Pluto template...`);const{source:j}=await l(`gh:plutocms/pluto-${T}-${A}-template`,{dir:C,force:!0});a.info(`Template downloaded from ${g.green(j)}`);const M=t.resolve(C,`.env`),N={WEBSITE_NAME:w?.toString()??``};if(T===`supabase`){let{envVars:e}=m(E,D,O);Object.assign(N,e)}try{let t=``;e.existsSync(M)?(t=e.readFileSync(M,`utf-8`),Object.entries(N).forEach(([e,n])=>{let r=RegExp(`^${e}=.*$`,`m`);r.test(t)?t=t.replace(r,`${e}="${n}"`):t+=`\n${e}="${n}"`})):(t=`# Pluto Configurations
2
- `,Object.entries(N).forEach(([e,n])=>{t+=`${e}="${n}"\n`})),e.writeFileSync(M,`${t.trim()}\n`)}catch(e){a.error(`Failed to write to .env file: ${e}`),process.exit(1)}k.stop(`All done!`),a.success(`Setup complete! 🎉`),a.info(`Nuxt project created in: ${g.green(S)}`);export{};
1
+ import e from"node:fs";import t from"node:path";import{cancel as n,confirm as r,isCancel as i,log as a,password as o,select as s,spinner as c,text as l}from"@clack/prompts";import{downloadTemplate as u}from"giget";import{randomBytes as d}from"node:crypto";const f=/^[\w.-]+\/[\w.-]+$/,p=/\r?\n/,m=/^(["'])(.*)\1$/;function h(e){return f.test(e)}function g(e){return e.trim().split(p).join(`\\n`)}function _(e){return e.trim().replace(m,`$2`)}async function v(e,t,r={}){let a=await e({message:t,...r});return i(a)&&(n(`Operation cancelled.`),process.exit(0)),(a??``).toString().trim()}async function y(e={}){let t={repo:``,appSlug:``,appId:``,clientId:``,clientSecret:``,privateKeyPath:``};return e.interactive??process.stdin.isTTY?(a.info(`Posts are Markdown files in a GitHub repository. You can skip any question and fill the .env file later.`),t.repo=await v(l,`GitHub repository for the posts (owner/name, optional):`,{placeholder:`your-name/your-blog`,validate:e=>e&&!h(e.trim())?`Use the format owner/name, like your-name/your-blog.`:void 0}),t.appSlug=await v(l,`GitHub App slug (github.com/apps/<slug>, optional):`),t.appId=await v(l,`GitHub App ID (optional):`),t.clientId=await v(l,`GitHub App Client ID (optional):`),t.clientSecret=await v(o,`GitHub App Client secret (optional, hidden):`),t.privateKeyPath=_(await v(l,`Path to the GitHub App private key .pem file (optional):`)),t):t}function b(n,r=process.cwd()){if(!n)return``;try{let i=e.readFileSync(t.resolve(r,n),`utf-8`);return i.includes(`-----BEGIN`)?g(i):(a.warn(`The key file is not a PEM file. Skipping the private key.`),``)}catch{return a.warn(`Could not read the key file at ${n}. Skipping the private key.`),``}}function x(e,t=process.cwd()){return{envVars:{PLUTO_CMS_REPO:e.repo,PLUTO_CMS_APP_SLUG:e.appSlug,NUXT_PLUTO_CMS_SESSION_PASSWORD:d(32).toString(`base64url`),NUXT_PLUTO_CMS_GITHUB_APP_ID:e.appId,NUXT_PLUTO_CMS_GITHUB_CLIENT_ID:e.clientId,NUXT_PLUTO_CMS_GITHUB_CLIENT_SECRET:e.clientSecret,NUXT_PLUTO_CMS_GITHUB_PRIVATE_KEY:b(e.privateKeyPath,t)}}}function S(e){let t=[`Run "bun run dev" and open http://localhost:3000/admin. You are signed in as a local user, and the posts are files in the content/ folder. No GitHub App is needed for this.`,`Deploy the site (for example to Vercel). Then open /admin/login on the deployed site and select "Create the GitHub App". Follow the page: paste the values in the environment variables of the host, redeploy, and install the App on the repository of your blog.`,`Step by step: "GitHub CMS in 10 minutes" (https://pluto.vulmix.dev/github-cms/quickstart). The manual steps are in the template README:
2
+ https://github.com/plutocms/pluto-core-blog-template#set-up-the-cms`];e.repo||t.splice(1,0,`Set PLUTO_CMS_REPO in .env, or deploy from a GitHub repository (Vercel gives the repository to Pluto).`),a.info(`Next steps:\n${t.map((e,t)=>`${t+1}. ${e}`).join(`
3
+ `)}`)}const C=/^postgres(?:ql)?:\/\//i;function w(e){return URL.canParse(e)}function T(e){return C.test(e)}async function E(){let e,t,r;for(;!e;){let t=await l({message:`Type/Paste your Supabase URL:`});if(i(t)&&(n(`Operation cancelled.`),process.exit(0)),!t||!w(t)){a.error(`Enter a valid Supabase URL, like https://xxxxx.supabase.co.`);continue}e=t}for(;!t;){let e=await l({message:`Type/Paste your Supabase Key:`});if(i(e)&&(n(`Operation cancelled.`),process.exit(0)),!e){a.error(`Supabase Key is required.`);continue}t=e}for(a.info(`Now find your database connection string: open your Supabase project, go to Project Settings > Database > Connection string, and copy the URI (the pooler connection works too).`);!r;){let e=await l({message:`Type/Paste your Supabase database connection string:`});if(i(e)&&(n(`Operation cancelled.`),process.exit(0)),!e||!T(e)){a.error(`Enter a valid Postgres connection string, starting with postgres:// or postgresql://.`);continue}r=e}return{supabaseUrl:e,supabaseKey:t,databaseUrl:r}}function D(e,t,n){let r={};return r.SUPABASE_URL=e?.toString()??``,r.SUPABASE_KEY=t?.toString()??``,r.DATABASE_URL=n?.toString()??``,{envVars:r}}function O(t,n){let r=``;e.existsSync(t)?(r=e.readFileSync(t,`utf-8`),Object.entries(n).forEach(([e,t])=>{let n=RegExp(`^${e}=.*$`,`m`),i=`${e}="${t}"`;n.test(r)?r=r.replace(n,()=>i):r+=`\n${i}`})):(r=`# Pluto Configurations
4
+ `,Object.entries(n).forEach(([e,t])=>{r+=`${e}="${t}"\n`})),e.writeFileSync(t,`${r.trim()}\n`)}const k={databases:[{value:`supabase`,label:`Supabase`,hint:`Hosted Postgres Database`,templates:[`shop`,`blog`]},{value:`core`,label:`None (Markdown files in GitHub)`,hint:`No database. Posts are Markdown files in a GitHub repository`,templates:[`blog`]}],templates:[{value:`shop`,label:`Shop (e-commerce)`,hint:`A full-featured online store template`},{value:`blog`,label:`Blog`,hint:`A simple blog template with a rich text editor`}]};function A(e){let t=k.databases.find(t=>t.value===e);return k.templates.filter(e=>t?.templates.includes(e.value))}function j(){return k.databases.flatMap(e=>A(e.value).map(t=>`${e.value}-${t.value}`))}function M(e){let t=(e??``).split(`-`),[n,r]=t,i=`Available options: ${j().join(`, `)}`,a=k.databases.find(e=>e.value===n),o=k.templates.some(e=>e.value===r);return t.length!==2||!a||!o?{ok:!1,message:`Unknown template "${e}". ${i}`}:a.templates.includes(r)?{ok:!0,databaseProvider:n,templateChoice:r}:{ok:!1,message:`The "${n}" option has no "${r}" template. ${i}`}}const N=process.cwd(),P={blue:e=>`\x1B[34m${e}\x1B[0m`,green:e=>`\x1B[32m${e}\x1B[0m`};function F(e){let t={};for(let n=0;n<e.length;n+=1){let r=e[n];if(r===`-t`||r===`--template`){t.templateShortcut=e[n+1],n+=1;continue}if(r?.startsWith(`--template=`)){t.templateShortcut=r.split(`=`)[1];continue}!r?.startsWith(`-`)&&!t.projectDir&&(t.projectDir=r)}return t}const I=F(process.argv.slice(2));let L;if(I.templateShortcut){let e=M(I.templateShortcut);e.ok||(a.error(e.message),process.exit(1)),L=e}const R=I.projectDir?I.projectDir:await l({message:`Where do you want to create your Pluto project?`,placeholder:`./my-pluto-project`,defaultValue:`my-pluto-project`});i(R)&&(n(`Operation cancelled.`),process.exit(0));const z=t.resolve(N,R);e.existsSync(z)||e.mkdirSync(z,{recursive:!0});const B=await l({message:`Website title:`,placeholder:`My Awesome Website`,defaultValue:`My Awesome Website`});i(B)&&(n(`Operation cancelled.`),process.exit(0));const V=L?L.databaseProvider:await s({message:`Pick a database provider.`,options:k.databases});i(V)&&(n(`Operation cancelled.`),process.exit(0));let H,U,W;if(V===`supabase`){a.warn(`You must have a Supabase project set up. If you do not have one, please create it at:\n${P.blue(`https://database.new/`)}.`);let{supabaseUrl:e,supabaseKey:t,databaseUrl:n}=await E();(!e||!t||!n)&&(a.error(`Supabase setup failed.`),process.exit(1)),H=e,U=t,W=n}const G=c();e.existsSync(`${N}/nuxt.config.ts`)&&(await r({message:`Nuxt project detected. Do you want to add Pluto environment variables?`})||process.exit(0));const K=A(String(V)),q=K.length===1?K[0]:void 0;q&&!L&&a.info(`Using the only template available: ${q.label}`);const J=L?L.templateChoice:q?.value??await s({message:`Select a template to use. You can add more layers as needed.`,options:K});i(J)&&(n(`Operation cancelled.`),process.exit(0)),e.readdirSync(z).length>0&&(await r({message:`The folder ${P.green(R)} is not empty. Do you want to continue and potentially overwrite existing files?`})||(n(`Operation cancelled.`),process.exit(0))),G.start(`Downloading Pluto template...`);const{source:Y}=await u(`gh:plutocms/pluto-${V}-${J}-template`,{dir:z,force:!0});a.info(`Template downloaded from ${P.green(Y)}`);const X=t.resolve(z,`.env`),Z={};let Q;if(V===`core`?(Z.NUXT_PUBLIC_WEBSITE_NAME=B?.toString()??``,G.stop(`Template downloaded.`),Q=await y(),Object.assign(Z,x(Q).envVars)):Z.WEBSITE_NAME=B?.toString()??``,V===`supabase`){let{envVars:e}=D(H,U,W);Object.assign(Z,e)}try{O(X,Z)}catch(e){a.error(`Failed to write to .env file: ${e}`),process.exit(1)}Q||G.stop(`All done!`),a.success(`Setup complete! 🎉`),a.info(`Nuxt project created in: ${P.green(R)}`),Q&&S(Q);export{};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "create-pluto",
3
3
  "type": "module",
4
- "version": "0.4.0",
4
+ "version": "0.5.0",
5
5
  "description": "CLI Wizard for creating a Pluto App",
6
6
  "author": "https://github.com/ojvribeiro",
7
7
  "license": "MIT",
@@ -35,6 +35,7 @@
35
35
  "scripts": {
36
36
  "setup": "node src/index.ts",
37
37
  "build": "tsdown",
38
+ "prepack": "tsdown",
38
39
  "prettier": "prettier --write .",
39
40
  "lint": "eslint .",
40
41
  "lint:fix": "eslint . --fix",