gasup 0.0.1
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/dist/Config.d.ts +13 -0
- package/dist/Config.js +39 -0
- package/dist/bin/gasup.d.ts +1 -0
- package/dist/bin/gasup.js +28 -0
- package/dist/bundle.d.ts +1 -0
- package/dist/bundle.js +20 -0
- package/dist/changeEnv.d.ts +2 -0
- package/dist/changeEnv.js +27 -0
- package/dist/gasup.d.ts +1 -0
- package/dist/gasup.js +22 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/package.json +37 -0
package/dist/Config.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type Env = 'dev' | 'stag' | 'prod';
|
|
2
|
+
export interface Config {
|
|
3
|
+
envPaths?: Record<Env, string>;
|
|
4
|
+
claspJsonPath?: string;
|
|
5
|
+
appScriptJsonPath?: string;
|
|
6
|
+
bundleEntries?: string[];
|
|
7
|
+
bundleOutfile?: string;
|
|
8
|
+
srcDir?: string;
|
|
9
|
+
distDir?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const defaultConfig: Config;
|
|
12
|
+
export declare function getConfig(): Promise<Config>;
|
|
13
|
+
export declare function saveDefaultConfig(): Promise<void>;
|
package/dist/Config.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
const configPath = 'gasup.json';
|
|
5
|
+
export const defaultConfig = {
|
|
6
|
+
envPaths: {
|
|
7
|
+
dev: '.env',
|
|
8
|
+
stag: '.env.stag',
|
|
9
|
+
prod: '.env.prod',
|
|
10
|
+
},
|
|
11
|
+
claspJsonPath: '.clasp.json',
|
|
12
|
+
appScriptJsonPath: 'appsscript.json',
|
|
13
|
+
bundleEntries: [path.join('src', 'index.ts')],
|
|
14
|
+
bundleOutfile: path.join('dist', 'bundle.js'),
|
|
15
|
+
srcDir: 'src',
|
|
16
|
+
distDir: 'dist',
|
|
17
|
+
};
|
|
18
|
+
export async function getConfig() {
|
|
19
|
+
try {
|
|
20
|
+
console.log('getConfig', configPath);
|
|
21
|
+
// const require = createRequire(import.meta.url);
|
|
22
|
+
const res = readFileSync(path.join(process.cwd(), configPath));
|
|
23
|
+
const data = JSON.parse(res.toString());
|
|
24
|
+
console.log('data', data);
|
|
25
|
+
return {
|
|
26
|
+
...defaultConfig,
|
|
27
|
+
...data,
|
|
28
|
+
envPaths: { ...defaultConfig.envPaths, ...(data.envPaths ?? {}) },
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
console.error(e);
|
|
33
|
+
return defaultConfig;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export async function saveDefaultConfig() {
|
|
37
|
+
const config = { ...defaultConfig };
|
|
38
|
+
await fs.writeFile(path.join(process.cwd(), configPath), JSON.stringify(config, null, 2));
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { program } from 'commander';
|
|
2
|
+
import { bundle } from '../bundle.js';
|
|
3
|
+
import { changeEnv } from '../changeEnv.js';
|
|
4
|
+
import { saveDefaultConfig } from '../Config.js';
|
|
5
|
+
program
|
|
6
|
+
.option('--init', 'init')
|
|
7
|
+
.option('--env <env>', 'change env')
|
|
8
|
+
.option('--bundle', 'bundle')
|
|
9
|
+
.parse();
|
|
10
|
+
async function main() {
|
|
11
|
+
if (program.opts().init) {
|
|
12
|
+
await init();
|
|
13
|
+
}
|
|
14
|
+
if (program.opts().change) {
|
|
15
|
+
await changeEnv(program.opts().change);
|
|
16
|
+
}
|
|
17
|
+
if (program.opts().bundle) {
|
|
18
|
+
await bundle();
|
|
19
|
+
}
|
|
20
|
+
console.log('done');
|
|
21
|
+
}
|
|
22
|
+
main().catch((err) => {
|
|
23
|
+
console.error(err.message);
|
|
24
|
+
process.exit(1);
|
|
25
|
+
});
|
|
26
|
+
async function init() {
|
|
27
|
+
await saveDefaultConfig();
|
|
28
|
+
}
|
package/dist/bundle.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function bundle(): Promise<void>;
|
package/dist/bundle.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { getConfig } from './Config.js';
|
|
2
|
+
import esbuild from 'esbuild';
|
|
3
|
+
import { GasPlugin } from 'esbuild-gas-plugin';
|
|
4
|
+
import fs from 'fs-extra';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
export async function bundle() {
|
|
7
|
+
console.log('bundle with esbuild');
|
|
8
|
+
const config = await getConfig();
|
|
9
|
+
await esbuild
|
|
10
|
+
.build({
|
|
11
|
+
entryPoints: config.bundleEntries,
|
|
12
|
+
bundle: true,
|
|
13
|
+
outfile: config.bundleOutfile,
|
|
14
|
+
plugins: [GasPlugin],
|
|
15
|
+
})
|
|
16
|
+
.catch((e) => {
|
|
17
|
+
throw new Error(e);
|
|
18
|
+
});
|
|
19
|
+
fs.copyFileSync(config.appScriptJsonPath, path.join(config.distDir, 'appsscript.json'));
|
|
20
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import dotenv from 'dotenv';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import { getConfig } from './Config.js';
|
|
4
|
+
export async function changeEnv(env = 'dev') {
|
|
5
|
+
const config = await getConfig();
|
|
6
|
+
const envPath = config.envPaths[env];
|
|
7
|
+
if (!envPath) {
|
|
8
|
+
throw new Error(`envPath not found on ${envPath}`);
|
|
9
|
+
}
|
|
10
|
+
const claspJsonPath = config.claspJsonPath;
|
|
11
|
+
for (const path of [envPath, claspJsonPath]) {
|
|
12
|
+
if (!fs.existsSync(path)) {
|
|
13
|
+
throw new Error(`${path} not found`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
dotenv.config({ path: envPath });
|
|
17
|
+
const scriptId = process.env.SCRIPT_ID;
|
|
18
|
+
if (!scriptId) {
|
|
19
|
+
throw new Error(`SCRIPT_ID not found on ${envPath}`);
|
|
20
|
+
}
|
|
21
|
+
const data = {
|
|
22
|
+
scriptId,
|
|
23
|
+
rootDir: config.distDir,
|
|
24
|
+
};
|
|
25
|
+
fs.writeFileSync(claspJsonPath, JSON.stringify(data, null, 2));
|
|
26
|
+
console.log(`env changed to ${env}`);
|
|
27
|
+
}
|
package/dist/gasup.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/gasup.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const commander_1 = require("commander");
|
|
4
|
+
const bundle_1 = require("./bundle");
|
|
5
|
+
const changeEnv_1 = require("./changeEnv");
|
|
6
|
+
commander_1.program
|
|
7
|
+
.option('--env <env>', 'change env')
|
|
8
|
+
.option('--bundle', 'bundle')
|
|
9
|
+
.parse();
|
|
10
|
+
async function main() {
|
|
11
|
+
if (commander_1.program.opts().change) {
|
|
12
|
+
await (0, changeEnv_1.changeEnv)(commander_1.program.opts().change);
|
|
13
|
+
}
|
|
14
|
+
if (commander_1.program.opts().bundle) {
|
|
15
|
+
await (0, bundle_1.bundle)();
|
|
16
|
+
}
|
|
17
|
+
console.log('done');
|
|
18
|
+
}
|
|
19
|
+
main().catch((err) => {
|
|
20
|
+
console.error(err.message);
|
|
21
|
+
process.exit(1);
|
|
22
|
+
});
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "gasup",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"bin": {
|
|
6
|
+
"gasup": "./dist/bin/gasup.js"
|
|
7
|
+
},
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"keywords": [
|
|
14
|
+
"gas",
|
|
15
|
+
"gasup",
|
|
16
|
+
"cli",
|
|
17
|
+
"google apps script"
|
|
18
|
+
],
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"commander": "^13.0.0",
|
|
21
|
+
"dotenv": "^16.4.7",
|
|
22
|
+
"esbuild": "^0.24.2",
|
|
23
|
+
"esbuild-gas-plugin": "^0.8.0",
|
|
24
|
+
"fs-extra": "^11.3.0",
|
|
25
|
+
"path": "^0.12.7",
|
|
26
|
+
"ts-node": "^10.9.2",
|
|
27
|
+
"tsx": "^4.19.2"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/fs-extra": "^11.0.4",
|
|
31
|
+
"@types/node": "^22.10.7"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsc",
|
|
35
|
+
"dev": "tsc --watch"
|
|
36
|
+
}
|
|
37
|
+
}
|