gasup 0.4.4 → 1.0.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,123 +1,196 @@
1
1
  # Gasup
2
2
 
3
- Gasup is a command-line interface (CLI) tool designed to simplify the process.
3
+ A simple CLI tool for bundling Google Apps Script projects with esbuild and the esbuild-gas-plugin.
4
4
 
5
- - building
6
- - bundling
7
- - pushing
8
- - deploying
9
- - change development, staging, production
5
+ ## Features
10
6
 
11
- It offers an easy way to automate tasks and manage your deployments without the need to manually interact with the Apps Script dashboard.
7
+ - **Simple bundling**: Bundle your TypeScript/JavaScript code into a single file optimized for Google Apps Script
8
+ - **Easy configuration**: Interactive wizard to create configuration files
9
+ - **esbuild-gas-plugin integration**: Automatically handles GAS-specific optimizations
10
+ - **File management**: Automatically copies `appsscript.json` and HTML files to the output directory
12
11
 
13
12
  ## Installation
14
13
 
15
- To get started with gasup, you need clasp first.
14
+ Install gasup as a dev dependency:
16
15
 
17
- Then you can install gasup like below.
18
-
19
- ```
20
- npm i -D gasup
16
+ ```bash
17
+ npm install -D gasup
21
18
  ```
22
19
 
23
- ## Usage
20
+ ## Quick Start
24
21
 
25
- ### Build
22
+ 1. **Initialize your project** (creates `gasup.config.ts`):
23
+ ```bash
24
+ npx gasup init
25
+ ```
26
26
 
27
- Simple build.
27
+ 2. **Bundle your project**:
28
+ ```bash
29
+ npx gasup
30
+ ```
28
31
 
29
- ```
30
- gasup --build
31
- ```
32
+ 3. **Push to Google Apps Script**:
33
+ ```bash
34
+ clasp push
35
+ ```
32
36
 
33
- This command compiles your code with tsc.
37
+ ## Commands
34
38
 
35
- ### Bundle
39
+ ### `gasup`
40
+ Bundles your Google Apps Script project using the current configuration.
36
41
 
37
- Bundle with esbuild into one file.
42
+ ```bash
43
+ # Using npx
44
+ npx gasup
38
45
 
39
- ```
40
- gasup --bundle
46
+ # Using pnpm
47
+ pnpm gasup
48
+
49
+ # Using yarn
50
+ yarn gasup
41
51
  ```
42
52
 
43
- This allows you to use libraries that are not natively available in Google Apps Script.
53
+ ### `gasup init`
54
+ Interactive wizard to create a `gasup.config.ts` configuration file.
44
55
 
45
- ### Push
56
+ ```bash
57
+ # Using npx
58
+ npx gasup init
46
59
 
47
- Simply push using "clasp push".
60
+ # Using pnpm
61
+ pnpm gasup init
48
62
 
49
- ```
50
- gasup --push
63
+ # Using yarn
64
+ yarn gasup init
51
65
  ```
52
66
 
53
- ### Deploy
67
+ The wizard will ask for:
68
+ - Entry point (default: `src/index.ts`)
69
+ - Output file (default: `dist/bundle.js`)
70
+ - appsscript.json path (default: `appsscript.json`)
54
71
 
55
- Deploy to the latest deployment. If no previous deployments exist, a new deployment will be created.
72
+ ### `gasup config`
73
+ Displays the current configuration.
56
74
 
57
- ```
58
- gasup --deploy
75
+ ```bash
76
+ # Using npx
77
+ npx gasup config
78
+
79
+ # Using pnpm
80
+ pnpm gasup config
81
+
82
+ # Using yarn
83
+ yarn gasup config
59
84
  ```
60
85
 
61
- appsscript.json affects deployment. Be sure to check your appsscript.json.
86
+ ## Using npm scripts (Recommended)
62
87
 
63
- If you want to deploy webapp, appsscript is like below.
88
+ Add these scripts to your `package.json` for easier access:
64
89
 
