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 +137 -64
- package/dist/bin/gasup.js +41 -40
- package/dist/bundle.js +6 -4
- package/dist/config.d.ts +2 -5
- package/dist/config.js +3 -7
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/init.d.ts +1 -0
- package/dist/init.js +65 -0
- package/dist/types.d.ts +2 -15
- package/package.json +8 -13
- package/assets/tsconfig.json +0 -8
- package/dist/build.d.ts +0 -2
- package/dist/build.js +0 -7
- package/dist/claspJson.d.ts +0 -2
- package/dist/claspJson.js +0 -7
- package/dist/deploy.d.ts +0 -1
- package/dist/deploy.js +0 -27
- package/dist/envFile/addToEnvString.d.ts +0 -1
- package/dist/envFile/addToEnvString.js +0 -39
- package/dist/envFile/addToEnvString.test.d.ts +0 -1
- package/dist/envFile/addToEnvString.test.js +0 -56
- package/dist/envFile/changeEnv.d.ts +0 -2
- package/dist/envFile/changeEnv.js +0 -24
- package/dist/envFile/envFile.d.ts +0 -3
- package/dist/envFile/envFile.js +0 -25
- package/dist/gitignore.d.ts +0 -1
- package/dist/gitignore.js +0 -18
package/README.md
CHANGED
|
@@ -1,123 +1,196 @@
|
|
|
1
1
|
# Gasup
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A simple CLI tool for bundling Google Apps Script projects with esbuild and the esbuild-gas-plugin.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
- bundling
|
|
7
|
-
- pushing
|
|
8
|
-
- deploying
|
|
9
|
-
- change development, staging, production
|
|
5
|
+
## Features
|
|
10
6
|
|
|
11
|
-
|
|
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
|
-
|
|
14
|
+
Install gasup as a dev dependency:
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
```
|
|
20
|
-
npm i -D gasup
|
|
16
|
+
```bash
|
|
17
|
+
npm install -D gasup
|
|
21
18
|
```
|
|
22
19
|
|
|
23
|
-
##
|
|
20
|
+
## Quick Start
|
|
24
21
|
|
|
25
|
-
|
|
22
|
+
1. **Initialize your project** (creates `gasup.config.ts`):
|
|
23
|
+
```bash
|
|
24
|
+
npx gasup init
|
|
25
|
+
```
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
2. **Bundle your project**:
|
|
28
|
+
```bash
|
|
29
|
+
npx gasup
|
|
30
|
+
```
|
|
28
31
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
3. **Push to Google Apps Script**:
|
|
33
|
+
```bash
|
|
34
|
+
clasp push
|
|
35
|
+
```
|
|
32
36
|
|
|
33
|
-
|
|
37
|
+
## Commands
|
|
34
38
|
|
|
35
|
-
###
|
|
39
|
+
### `gasup`
|
|
40
|
+
Bundles your Google Apps Script project using the current configuration.
|
|
36
41
|
|
|
37
|
-
|
|
42
|
+
```bash
|
|
43
|
+
# Using npx
|
|
44
|
+
npx gasup
|
|
38
45
|
|
|
39
|
-
|
|
40
|
-
gasup
|
|
46
|
+
# Using pnpm
|
|
47
|
+
pnpm gasup
|
|
48
|
+
|
|
49
|
+
# Using yarn
|
|
50
|
+
yarn gasup
|
|
41
51
|
```
|
|
42
52
|
|
|
43
|
-
|
|
53
|
+
### `gasup init`
|
|
54
|
+
Interactive wizard to create a `gasup.config.ts` configuration file.
|
|
44
55
|
|
|
45
|
-
|
|
56
|
+
```bash
|
|
57
|
+
# Using npx
|
|
58
|
+
npx gasup init
|
|
46
59
|
|
|
47
|
-
|
|
60
|
+
# Using pnpm
|
|
61
|
+
pnpm gasup init
|
|
48
62
|
|
|
49
|
-
|
|
50
|
-
gasup
|
|
63
|
+
# Using yarn
|
|
64
|
+
yarn gasup init
|
|
51
65
|
```
|
|
52
66
|
|
|
53
|
-
|
|
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
|
-
|
|
72
|
+
### `gasup config`
|
|
73
|
+
Displays the current configuration.
|
|
56
74
|
|
|
57
|
-
```
|
|
58
|
-
|
|
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
|
-
|
|
86
|
+
## Using npm scripts (Recommended)
|
|
62
87
|
|
|
63
|
-
|
|
88
|
+
Add these scripts to your `package.json` for easier access:
|
|
64
89
|
|
|
65
90
|
```json
|
|
66
91
|
{
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
92
|
+
"scripts": {
|
|
93
|
+
"build": "gasup",
|
|
94
|
+
"init": "gasup init",
|
|
95
|
+
"config": "gasup config"
|
|
70
96
|
}
|
|
71
97
|
}
|
|
72
98
|
```
|
|
73
99
|
|
|
74
|
-
|
|
100
|
+
Then you can run:
|
|
75
101
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
###
|
|
124
|
+
### Configuration Options
|
|
90
125
|
|
|
91
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
175
|
+
### Custom configuration
|
|
176
|
+
```typescript
|
|
102
177
|
// gasup.config.ts
|
|
103
178
|
import { Config } from 'gasup';
|
|
104
179
|
|
|
105
|
-
const config:Config = {
|
|
106
|
-
|
|
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
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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 {
|
|
7
|
-
import { changeEnv } from '../envFile/changeEnv.js';
|
|
4
|
+
import { init } from '../init.js';
|
|
8
5
|
program
|
|
9
|
-
.
|
|
10
|
-
.
|
|
11
|
-
.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
.
|
|
15
|
-
.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
console.log(
|
|
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
|
-
|
|
27
|
-
console.
|
|
28
|
-
|
|
19
|
+
catch (error) {
|
|
20
|
+
console.error('❌ Bundle failed:', error);
|
|
21
|
+
process.exit(1);
|
|
29
22
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
35
|
-
console.
|
|
36
|
-
|
|
32
|
+
catch (error) {
|
|
33
|
+
console.error('❌ Init failed:', error);
|
|
34
|
+
process.exit(1);
|
|
37
35
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
43
|
-
console.
|
|
44
|
-
|
|
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
|
|
3
|
+
import fs from 'fs';
|
|
4
4
|
import path from 'path';
|
|
5
5
|
export async function bundle(config) {
|
|
6
|
-
const {
|
|
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:
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
package/dist/index.js
CHANGED
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
|
-
|
|
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.
|
|
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.
|
|
26
|
-
"
|
|
27
|
-
"esbuild": "
|
|
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/
|
|
35
|
-
"
|
|
36
|
-
"vitest": "^3.
|
|
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",
|
package/assets/tsconfig.json
DELETED
package/dist/build.d.ts
DELETED
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
|
-
}
|
package/dist/claspJson.d.ts
DELETED
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,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
|
-
}
|
package/dist/envFile/envFile.js
DELETED
|
@@ -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
|
-
}
|
package/dist/gitignore.d.ts
DELETED
|
@@ -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
|
-
}
|