gasup 0.1.0 → 0.2.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/dist/Config.js CHANGED
@@ -10,7 +10,7 @@ export const defaultConfig = {
10
10
  },
11
11
  claspJsonPath: '.clasp.json',
12
12
  appsScriptJsonPath: 'appsscript.json',
13
- bundleEntries: [path.join('src', 'index.ts')],
13
+ bundleEntries: [path.join('main', 'src', 'index.ts')],
14
14
  bundleOutfile: path.join('dist', 'bundle.js'),
15
15
  srcDir: 'src',
16
16
  distDir: 'dist',
@@ -30,7 +30,6 @@ export function getConfig() {
30
30
  };
31
31
  }
32
32
  catch (e) {
33
- console.error(e);
34
33
  return defaultConfig;
35
34
  }
36
35
  }
package/dist/bin/gasup.js CHANGED
@@ -3,16 +3,29 @@ import { build } from '../build.js';
3
3
  import { bundle } from '../bundle.js';
4
4
  import { changeEnv } from '../changeEnv.js';
5
5
  import { init } from '../init.js';
6
+ import inquirer from 'inquirer';
6
7
  program
7
8
  .option('--init', 'init')
8
9
  .option('--env <env>', 'change env')
9
10
  .option('--bundle', 'bundle')
10
11
  .option('--build', 'build')
11
12
  .parse();
12
- function main() {
13
+ async function main() {
13
14
  if (program.opts().init) {
14
- console.log('init gasup');
15
- init();
15
+ inquirer
16
+ .prompt({
17
+ type: 'confirm',
18
+ name: 'do',
19
+ message: 'This action will overwrite some files. Are you sure?',
20
+ })
21
+ .then((res) => {
22
+ if (!res.do)
23
+ return;
24
+ console.log('init gasup');
25
+ init();
26
+ console.log('init done');
27
+ });
28
+ return;
16
29
  }
17
30
  if (program.opts().env) {
18
31
  changeEnv(program.opts().env);
@@ -24,12 +37,12 @@ function main() {
24
37
  }
25
38
  if (program.opts().bundle) {
26
39
  console.log('bundle with esbuild');
27
- bundle();
40
+ await bundle();
28
41
  }
29
42
  console.log('gasup done');
30
43
  }
31
44
  try {
32
- main();
45
+ await main();
33
46
  }
34
47
  catch (err) {
35
48
  console.error(err.message);
package/dist/bundle.d.ts CHANGED
@@ -1 +1 @@
1
- export declare function bundle(): void;
1
+ export declare function bundle(): Promise<void>;
package/dist/bundle.js CHANGED
@@ -3,9 +3,9 @@ import esbuild from 'esbuild';
3
3
  import { GasPlugin } from 'esbuild-gas-plugin';
4
4
  import fs from 'fs-extra';
5
5
  import path from 'path';
6
- export function bundle() {
6
+ export async function bundle() {
7
7
  const config = getConfig();
8
- esbuild.buildSync({
8
+ await esbuild.build({
9
9
  entryPoints: config.bundleEntries,
10
10
  bundle: true,
11
11
  outfile: config.bundleOutfile,
package/dist/changeEnv.js CHANGED
@@ -14,9 +14,9 @@ export function changeEnv(env = 'dev') {
14
14
  }
15
15
  }
16
16
  dotenv.config({ path: envPath });
17
- const scriptId = process.env.SCRIPT_ID;
17
+ const scriptId = process.env.GASUP_SCRIPT_ID;
18
18
  if (!scriptId) {
19
- throw new Error(`SCRIPT_ID not found on ${envPath}`);
19
+ throw new Error(`GASUP_SCRIPT_ID not found on ${envPath}`);
20
20
  }
21
21
  const data = {
22
22
  scriptId,
@@ -0,0 +1 @@
1
+ export declare function getClaspJson(): any;
@@ -0,0 +1,7 @@
1
+ import { getConfig } from './config.js';
2
+ import fs from 'fs-extra';
3
+ export function getClaspJson() {
4
+ const config = getConfig();
5
+ const json = fs.readFileSync(config.claspJsonPath, 'utf-8');
6
+ return JSON.parse(json ?? '{}');
7
+ }
package/dist/envFile.js CHANGED
@@ -1,21 +1,25 @@
1
1
  import fs from 'fs-extra';
2
2
  import { getConfig } from './config.js';
3
- import { getAppsScript } from './appsScript.js';
3
+ import { getClaspJson } from './claspJson.js';
4
4
  export function initEnvFiles() {
5
5
  const config = getConfig();
6
- const appsScript = getAppsScript();
7
- const scriptId = appsScript.scriptId;
6
+ const claspJson = getClaspJson();
7
+ const scriptId = claspJson.scriptId;
8
8
  const envPath = config.envPaths['dev'];
9
9
  addToEnvFile(envPath, {
10
- SCRIPT_ID: scriptId,
10
+ GASUP_SCRIPT_ID: scriptId,
11
11
  });
12
12
  }
13
13
  export function addToEnvFile(envPath, _items) {
14
- const envString = fs.readFileSync(envPath, 'utf-8');
15
- const newEnvString = addToEnvString(envString, _items);
14
+ let envString = '';
15
+ try {
16
+ envString = fs.readFileSync(envPath, 'utf-8');
17
+ }
18
+ catch (e) { }
19
+ const newEnvString = addToEnvString(envString.trim(), _items);
16
20
  fs.writeFileSync(envPath, newEnvString);
17
21
  }
18
- // 環境変数を追加する。安全のため、既存の環境変数は上書きしない
22
+ // 環境変数を変更する
19
23
  export function addToEnvString(envString, _items) {
20
24
  const items = { ..._items };
21
25
  const newLines = [];
@@ -26,16 +30,23 @@ export function addToEnvString(envString, _items) {
26
30
  else {
27
31
  const { key, value } = parseLine(line);
28
32
  if (key) {
29
- newLines.push(`${key}=${value}`);
33
+ if (items[key]) {
34
+ newLines.push(`${key}=${items[key]}`);
35
+ delete items[key];
36
+ }
37
+ else {
38
+ newLines.push(`${key}=${value}`);
39
+ }
30
40
  }
31
41
  else {
32
42
  newLines.push('');
33
43
  }
34
- delete items[key];
35
44
  }
36
45
  }
37
46
  newLines.push('');
38
47
  for (const [key, value] of Object.entries(items)) {
48
+ if (!key)
49
+ continue;
39
50
  newLines.push(`${key}=${value}`);
40
51
  }
41
52
  return newLines.join('\n');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gasup",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "gasup": "./dist/bin/gasup.js"
@@ -23,6 +23,7 @@
23
23
  "esbuild": "^0.24.2",
24
24
  "esbuild-gas-plugin": "^0.8.0",
25
25
  "fs-extra": "^11.3.0",
26
+ "inquirer": "^12.3.2",
26
27
  "path": "^0.12.7",
27
28
  "remeda": "^2.19.2",
28
29
  "ts-node": "^10.9.2",