create-clasp 0.1.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 (3) hide show
  1. package/README.md +74 -0
  2. package/dist/index.js +45 -0
  3. package/package.json +46 -0
package/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # create-clasp
2
+
3
+ GAS (Google Apps Script) プロジェクトのセットアップを自動化するCLIツール。
4
+
5
+ ## インストール
6
+
7
+ ```bash
8
+ npm install -g create-clasp
9
+ # or
10
+ pnpm add -g create-clasp
11
+ # or
12
+ yarn global add create-clasp
13
+ ```
14
+
15
+ ## 前提条件
16
+
17
+ - Node.js >= 18
18
+ - `@google/clasp` がグローバルインストールされていること
19
+ - `clasp login` 済み
20
+ - Google Apps Script API 有効化済み
21
+
22
+ ## 使い方
23
+
24
+ ### プロジェクト作成
25
+
26
+ ```bash
27
+ # インタラクティブモード
28
+ npx create-clasp init
29
+
30
+ # プロジェクト名を指定
31
+ npx create-clasp init my-project
32
+ ```
33
+
34
+ ### ビルド
35
+
36
+ ```bash
37
+ # プロジェクトディレクトリ内で
38
+ npx create-clasp build
39
+ ```
40
+
41
+ ### プッシュ
42
+
43
+ ```bash
44
+ # ビルド + GASへプッシュ
45
+ npx create-clasp push
46
+ ```
47
+
48
+ ## 生成されるプロジェクト構造
49
+
50
+ ```
51
+ my-project/
52
+ ├── src/
53
+ │ └── index.ts # 初期コード
54
+ ├── dist/ # ビルド出力先
55
+ ├── appsscript.json # GAS設定
56
+ ├── .clasp.json # clasp設定
57
+ ├── .claspignore # push除外設定
58
+ ├── tsconfig.json # TypeScript設定
59
+ ├── package.json # npm scripts
60
+ └── .gitignore # Git除外設定
61
+ ```
62
+
63
+ ## GASプロジェクトタイプ
64
+
65
+ - **Standalone** - 独立したスクリプト
66
+ - **Google Sheets** - スプレッドシートにバインド
67
+ - **Google Docs** - ドキュメントにバインド
68
+ - **Google Forms** - フォームにバインド
69
+ - **Google Slides** - スライドにバインド
70
+ - **Web App** - Webアプリケーション
71
+
72
+ ## ライセンス
73
+
74
+ MIT
package/dist/index.js ADDED
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env node
2
+ import q from"cac";import*as s 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,n){return new Promise((r,o)=>{let i=N(e,t,{cwd:n?.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,n){let r=L(e,t);await a(e,r,{cwd:n})}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
+ "compilerOptions": {
4
+ "target": "ES2019",
5
+ "module": "none",
6
+ "lib": ["ES2019"],
7
+ "rootDir": "src",
8
+ "outDir": "dist",
9
+ "types": ["google-apps-script"],
10
+ "strict": true
11
+ },
12
+ "include": ["src/**/*.ts"]
13
+ }
14
+ `}function P(e){return`{
15
+ "name": "${e}",
16
+ "version": "1.0.0",
17
+ "private": true,
18
+ "scripts": {
19
+ "build": "tsc",
20
+ "push": "NODE_OPTIONS=--openssl-legacy-provider tsc && clasp push"
21
+ }
22
+ }
23
+ `}function x(){return`node_modules/**
24
+ src/**
25
+ *.map
26
+ package.json
27
+ package-lock.json
28
+ pnpm-lock.yaml
29
+ yarn.lock
30
+ tsconfig.json
31
+ `}function h(){return`node_modules/
32
+ dist/
33
+ .env
34
+ *.log
35
+ `}function j(){return`function hello() {
36
+ Logger.log("Hello GAS from TypeScript");
37
+ }
38
+ `}function v(e,t="Asia/Tokyo"){let n={timeZone:t,dependencies:{},exceptionLogging:"STACKDRIVER",runtimeVersion:"V8"};return e==="webapp"&&(n.webapp={executeAs:"USER_DEPLOYING",access:"MYSELF"}),JSON.stringify(n,null,2)+`
39
+ `}function S(){return["typescript","@types/google-apps-script"]}function A(e){let t=e==="npm"?"npm run":e;return`
40
+ Next steps:
41
+ 1. cd into your project directory
42
+ 2. ${t} build # Compile TypeScript
43
+ 3. ${t} push # Push to Google Apps Script
44
+ 4. clasp open # Open in GAS editor
45
+ `}async function b(e){s.intro("create-clasp - GAS Project Setup");let t=await B(e);s.isCancel(t)&&(s.cancel("Operation cancelled."),process.exit(0));let n=await V();s.isCancel(n)&&(s.cancel("Operation cancelled."),process.exit(0));let r=await _();s.isCancel(r)&&(s.cancel("Operation cancelled."),process.exit(0));let o=R(process.cwd(),t);await p(o)&&(s.log.error(`Directory "${t}" already exists.`),process.exit(1));let i=s.spinner();try{i.start("Creating project files..."),await z(o,t,n),i.stop("Project files created."),i.start("Creating GAS project with clasp..."),await W(o,t,n),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."),s.outro("Project created successfully!"),console.log(A(r)),console.log(` cd ${t}`)}catch(d){i.stop("Failed."),d instanceof Error&&s.log.error(d.message),process.exit(1)}}async function B(e){return e||s.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 s.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 s.select({message:"Package manager:",options:[{value:"pnpm",label:"pnpm"},{value:"npm",label:"npm"},{value:"yarn",label:"yarn"}]})}async function z(e,t,n){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(n))}async function W(e,t,n){let r=["create","--title",t,"--rootDir","dist"];n!=="standalone"&&r.push("--type",n),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"),n=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(n)||(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"),n=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(n)||(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();
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "create-clasp",
3
+ "version": "0.1.0",
4
+ "description": "CLI tool for setting up GAS projects with TypeScript",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "bin": {
8
+ "create-clasp": "./dist/index.js"
9
+ },
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "scripts": {
14
+ "build": "tsup",
15
+ "dev": "tsup --watch"
16
+ },
17
+ "keywords": [
18
+ "gas",
19
+ "google-apps-script",
20
+ "clasp",
21
+ "typescript",
22
+ "cli"
23
+ ],
24
+ "author": "",
25
+ "license": "MIT",
26
+ "engines": {
27
+ "node": ">=18"
28
+ },
29
+ "peerDependencies": {
30
+ "@google/clasp": "^2.0.0"
31
+ },
32
+ "peerDependenciesMeta": {
33
+ "@google/clasp": {
34
+ "optional": true
35
+ }
36
+ },
37
+ "dependencies": {
38
+ "@clack/prompts": "^0.11.0",
39
+ "cac": "^6.7.14"
40
+ },
41
+ "devDependencies": {
42
+ "@types/node": "^25.0.9",
43
+ "tsup": "^8.5.1",
44
+ "typescript": "^5.9.3"
45
+ }
46
+ }