65
90
  ```json
66
91
  {
67
- "webapp": {
68
- "executeAs": "USER_DEPLOYING",
69
- "access": "ANYONE_ANONYMOUS"
92
+ "scripts": {
93
+ "build": "gasup",
94
+ "init": "gasup init",
95
+ "config": "gasup config"
70
96
  }
71
97
  }
72
98
  ```
73
99
 
74
- ### Change Environment
100
+ Then you can run:
75
101
 
76
- If you need to switch between different environments (e.g., development, staging, production), you can use the --env flag to modify the appsscript.json file accordingly.
77
-
78
- ```
79
- gasup --env <envpath>
102
+ ```bash
103
+ npm run init # Initialize configuration
104
+ npm run build # Bundle your project
105
+ npm run config # Show configuration
80
106
  ```
81
107
 
82
- Environment file details:
108
+ ## Configuration
109
+
110
+ Create a `gasup.config.ts` file in your project root:
111
+
112
+ ```typescript
113
+ import { Config } from 'gasup';
83
114
 
84
- ```env
85
- GASUP_SCRIPT_ID=xxx
86
- GASUP_PARENT_ID=yyy,zzz
115
+ const config: Config = {
116
+ entryPoint: 'src/index.ts',
117
+ outputFile: 'dist/bundle.js',
118
+ appsScriptJsonPath: 'appsscript.json',
119
+ };
120
+
121
+ export default config;
87
122
  ```
88
123
 
89
- ### Chain
124
+ ### Configuration Options
90
125
 
91
- Chan command is available like below.
126
+ | Option | Type | Default | Description |
127
+ |--------|------|---------|-------------|
128
+ | `entryPoint` | `string` | `'src/index.ts'` | Path to your main TypeScript/JavaScript file |
129
+ | `outputFile` | `string` | `'dist/bundle.js'` | Path for the bundled output file |
130
+ | `appsScriptJsonPath` | `string` | `'appsscript.json'` | Path to your appsscript.json file |
131
+
132
+ ## Project Structure
92
133
 
93
134
  ```
94
- gasup --env .env.production --bundle --push --deploy
135
+ your-project/
136
+ ├── src/
137
+ │ └── index.ts # Your main entry point
138
+ ├── dist/
139
+ │ ├── bundle.js # Bundled output (auto-generated)
140
+ │ └── appsscript.json # Copied from root (auto-generated)
141
+ ├── appsscript.json # Google Apps Script configuration
142
+ ├── gasup.config.ts # Gasup configuration (optional)
143
+ └── package.json
95
144
  ```
96
145
 
97
- ### Config
146
+ ## How it works
147
+
148
+ 1. **Bundling**: Uses esbuild with the esbuild-gas-plugin to bundle your code
149
+ 2. **Optimization**: Automatically applies Google Apps Script-specific optimizations
150
+ 3. **File copying**: Copies `appsscript.json` and any HTML files to the output directory
151
+ 4. **Ready for deployment**: The bundled file is ready to be pushed to Google Apps Script
152
+
153
+ ## Examples
154
+
155
+ ### Basic usage
156
+ ```bash
157
+ # Initialize configuration
158
+ npx gasup init
159
+
160
+ # Bundle your project
161
+ npx gasup
98
162
 
99
- The config file will below.
163
+ # Push to Google Apps Script
164
+ clasp push
165
+ ```
166
+
167
+ ### Using npm scripts
168
+ ```bash
169
+ # Add to package.json scripts
170
+ npm run init
171
+ npm run build
172
+ clasp push
173
+ ```
100
174
 
101
- ```ts
175
+ ### Custom configuration
176
+ ```typescript
102
177
  // gasup.config.ts
103
178
  import { Config } from 'gasup';
104
179
 
105
- const config:Config = {
106
- srcDir: './src';
107
- }
180
+ const config: Config = {
181
+ entryPoint: 'src/main.ts',
182
+ outputFile: 'build/script.js',
183
+ appsScriptJsonPath: 'gas/appsscript.json',
184
+ };
108
185
 
109
186
  export default config;
