create-clasp 0.1.0 → 0.1.1
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/dist/index.js +4 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import q from"cac";import*as
|
|
2
|
+
import q from"cac";import*as n from"@clack/prompts";import{resolve as R}from"path";import{mkdir as T,writeFile as M,access as I}from"fs/promises";import{join as $,dirname as E}from"path";async function O(e){await T(e,{recursive:!0})}async function c(e,t){await O(E(e)),await M(e,t,"utf-8")}async function p(e){try{return await I(e),!0}catch{return!1}}function l(e,...t){return $(e,...t)}import{exec as F,spawn as N}from"child_process";import{promisify as J}from"util";var X=J(F);function a(e,t,s){return new Promise((r,o)=>{let i=N(e,t,{cwd:s?.cwd,stdio:"inherit",shell:!0});i.on("close",d=>{d===0?r():o(new Error(`Command failed with exit code ${d}`))}),i.on("error",o)})}async function f(e,t){await a(e,["install"],{cwd:t})}async function y(e,t,s){let r=L(e,t);await a(e,r,{cwd:s})}function L(e,t){switch(e){case"pnpm":return["add","-D",...t];case"npm":return["install","-D",...t];case"yarn":return["add","-D",...t]}}function w(){return`{
|
|
3
3
|
"compilerOptions": {
|
|
4
4
|
"target": "ES2019",
|
|
5
5
|
"module": "none",
|
|
@@ -17,6 +17,7 @@ import q from"cac";import*as s from"@clack/prompts";import{resolve as R}from"pat
|
|
|
17
17
|
"private": true,
|
|
18
18
|
"scripts": {
|
|
19
19
|
"build": "tsc",
|
|
20
|
+
"open": "clasp open",
|
|
20
21
|
"push": "NODE_OPTIONS=--openssl-legacy-provider tsc && clasp push"
|
|
21
22
|
}
|
|
22
23
|
}
|
|
@@ -35,11 +36,11 @@ dist/
|
|
|
35
36
|
`}function j(){return`function hello() {
|
|
36
37
|
Logger.log("Hello GAS from TypeScript");
|
|
37
38
|
}
|
|
38
|
-
`}function v(e,t="Asia/Tokyo"){let
|
|
39
|
+
`}function v(e,t="Asia/Tokyo"){let s={timeZone:t,dependencies:{},exceptionLogging:"STACKDRIVER",runtimeVersion:"V8"};return e==="webapp"&&(s.webapp={executeAs:"USER_DEPLOYING",access:"MYSELF"}),JSON.stringify(s,null,2)+`
|
|
39
40
|
`}function S(){return["typescript","@types/google-apps-script"]}function A(e){let t=e==="npm"?"npm run":e;return`
|
|
40
41
|
Next steps:
|
|
41
42
|
1. cd into your project directory
|
|
42
43
|
2. ${t} build # Compile TypeScript
|
|
43
44
|
3. ${t} push # Push to Google Apps Script
|
|
44
45
|
4. clasp open # Open in GAS editor
|
|
45
|
-
`}async function b(e){
|
|
46
|
+
`}async function b(e){n.intro("create-clasp - GAS Project Setup");let t=await B(e);n.isCancel(t)&&(n.cancel("Operation cancelled."),process.exit(0));let s=await V();n.isCancel(s)&&(n.cancel("Operation cancelled."),process.exit(0));let r=await _();n.isCancel(r)&&(n.cancel("Operation cancelled."),process.exit(0));let o=R(process.cwd(),t);await p(o)&&(n.log.error(`Directory "${t}" already exists.`),process.exit(1));let i=n.spinner();try{i.start("Creating project files..."),await z(o,t,s),i.stop("Project files created."),i.start("Creating GAS project with clasp..."),await W(o,t,s),i.stop("GAS project created."),i.start(`Initializing ${r}...`),await Y(r,o),i.stop(`${r} initialized.`),i.start("Installing dependencies..."),await f(r,o),await y(r,S(),o),i.stop("Dependencies installed."),n.outro("Project created successfully!"),console.log(A(r)),console.log(` cd ${t}`)}catch(d){i.stop("Failed."),d instanceof Error&&n.log.error(d.message),process.exit(1)}}async function B(e){return e||n.text({message:"Project name:",placeholder:"my-gas-project",validate:t=>{if(!t)return"Project name is required.";if(!/^[a-z0-9-]+$/.test(t))return"Project name can only contain lowercase letters, numbers, and hyphens."}})}async function V(){return n.select({message:"GAS project type:",options:[{value:"standalone",label:"Standalone"},{value:"sheets",label:"Google Sheets"},{value:"docs",label:"Google Docs"},{value:"forms",label:"Google Forms"},{value:"slides",label:"Google Slides"},{value:"webapp",label:"Web App"}]})}async function _(){return n.select({message:"Package manager:",options:[{value:"pnpm",label:"pnpm"},{value:"npm",label:"npm"},{value:"yarn",label:"yarn"}]})}async function z(e,t,s){await c(l(e,"tsconfig.json"),w()),await c(l(e,"package.json"),P(t)),await c(l(e,".claspignore"),x()),await c(l(e,".gitignore"),h()),await c(l(e,"src","index.ts"),j()),await c(l(e,"dist",".gitkeep"),""),await c(l(e,"dist","appsscript.json"),v(s))}async function W(e,t,s){let r=["create","--title",t,"--rootDir","dist"];s!=="standalone"&&r.push("--type",s),await a("clasp",r,{cwd:e})}async function Y(e,t){}import*as m from"@clack/prompts";import{resolve as k}from"path";async function G(){let e=process.cwd(),t=k(e,"tsconfig.json"),s=k(e,"src");await p(t)||(m.log.error("tsconfig.json not found. Are you in a create-clasp project directory?"),process.exit(1)),await p(s)||(m.log.error("src directory not found. Are you in a create-clasp project directory?"),process.exit(1));let r=m.spinner();try{r.start("Compiling TypeScript..."),await a("npx",["tsc"],{cwd:e}),r.stop("Build completed.")}catch(o){r.stop("Build failed."),o instanceof Error&&m.log.error(o.message),process.exit(1)}}import*as g from"@clack/prompts";import{resolve as D}from"path";async function C(){let e=process.cwd(),t=D(e,".clasp.json"),s=D(e,"tsconfig.json");await p(t)||(g.log.error(".clasp.json not found. Are you in a create-clasp project directory?"),process.exit(1)),await p(s)||(g.log.error("tsconfig.json not found. Are you in a create-clasp project directory?"),process.exit(1));let r=g.spinner();try{r.start("Compiling TypeScript..."),await a("npx",["tsc"],{cwd:e}),r.stop("Build completed."),r.start("Pushing to Google Apps Script..."),await a("clasp",["push"],{cwd:e}),r.stop("Push completed."),g.log.success("Successfully pushed to Google Apps Script!")}catch(o){r.stop("Failed."),o instanceof Error&&g.log.error(o.message),process.exit(1)}}var u=q("create-clasp");u.command("init [project-name]","Create a new GAS project with TypeScript").action(b);u.command("build","Compile TypeScript to JavaScript").action(G);u.command("push","Build and push to Google Apps Script").action(C);u.help();u.version("0.1.0");u.parse();
|