gasup 1.0.1 → 1.0.3

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
@@ -5,10 +5,23 @@ A simple CLI tool for bundling Google Apps Script projects with esbuild and the
5
5
  ## Features
6
6
 
7
7
  - **Simple bundling**: Bundle your TypeScript/JavaScript code into a single file optimized for Google Apps Script
8
+ - **Watch mode**: Automatically rebuild when files change during development
8
9
  - **Easy configuration**: Interactive wizard to create configuration files
9
10
  - **esbuild-gas-plugin integration**: Automatically handles GAS-specific optimizations
10
11
  - **File management**: Automatically copies `appsscript.json` and HTML files to the output directory
11
12
 
13
+ ## Making Functions Available in Google Apps Script
14
+
15
+ To make your functions executable in Google Apps Script, you need to expose them globally. Functions that are not exposed globally cannot be called from the GAS interface or triggers.
16
+
17
+ ```typescript
18
+ // src/index.ts
19
+
20
+ (global as any).helloWorld = () => {
21
+ console.log('Hello world!');
22
+ }
23
+ ```
24
+
12
25
  ## Installation
13
26
 
14
27
  Install gasup as a dev dependency:
@@ -50,6 +63,20 @@ pnpm gasup
50
63
  yarn gasup
51
64
  ```
52
65
 
66
+ ### `gasup --watch`
67
+ Watches for file changes and automatically rebuilds your project.
68
+
69
+ ```bash
70
+ # Using npx
71
+ npx gasup --watch
72
+
73
+ # Using pnpm
74
+ pnpm gasup --watch
75
+
76
+ # Using yarn
77
+ yarn gasup --watch
78
+ ```
79
+
53
80
  ### `gasup init`
54
81
  Interactive wizard to create a `gasup.config.ts` configuration file.
55
82
 
@@ -91,6 +118,7 @@ Add these scripts to your `package.json` for easier access:
91
118
  {
92
119
  "scripts": {
93
120
  "build": "gasup",
121
+ "dev": "gasup --watch",
94
122
  "init": "gasup init",
95
123
  "config": "gasup config"
96
124
  }
@@ -102,6 +130,7 @@ Then you can run:
102
130
  ```bash
103
131
  npm run init # Initialize configuration
104
132
  npm run build # Bundle your project
133
+ npm run dev # Watch mode for development
105
134
  npm run config # Show configuration
106
135
  ```
107
136
 
@@ -148,7 +177,8 @@ your-project/
148
177
  1. **Bundling**: Uses esbuild with the esbuild-gas-plugin to bundle your code
149
178
  2. **Optimization**: Automatically applies Google Apps Script-specific optimizations
150
179
  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
180
+ 4. **Watch mode**: Monitors file changes and automatically rebuilds when needed
181
+ 5. **Ready for deployment**: The bundled file is ready to be pushed to Google Apps Script
152
182
 
153
183
  ## Examples
154
184
 
@@ -164,11 +194,21 @@ npx gasup
164
194
  clasp push
165
195
  ```
166
196
 
197
+ ### Development with watch mode
198
+ ```bash
199
+ # Start watch mode for development
200
+ npx gasup --watch
201
+
202
+ # In another terminal, push changes
203
+ clasp push
204
+ ```
205
+
167
206
  ### Using npm scripts
168
207
  ```bash
169
208
  # Add to package.json scripts
170
209
  npm run init
171
- npm run build
210
+ npm run dev # Watch mode
211
+ npm run build # One-time build
172
212
  clasp push
173
213
  ```
174
214
 
package/dist/bin/gasup.js CHANGED
@@ -5,16 +5,23 @@ import { init } from '../init.js';
5
5
  program
6
6
  .name('gasup')
7
7
  .description('CLI tool for Google Apps Script bundling')
8
- .version('0.4.4');
8
+ .version('1.0.1');
9
9
  // Main command (bundle execution)
10
10
  program
11
11
  .description('Bundle your Google Apps Script project')
12
- .action(async () => {
12
+ .option('--watch', 'Watch for changes and rebuild automatically')
13
+ .action(async (options) => {
13
14
  try {
14
15
  const config = await loadConfigWithDefault();
15
- console.log('📦 Bundling with esbuild...');
16
- await bundle(config);
17
- console.log('✅ Bundle completed');
16
+ if (options.watch) {
17
+ console.log('📦 Starting watch mode...');
18
+ await bundle(config, true);
19
+ }
20
+ else {
21
+ console.log('📦 Bundling with esbuild...');
22
+ await bundle(config, false);
23
+ console.log('✅ Bundle completed');
24
+ }
18
25
  }
19
26
  catch (error) {
20
27
  console.error('❌ Bundle failed:', error);
package/dist/bundle.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  import { Config } from './types.js';
2
- export declare function bundle(config: Config): Promise<void>;
2
+ export declare function bundle(config: Config, watch?: boolean): Promise<void>;
package/dist/bundle.js CHANGED
@@ -2,23 +2,50 @@ import esbuild from 'esbuild';
2
2
  import { GasPlugin } from 'esbuild-gas-plugin';
3
3
  import fs from 'fs';
4
4
  import path from 'path';
5
- export async function bundle(config) {
5
+ export async function bundle(config, watch = false) {
6
6
  const { appsScriptJsonPath, entryPoint, outputFile } = config;
7
7
  const bundleEntries = [entryPoint];
8
- await esbuild.build({
8
+ const buildOptions = {
9
9
  entryPoints: bundleEntries,
10
10
  bundle: true,
11
11
  outfile: outputFile,
12
12
  plugins: [GasPlugin],
13
- });
13
+ };
14
+ if (watch) {
15
+ // Watch mode
16
+ const context = await esbuild.context(buildOptions);
17
+ await context.watch();
18
+ // Initial build
19
+ await context.rebuild();
20
+ // Copy files after initial build
21
+ copyFiles(config);
22
+ console.log('👀 Watching for changes... (Press Ctrl+C to stop)');
23
+ // Keep the process running
24
+ process.on('SIGINT', () => {
25
+ context.dispose();
26
+ process.exit(0);
27
+ });
28
+ }
29
+ else {
30
+ // Normal build
31
+ await esbuild.build(buildOptions);
32
+ copyFiles(config);
33
+ }
34
+ }
35
+ function copyFiles(config) {
36
+ const { appsScriptJsonPath, entryPoint, outputFile } = config;
14
37
  const distDir = path.dirname(outputFile);
38
+ // Copy appsscript.json
15
39
  fs.copyFileSync(appsScriptJsonPath, path.join(distDir, 'appsscript.json'));
16
40
  // Copy HTML files to dist directory
17
- for (const bundleEntry of bundleEntries) {
18
- const entryDir = path.dirname(bundleEntry);
41
+ const entryDir = path.dirname(entryPoint);
42
+ try {
19
43
  const htmlFiles = fs.readdirSync(entryDir).filter(file => file.endsWith('.html'));
20
44
  for (const htmlFile of htmlFiles) {
21
45
  fs.copyFileSync(path.join(entryDir, htmlFile), path.join(distDir, htmlFile));
22
46
  }
23
47
  }
48
+ catch (error) {
49
+ // Directory might not exist or be readable, ignore
50
+ }
24
51
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gasup",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",