110
187
  ```
111
188
 
112
- ```ts
113
- export interface Config {
114
- appsScriptJsonPath?: string;
115
- bundleEntries?: string[];
116
- bundleOutfile?: string;
117
- srcDir?: string;
118
- distDir?: string;
119
- }
120
- ```
189
+ ## Requirements
190
+
191
+ - Node.js 18+
192
+ - Google Apps Script project set up with clasp
193
+ - TypeScript or JavaScript source files
121
194
 
122
195
  ## License
123
196
 
package/dist/bin/gasup.js CHANGED
@@ -1,51 +1,52 @@
1
- import { execSync } from 'child_process';
2
1
  import { program } from 'commander';
3
- import { build } from '../build.js';
4
2
  import { bundle } from '../bundle.js';
5
3
  import { loadConfigWithDefault } from '../config.js';
6
- import { deploy } from '../deploy.js';
7
- import { changeEnv } from '../envFile/changeEnv.js';
4
+ import { init } from '../init.js';
8
5
  program
9
- .option('--config', 'display current configuration')
10
- .option('--env <envpath>', 'apply env to clasp')
11
- .option('--bundle', 'bundle')
12
- .option('--build', 'build')
13
- .option('--push', 'push')
14
- .option('--deploy', 'deploy')
15
- .parse();
16
- async function main() {
17
- const opts = program.opts();
18
- const config = await loadConfigWithDefault();
19
- if (opts.config) {
20
- console.log({ config });
21
- return;
22
- }
23
- if (opts.env?.startsWith('--')) {
24
- throw new Error('env option is required');
6
+ .name('gasup')
7
+ .description('CLI tool for Google Apps Script bundling')
8
+ .version('0.4.4');
9
+ // Main command (bundle execution)
10
+ program
11
+ .description('Bundle your Google Apps Script project')
12
+ .action(async () => {
13
+ try {
14
+ const config = await loadConfigWithDefault();
15
+ console.log('📦 Bundling with esbuild...');
16
+ await bundle(config);
17
+ console.log('✅ Bundle completed');
25
18
  }
26
- if (opts.env) {
27
- console.log(`apply ${opts.env} to clasp`);
28
- changeEnv(opts.env, config);
19
+ catch (error) {
20
+ console.error('❌ Bundle failed:', error);
21
+ process.exit(1);
29
22
  }
30
- if (opts.build) {
31
- console.log('build with tsc');
32
- build(config);
23
+ });
24
+ // init subcommand
25
+ program
26
+ .command('init')
27
+ .description('Initialize gasup configuration file')
28
+ .action(async () => {
29
+ try {
30
+ await init();
33
31
  }
34
- if (opts.bundle) {
35
- console.log('bundle with esbuild');
36
- await bundle(config);
32
+ catch (error) {
33
+ console.error(' Init failed:', error);
34
+ process.exit(1);
37
35
  }
38
- if (opts.push) {
39
- console.log('push');
40
- execSync('clasp push', { stdio: 'inherit' });
36
+ });
37
+ // config subcommand
38
+ program
39
+ .command('config')
40
+ .description('Display current configuration')
41
+ .action(async () => {
42
+ try {
43
+ const config = await loadConfigWithDefault();
44
+ console.log('📋 Current configuration:');
45
+ console.log(JSON.stringify(config, null, 2));
41
46
  }
42
- if (opts.deploy) {
43
- console.log(`deploy`);
44
- deploy();
47
+ catch (error) {
48
+ console.error('❌ Config display failed:', error);
49
+ process.exit(1);
45
50
  }
46
- console.log('gasup done');
47
- }
48
- main().catch((err) => {
49
- console.error(err.message);
50
- process.exit(1);
51
51
  });
52
+ program.parse();
package/dist/bundle.js CHANGED
@@ -1,17 +1,19 @@
1
1
  import esbuild from 'esbuild';
2
2
  import { GasPlugin } from 'esbuild-gas-plugin';
3
- import fs from 'fs-extra';
3
+ import fs from 'fs';
4
4
  import path from 'path';
5
5
  export async function bundle(config) {
6
- const { bundleEntries, bundleOutfile, appsScriptJsonPath, distDir } = config;
6
+ const { appsScriptJsonPath, entryPoint, outputFile } = config;
7
+ const bundleEntries = [entryPoint];
7
8
  await esbuild.build({
8
9
  entryPoints: bundleEntries,
9
10
  bundle: true,
10
- outfile: bundleOutfile,
11
+ outfile: outputFile,
11
12
  plugins: [GasPlugin],
12
13
  });
14
+ const distDir = path.dirname(outputFile);
13
15
  fs.copyFileSync(appsScriptJsonPath, path.join(distDir, 'appsscript.json'));
14
- // HTMLファイルをdistディレクトリにコピー
16
+ // Copy HTML files to dist directory
15
17
  for (const bundleEntry of bundleEntries) {
16
18
  const entryDir = path.dirname(bundleEntry);
17
19
  const htmlFiles = fs.readdirSync(entryDir).filter(file => file.endsWith('.html'));
package/dist/config.d.ts CHANGED
@@ -1,10 +1,7 @@
1
1
  import { Config } from './types.js';
2
2
  export declare const defaultConfig: Config;
3
3
  export declare function loadConfigWithDefault(): Promise<{
4
- claspJsonPath?: string;
4
+ entryPoint?: string;
5
+ outputFile?: string;
5
6
  appsScriptJsonPath?: string;
6
- bundleEntries?: string[];
7
- bundleOutfile?: string;
8
- srcDir?: string;
9
- distDir?: string;
10
7
  }>;
package/dist/config.js CHANGED
@@ -1,16 +1,12 @@
1
- import fs from 'fs-extra';
1
+ import fs from 'fs';
2
2
  import path from 'path';
3
3
  import tsnode from 'ts-node';
4
4
  const configFileName = 'gasup.config.ts';
5
5
  export const defaultConfig = {
6
- claspJsonPath: '.clasp.json',
6
+ entryPoint: 'src/index.ts',
7
+ outputFile: 'dist/bundle.js',
7
8
  appsScriptJsonPath: 'appsscript.json',
8
- bundleEntries: [path.join('src', 'index.ts')],
9
- bundleOutfile: path.join('dist', 'bundle.js'),
10
- srcDir: 'src',
11
- distDir: 'dist',
12
9
  };
13
- // export const config = loadConfigWithDefault();
14
10
  export async function loadConfigWithDefault() {
15
11
  const configPath = path.join(process.cwd(), configFileName);
16
12
  const config = await loadConfig(configPath);
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export * from './bundle.js';
2
- export * from './envFile/changeEnv.js';
3
2
  export * from './config.js';
4
3
  export * from './types.js';
4
+ export * from './init.js';
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  export * from './bundle.js';
2
- export * from './envFile/changeEnv.js';
3
2
  export * from './config.js';
4
3
  export * from './types.js';
4
+ export * from './init.js';
package/dist/init.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function init(): Promise<void>;
package/dist/init.js ADDED
@@ -0,0 +1,65 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import readline from 'readline';
4
+ const defaultConfig = {
5
+ entryPoint: 'src/index.ts',
6
+ outputFile: 'dist/bundle.js',
7
+ appsScriptJsonPath: 'appsscript.json',
8
+ };
9
+ export async function init() {
10
+ console.log('🚀 Gasup Configuration Wizard');
11
+ console.log('');
12
+ const rl = readline.createInterface({
13
+ input: process.stdin,
14
+ output: process.stdout,
15
+ });
16
+ const question = (query) => {
17
+ return new Promise((resolve) => {
18
+ rl.question(query, resolve);
19
+ });
20
+ };
21
+ try {
22
+ // Entry point
23
+ const entryPoint = await question(`Entry point (default: ${defaultConfig.entryPoint}): `);
24
+ // Output file
25
+ const outputFile = await question(`Output file (default: ${defaultConfig.outputFile}): `);
26
+ // appsscript.json path
27
+ const appsScriptJsonPath = await question(`appsscript.json path (default: ${defaultConfig.appsScriptJsonPath}): `);
28
+ rl.close();
29
+ // Create config object
30
+ const config = {
31
+ entryPoint: entryPoint || defaultConfig.entryPoint,
32
+ outputFile: outputFile || defaultConfig.outputFile,
33
+ appsScriptJsonPath: appsScriptJsonPath || defaultConfig.appsScriptJsonPath,
34
+ };
35
+ // Generate config file content
36
+ const configContent = generateConfigFile(config);
37
+ // Write to file
38
+ const configPath = path.join(process.cwd(), 'gasup.config.ts');
39
+ fs.writeFileSync(configPath, configContent);
40
+ console.log('');
41
+ console.log('✅ Configuration file created: gasup.config.ts');
42
+ console.log('');
43
+ console.log('Configuration:');
44
+ console.log(JSON.stringify(config, null, 2));
45
+ console.log('');
46
+ console.log('You can now run `gasup` to bundle your project.');
47
+ }
48
+ catch (error) {
49
+ rl.close();
50
+ console.error('❌ Failed to create configuration file:', error);
51
+ process.exit(1);
52
+ }
53
+ }
54
+ function generateConfigFile(config) {
55
+ return `import { Config } from 'gasup';
56
+
57
+ const config: Config = {
58
+ entryPoint: '${config.entryPoint}',
59
+ outputFile: '${config.outputFile}',
60
+ appsScriptJsonPath: '${config.appsScriptJsonPath}',
61
+ };
62
+
63
+ export default config;
64
+ `;
65
+ }
package/dist/types.d.ts CHANGED
@@ -1,18 +1,5 @@
1
- export type Env = 'dev' | 'stag' | 'prod';
2
1
  export interface Config {
3
- claspJsonPath?: string;
2
+ entryPoint?: string;
3
+ outputFile?: string;
4
4
  appsScriptJsonPath?: string;
5
- bundleEntries?: string[];
6
- bundleOutfile?: string;
7
- srcDir?: string;
8
- distDir?: string;
9
- }
10
- export interface EnvObject {
11
- GASUP_SCRIPT_ID?: string;
12
- GASUP_PARENT_ID?: string[];
13
- }
14
- export interface ClaspJson {
15
- scriptId?: string;
16
- rootDir?: string;
17
- parentId?: string[];
18
5
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gasup",
3
- "version": "0.4.4",
3
+ "version": "1.0.0",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -12,8 +12,7 @@
12
12
  "main": "./dist/index.js",
13
13
  "types": "./dist/index.d.ts",
14
14
  "files": [
15
- "dist",
16
- "assets"
15
+ "dist"
17
16
  ],
18
17
  "keywords": [
19
18
  "gas",
@@ -22,18 +21,14 @@
22
21
  "google apps script"
23
22
  ],
24
23
  "dependencies": {
25
- "commander": "^13.0.0",
26
- "dotenv": "^16.4.7",
27
- "esbuild": ">=0.25.0",
28
- "esbuild-gas-plugin": "^0.8.0",
29
- "fs-extra": "^11.3.0",
30
- "remeda": "^2.19.2",
31
- "ts-node": "^10.9.2"
24
+ "commander": "^13.1.0",
25
+ "esbuild": "^0.25.5",
26
+ "esbuild-gas-plugin": "^0.9.0"
32
27
  },
33
28
  "devDependencies": {
34
- "@types/fs-extra": "^11.0.4",
35
- "@types/node": "^22.10.7",
36
- "vitest": "^3.0.5"
29
+ "@types/node": "^22.15.30",
30
+ "ts-node": "^10.9.2",
31
+ "vitest": "^3.2.2"
37
32
  },
38
33
  "scripts": {
39
34
  "build": "tsc",
@@ -1,8 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "lib": [
5
- "ES2020"
6
- ],
7
- }
8
- }
package/dist/build.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import { Config } from './types.js';
2
- export declare function build(config: Config): void;
package/dist/build.js DELETED
@@ -1,7 +0,0 @@
1
- import { execSync } from 'child_process';
2
- import { copyFileSync } from 'fs';
3
- import path from 'path';
4
- export function build(config) {
5
- execSync('tsc', { stdio: 'inherit' });
6
- copyFileSync(config.appsScriptJsonPath, path.join(config.distDir, 'appsscript.json'));
7
- }
@@ -1,2 +0,0 @@
1
- import { ClaspJson } from './types.js';
2
- export declare function updateClaspJson(claspJsonPath: string, data: ClaspJson): void;
package/dist/claspJson.js DELETED
@@ -1,7 +0,0 @@
1
- import fs from 'fs-extra';
2
- export function updateClaspJson(claspJsonPath, data) {
3
- const json = fs.readFileSync(claspJsonPath, 'utf-8');
4
- const existingData = JSON.parse(json ?? '{}');
5
- const newData = { ...existingData, ...data };
6
- fs.writeFileSync(claspJsonPath, JSON.stringify(newData, null, 2));
7
- }
package/dist/deploy.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare function deploy(): void;
package/dist/deploy.js DELETED
@@ -1,27 +0,0 @@
1
- import { execSync } from 'child_process';
2
- export function deploy() {
3
- const currentDeployments = getCurrentDeployments();
4
- const latestDeployment = currentDeployments[0];
5
- if (latestDeployment) {
6
- console.log('deploy to latest: ' +
7
- latestDeployment.id +
8
- ' ' +
9
- latestDeployment.version);
10
- execSync('clasp deploy -i ' + latestDeployment.id);
11
- }
12
- else {
13
- console.log('deploy new version');
14
- execSync('clasp deploy');
15
- }
16
- }
17
- function getCurrentDeployments() {
18
- const res = execSync('clasp deployments').toString();
19
- const lines = res.split('\n');
20
- const deployments = lines
21
- .filter((line) => line.startsWith('-'))
22
- .map((line) => {
23
- const [_, id, versionStr] = line.split(' ');
24
- return { id, version: Number(versionStr.replace(/[^\d]/g, '')) };
25
- });
26
- return deployments.sort((a, b) => b.version - a.version);
27
- }
@@ -1 +0,0 @@
1
- export declare function addToEnvString(envString: string, _items: Record<string, string>): string;
@@ -1,39 +0,0 @@
1
- // 環境変数を変更する
2
- export function addToEnvString(envString, _items) {
3
- const items = { ..._items };
4
- const newLines = [];
5
- for (const line of envString.split('\n')) {
6
- if (isCommentLine(line)) {
7
- newLines.push(line);
8
- }
9
- else {
10
- const { key, value } = parseLine(line);
11
- if (key) {
12
- if (items[key]) {
13
- newLines.push(`${key}=${items[key]}`);
14
- delete items[key];
15
- }
16
- else {
17
- newLines.push(`${key}=${value}`);
18
- }
19
- }
20
- else {
21
- newLines.push('');
22
- }
23
- }
24
- }
25
- newLines.push('');
26
- for (const [key, value] of Object.entries(items)) {
27
- if (!key)
28
- continue;
29
- newLines.push(`${key}=${value}`);
30
- }
31
- return newLines.join('\n');
32
- }
33
- function isCommentLine(line) {
34
- return line.startsWith('#');
35
- }
36
- function parseLine(line) {
37
- const [key, ...values] = line.split('=');
38
- return { key, value: values.join('=') };
39
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,56 +0,0 @@
1
- import { addToEnvString } from './addToEnvString.js';
2
- import { describe, it, expect } from 'vitest';
3
- describe('addToEnvString', () => {
4
- const mockEnvString = `
5
- # This is a comment
6
- KEY1=value1
7
- KEY2=value2
8
- `.trim();
9
- it('should add new keys to the env string and overwrite existing ones', () => {
10
- const itemsToAdd = {
11
- KEY3: 'value3',
12
- KEY1: 'newValue1', // 既存のKEY1を上書きしない
13
- };
14
- const result = addToEnvString(mockEnvString, itemsToAdd);
15
- // 新しい環境変数を含んだ結果を確認
16
- const expectedContent = `
17
- # This is a comment
18
- KEY1=value1
19
- KEY2=value2
20
-
21
- KEY3=value3
22
- `.trim();
23
- console.log({ mockEnvString, result, expectedContent });
24
- expect(result).toBe(expectedContent);
25
- });
26
- it('should add only new keys if not already in the string', () => {
27
- const itemsToAdd = {
28
- KEY3: 'value3',
29
- KEY4: 'value4',
30
- };
31
- const result = addToEnvString(mockEnvString, itemsToAdd);
32
- // 新しい環境変数を含んだ結果を確認
33
- const expectedContent = `
34
- # This is a comment
35
- KEY1=value1
36
- KEY2=value2
37
-
38
- KEY3=value3
39
- KEY4=value4
40
- `.trim();
41
- expect(result).toBe(expectedContent);
42
- });
43
- it('should handle an empty env string', () => {
44
- const itemsToAdd = {
45
- KEY1: 'value1',
46
- KEY2: 'value2',
47
- };
48
- const result = addToEnvString('', itemsToAdd);
49
- // 空の環境変数文字列に対して追加された内容を確認
50
- const expectedContent = `
51
- KEY1=value1
52
- KEY2=value2
53
- `.trim();
54
- expect(result.trim()).toBe(expectedContent);
55
- });
56
- });
@@ -1,2 +0,0 @@
1
- import { Config } from '../types.js';
2
- export declare function changeEnv(envPath: string, config: Config): void;
@@ -1,24 +0,0 @@
1
- import fs from 'fs-extra';
2
- import { updateClaspJson } from '../claspJson.js';
3
- import { getEnvData } from './envFile.js';
4
- export function changeEnv(envPath, config) {
5
- if (!envPath) {
6
- throw new Error(`envPath not found on ${envPath}`);
7
- }
8
- if (!fs.existsSync(envPath)) {
9
- throw new Error(`${envPath} not found`);
10
- }
11
- const envData = getEnvData(envPath);
12
- const scriptId = envData.GASUP_SCRIPT_ID;
13
- const parentIds = envData.GASUP_PARENT_ID;
14
- if (!scriptId) {
15
- throw new Error(`GASUP_SCRIPT_ID not found on ${envPath}`);
16
- }
17
- if (!parentIds) {
18
- throw new Error(`GASUP_PARENT_ID not found on ${envPath}`);
19
- }
20
- updateClaspJson(config.claspJsonPath, {
21
- scriptId,
22
- parentId: parentIds,
23
- });
24
- }
@@ -1,3 +0,0 @@
1
- import { EnvObject } from '../types.js';
2
- export declare function getEnvData(envPath: string): EnvObject;
3
- export declare function addToEnvFile(envPath: string, _items: Record<string, string>): void;
@@ -1,25 +0,0 @@
1
- import dotenv from 'dotenv';
2
- import fs from 'fs-extra';
3
- import { addToEnvString } from './addToEnvString.js';
4
- export function getEnvData(envPath) {
5
- try {
6
- const envString = fs.readFileSync(envPath, 'utf-8');
7
- const data = dotenv.parse(envString);
8
- return {
9
- GASUP_SCRIPT_ID: data.GASUP_SCRIPT_ID,
10
- GASUP_PARENT_ID: data.GASUP_PARENT_ID?.split(','),
11
- };
12
- }
13
- catch (err) {
14
- return {};
15
- }
16
- }
17
- export function addToEnvFile(envPath, _items) {
18
- let envString = '';
19
- try {
20
- envString = fs.readFileSync(envPath, 'utf-8');
21
- }
22
- catch (e) { }
23
- const newEnvString = addToEnvString(envString.trim(), _items);
24
- fs.writeFileSync(envPath, newEnvString);
25
- }
@@ -1 +0,0 @@
1
- export declare function addGitIgnores(): void;
package/dist/gitignore.js DELETED
@@ -1,18 +0,0 @@
1
- import path from 'path';
2
- import fs from 'fs-extra';
3
- import * as R from 'remeda';
4
- export function addGitIgnores() {
5
- const filePath = path.join(process.cwd(), '.gitignore');
6
- const existsIgnores = read(filePath);
7
- const ignores = ['node_modules', '.DS_Store', '.env*', '.clasp.json'];
8
- const newIgnores = R.unique([...existsIgnores, ...ignores]);
9
- fs.writeFileSync(filePath, newIgnores.join('\n'));
10
- }
11
- function read(filePath) {
12
- try {
13
- return fs.readFileSync(filePath).toString().split('\n');
14
- }
15
- catch (err) {
16
- return [];
17
- }
18
- }