@ciderjs/gasbombe 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.
- package/LICENSE +21 -0
- package/README.ja.md +98 -0
- package/README.md +98 -0
- package/dist/cli.cjs +59 -0
- package/dist/cli.d.cts +4 -0
- package/dist/cli.d.mts +4 -0
- package/dist/cli.d.ts +4 -0
- package/dist/cli.mjs +57 -0
- package/dist/index.cjs +108 -0
- package/dist/index.d.cts +10 -0
- package/dist/index.d.mts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.mjs +108 -0
- package/dist/templates/common/.gitignore.ejs +28 -0
- package/dist/templates/react-tsx/.clasp.json.ejs +5 -0
- package/dist/templates/react-tsx/.env.ejs +1 -0
- package/dist/templates/react-tsx/README.md.ejs +69 -0
- package/dist/templates/react-tsx/biome.json.ejs +65 -0
- package/dist/templates/react-tsx/gasnuki.config.ts.ejs +7 -0
- package/dist/templates/react-tsx/index.html.ejs +13 -0
- package/dist/templates/react-tsx/package.json.ejs +48 -0
- package/dist/templates/react-tsx/pnpm-lock.yaml.ejs +6015 -0
- package/dist/templates/react-tsx/pnpm-workspace.yaml.ejs +3 -0
- package/dist/templates/react-tsx/public/vite.svg.ejs +1 -0
- package/dist/templates/react-tsx/rolldown.config.ts.ejs +25 -0
- package/dist/templates/react-tsx/server/app.ts.ejs +29 -0
- package/dist/templates/react-tsx/server/appsscript.json.ejs +12 -0
- package/dist/templates/react-tsx/server/modules/hello.ts.ejs +3 -0
- package/dist/templates/react-tsx/src/App.css.ejs +42 -0
- package/dist/templates/react-tsx/src/App.tsx.ejs +58 -0
- package/dist/templates/react-tsx/src/assets/react.svg.ejs +1 -0
- package/dist/templates/react-tsx/src/index.css.ejs +68 -0
- package/dist/templates/react-tsx/src/lib/parameters.ts.ejs +20 -0
- package/dist/templates/react-tsx/src/lib/server.ts.ejs +18 -0
- package/dist/templates/react-tsx/src/main.tsx.ejs +11 -0
- package/dist/templates/react-tsx/src/vite-env.d.ts.ejs +1 -0
- package/dist/templates/react-tsx/tests/server/modules/hello.spec.ts.ejs +9 -0
- package/dist/templates/react-tsx/tests/src/lib/server.spec.ts.ejs +8 -0
- package/dist/templates/react-tsx/tsconfig.app.json.ejs +31 -0
- package/dist/templates/react-tsx/tsconfig.json.ejs +13 -0
- package/dist/templates/react-tsx/tsconfig.node.json.ejs +25 -0
- package/dist/templates/react-tsx/types/appsscript/client.ts.ejs +57 -0
- package/dist/templates/react-tsx/types/appsscript/server.ts.ejs +10 -0
- package/dist/templates/react-tsx/vite.config.ts.ejs +20 -0
- package/dist/templates/vanilla-ts/.clasp.json.ejs +5 -0
- package/dist/templates/vanilla-ts/.env.ejs +1 -0
- package/dist/templates/vanilla-ts/README.md.ejs +1 -0
- package/dist/templates/vanilla-ts/biome.json.ejs +36 -0
- package/dist/templates/vanilla-ts/package.json.ejs +33 -0
- package/dist/templates/vanilla-ts/pnpm-lock.yaml.ejs +5300 -0
- package/dist/templates/vanilla-ts/pnpm-workspace.yaml.ejs +3 -0
- package/dist/templates/vanilla-ts/rolldown.config.ts.ejs +29 -0
- package/dist/templates/vanilla-ts/src/main.ts.ejs +5 -0
- package/dist/templates/vanilla-ts/src/modules/hello.ts.ejs +3 -0
- package/dist/templates/vanilla-ts/tests/main.test.ts.ejs +15 -0
- package/dist/templates/vanilla-ts/tsconfig.json.ejs +30 -0
- package/dist/templates/vanilla-ts/vitest.config.ts.ejs +11 -0
- package/package.json +58 -0
- package/src/index.ts +114 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import alias from '@rollup/plugin-alias';
|
|
3
|
+
import { defineConfig } from 'rolldown';
|
|
4
|
+
import { removeExportPlugin } from 'rolldown-plugin-remove-export';
|
|
5
|
+
|
|
6
|
+
const outputFile = 'index.js';
|
|
7
|
+
|
|
8
|
+
export default defineConfig({
|
|
9
|
+
input: 'src/main.ts',
|
|
10
|
+
output: {
|
|
11
|
+
format: 'esm',
|
|
12
|
+
file: `dist/${outputFile}`,
|
|
13
|
+
},
|
|
14
|
+
plugins: [
|
|
15
|
+
alias({
|
|
16
|
+
entries: [
|
|
17
|
+
{
|
|
18
|
+
find: '@',
|
|
19
|
+
replacement: path.resolve(__dirname, 'src'),
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
find: '~',
|
|
23
|
+
replacement: path.resolve(__dirname),
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
}),
|
|
27
|
+
removeExportPlugin(outputFile),
|
|
28
|
+
],
|
|
29
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { describe, expect, test, vi } from 'vitest';
|
|
2
|
+
import { myFunction } from '@/main';
|
|
3
|
+
import { useHello } from '@/modules/hello';
|
|
4
|
+
|
|
5
|
+
describe('main', () => {
|
|
6
|
+
test('useHello', () => {
|
|
7
|
+
expect(useHello('world')).toBe('Hello world');
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
test('myFunction', () => {
|
|
11
|
+
vi.stubGlobal('Logger', { log: vi.fn() });
|
|
12
|
+
myFunction();
|
|
13
|
+
expect(Logger.log).toHaveBeenCalledWith('Hello world');
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2022",
|
|
4
|
+
"useDefineForClassFields": true,
|
|
5
|
+
"module": "esnext",
|
|
6
|
+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
|
|
9
|
+
/* Bundler mode */
|
|
10
|
+
"moduleResolution": "bundler",
|
|
11
|
+
"allowImportingTsExtensions": true,
|
|
12
|
+
"isolatedModules": true,
|
|
13
|
+
"moduleDetection": "force",
|
|
14
|
+
"noEmit": true,
|
|
15
|
+
|
|
16
|
+
/* Linting */
|
|
17
|
+
"strict": true,
|
|
18
|
+
"noUnusedLocals": true,
|
|
19
|
+
"noUnusedParameters": true,
|
|
20
|
+
"noFallthroughCasesInSwitch": true,
|
|
21
|
+
"noUncheckedSideEffectImports": true,
|
|
22
|
+
|
|
23
|
+
// Aliases
|
|
24
|
+
"paths": {
|
|
25
|
+
"@/*": ["./src/*"],
|
|
26
|
+
"~/*": ["./*"]
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"include": ["src", "tests", "types", "./*.ts"]
|
|
30
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ciderjs/gasbombe",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A TypeScript Project Generator for GoogleAppsScript, available as CLI",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.ts",
|
|
7
|
+
"bin": {
|
|
8
|
+
"gasbombe": "dist/cli.cjs"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"LICENSE",
|
|
13
|
+
"README.md"
|
|
14
|
+
],
|
|
15
|
+
"module": "dist/index.mjs",
|
|
16
|
+
"types": "dist/index.d.ts",
|
|
17
|
+
"scripts": {
|
|
18
|
+
"tsc": "tsgo --noEmit src",
|
|
19
|
+
"check": "biome check --write",
|
|
20
|
+
"generate": "jiti scripts/copyTemplates",
|
|
21
|
+
"prebuild": "pnpm run tsc",
|
|
22
|
+
"build": "unbuild",
|
|
23
|
+
"postbuild": "pnpm run generate",
|
|
24
|
+
"postinstall": "pnpm run generate"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"googleappsscript",
|
|
28
|
+
"generator",
|
|
29
|
+
"typescript",
|
|
30
|
+
"react"
|
|
31
|
+
],
|
|
32
|
+
"author": "luthpg",
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "https://github.com/luthpg/gasbombe.git"
|
|
37
|
+
},
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/luthpg/gasbombe/issues"
|
|
40
|
+
},
|
|
41
|
+
"homepage": "https://github.com/luthpg/gasbombe#readme",
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@inquirer/prompts": "^7.8.6",
|
|
44
|
+
"commander": "^14.0.1",
|
|
45
|
+
"consola": "^3.4.2",
|
|
46
|
+
"ejs": "^3.1.10",
|
|
47
|
+
"glob": "^11.0.3"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@biomejs/biome": "^2.2.4",
|
|
51
|
+
"@types/ejs": "^3.1.5",
|
|
52
|
+
"@types/node": "^24.5.2",
|
|
53
|
+
"@typescript/native-preview": "7.0.0-dev.20250925.1",
|
|
54
|
+
"jiti": "^2.6.0",
|
|
55
|
+
"typescript": "^5.9.2",
|
|
56
|
+
"unbuild": "^3.6.1"
|
|
57
|
+
}
|
|
58
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { consola } from 'consola';
|
|
5
|
+
import ejs from 'ejs';
|
|
6
|
+
import { glob } from 'glob';
|
|
7
|
+
import type { ProjectOptions } from '../types';
|
|
8
|
+
|
|
9
|
+
export async function runCommand(
|
|
10
|
+
command: string,
|
|
11
|
+
args: string[],
|
|
12
|
+
cwd: string,
|
|
13
|
+
): Promise<void> {
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
const child = spawn(command, args, {
|
|
16
|
+
cwd,
|
|
17
|
+
stdio: 'inherit',
|
|
18
|
+
shell: true,
|
|
19
|
+
});
|
|
20
|
+
child.on('close', (code) => {
|
|
21
|
+
if (code === 0) {
|
|
22
|
+
resolve();
|
|
23
|
+
} else {
|
|
24
|
+
reject(new Error(`Command failed with exit code ${code}`));
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
child.on('error', (err) => {
|
|
28
|
+
reject(err);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export async function generateProject({
|
|
34
|
+
projectName,
|
|
35
|
+
packageManager,
|
|
36
|
+
templateType,
|
|
37
|
+
}: ProjectOptions): Promise<void> {
|
|
38
|
+
const outputDir = path.resolve(process.cwd(), projectName);
|
|
39
|
+
const templateBaseDir = path.resolve(__dirname, '..', 'dist', 'templates');
|
|
40
|
+
const commonTemplateDir = path.resolve(templateBaseDir, 'common');
|
|
41
|
+
const specificTemplateDir = path.resolve(templateBaseDir, templateType);
|
|
42
|
+
|
|
43
|
+
consola.start(
|
|
44
|
+
`Creating a new Project for GoogleAppsScript in ${outputDir}...`,
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
await fs.access(outputDir);
|
|
49
|
+
consola.error(`Directory ${projectName} already exists.`);
|
|
50
|
+
process.exit(1);
|
|
51
|
+
} catch {
|
|
52
|
+
// Directory dose not exits, which is what we want.
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
await fs.mkdir(outputDir, { recursive: true });
|
|
56
|
+
consola.info(`Generating project files from template '${templateType}'...`);
|
|
57
|
+
|
|
58
|
+
const ejsData = { projectName };
|
|
59
|
+
const templateDirs = [commonTemplateDir, specificTemplateDir];
|
|
60
|
+
for (const dir of templateDirs) {
|
|
61
|
+
const files = await glob('./**/*', {
|
|
62
|
+
cwd: dir,
|
|
63
|
+
nodir: true,
|
|
64
|
+
dot: true,
|
|
65
|
+
dotRelative: true,
|
|
66
|
+
follow: true,
|
|
67
|
+
windowsPathsNoEscape: true,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
for (const file of files) {
|
|
71
|
+
const templatePath = path.join(dir, file);
|
|
72
|
+
const outputPath = path.join(outputDir, file.replace('.ejs', ''));
|
|
73
|
+
|
|
74
|
+
await fs.mkdir(path.dirname(outputPath), { recursive: true });
|
|
75
|
+
|
|
76
|
+
const templateContent = await fs.readFile(templatePath, {
|
|
77
|
+
encoding: 'utf-8',
|
|
78
|
+
});
|
|
79
|
+
const renderedContent = ejs.render(templateContent, ejsData);
|
|
80
|
+
await fs.writeFile(outputPath, renderedContent);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
consola.start(`Installing dependencies with ${packageManager}...`);
|
|
85
|
+
try {
|
|
86
|
+
await runCommand(packageManager, ['install'], outputDir);
|
|
87
|
+
consola.success(`Dependencies installed successfully.`);
|
|
88
|
+
} catch (e) {
|
|
89
|
+
consola.fail('Failed to install dependencies.');
|
|
90
|
+
consola.error(e);
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
consola.start(`Initializing Git repository...`);
|
|
95
|
+
try {
|
|
96
|
+
await runCommand('git', ['init'], outputDir);
|
|
97
|
+
await runCommand('git', ['add', '-A'], outputDir);
|
|
98
|
+
await runCommand(
|
|
99
|
+
'git',
|
|
100
|
+
['commit', '-m', '"Initial commit from gasbombe"'],
|
|
101
|
+
outputDir,
|
|
102
|
+
);
|
|
103
|
+
consola.success(`Git repository initialized successfully.`);
|
|
104
|
+
} catch {
|
|
105
|
+
consola.fail('Failed to initialize Git repository. Please do it manually.');
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
consola.success(`Project '${projectName}' created successfully!`);
|
|
109
|
+
consola.log(`\nTo get started, run:\n`);
|
|
110
|
+
projectName !== '.' && consola.log(` cd ${projectName}`);
|
|
111
|
+
templateType !== 'vanilla-ts'
|
|
112
|
+
? consola.log(` ${packageManager} dev`)
|
|
113
|
+
: consola.log(` ...and write your GAS code!`);
|
|
114
|
+
}
|