gasup 0.4.0 → 0.4.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/bin/gasup.js CHANGED
@@ -2,9 +2,11 @@ import { execSync } from 'child_process';
2
2
  import { program } from 'commander';
3
3
  import { build } from '../build.js';
4
4
  import { bundle } from '../bundle.js';
5
+ import { loadConfigWithDefault } from '../config.js';
5
6
  import { deploy } from '../deploy.js';
6
7
  import { changeEnv } from '../envFile/changeEnv.js';
7
8
  program
9
+ .option('--config', 'display current configuration')
8
10
  .option('--env <envpath>', 'apply env to clasp')
9
11
  .option('--bundle', 'bundle')
10
12
  .option('--build', 'build')
@@ -13,20 +15,25 @@ program
13
15
  .parse();
14
16
  async function main() {
15
17
  const opts = program.opts();
18
+ const config = await loadConfigWithDefault();
19
+ if (opts.config) {
20
+ console.log({ config });
21
+ return;
22
+ }
16
23
  if (opts.env?.startsWith('--')) {
17
24
  throw new Error('env option is required');
18
25
  }
19
26
  if (opts.env) {
20
27
  console.log(`apply ${opts.env} to clasp`);
21
- changeEnv(opts.env);
28
+ changeEnv(opts.env, config);
22
29
  }
23
30
  if (opts.build) {
24
31
  console.log('build with tsc');
25
- build();
32
+ build(config);
26
33
  }
27
34
  if (opts.bundle) {
28
35
  console.log('bundle with esbuild');
29
- await bundle();
36
+ await bundle(config);
30
37
  }
31
38
  if (opts.push) {
32
39
  console.log('push');
package/dist/build.d.ts CHANGED
@@ -1 +1,2 @@
1
- export declare function build(): void;
1
+ import { Config } from './types.js';
2
+ export declare function build(config: Config): void;
package/dist/build.js CHANGED
@@ -1,8 +1,7 @@
1
1
  import { execSync } from 'child_process';
2
2
  import { copyFileSync } from 'fs';
3
3
  import path from 'path';
4
- import { config } from './config.js';
5
- export function build() {
4
+ export function build(config) {
6
5
  execSync('tsc', { stdio: 'inherit' });
7
6
  copyFileSync(config.appsScriptJsonPath, path.join(config.distDir, 'appsscript.json'));
8
7
  }
package/dist/bundle.d.ts CHANGED
@@ -1 +1,2 @@
1
- export declare function bundle(): Promise<void>;
1
+ import { Config } from './types.js';
2
+ export declare function bundle(config: Config): Promise<void>;
package/dist/bundle.js CHANGED
@@ -2,13 +2,13 @@ import esbuild from 'esbuild';
2
2
  import { GasPlugin } from 'esbuild-gas-plugin';
3
3
  import fs from 'fs-extra';
4
4
  import path from 'path';
5
- import { config } from './config.js';
6
- export async function bundle() {
5
+ export async function bundle(config) {
6
+ const { bundleEntries, bundleOutfile, appsScriptJsonPath, distDir } = config;
7
7
  await esbuild.build({
8
- entryPoints: config.bundleEntries,
8
+ entryPoints: bundleEntries,
9
9
  bundle: true,
10
- outfile: config.bundleOutfile,
10
+ outfile: bundleOutfile,
11
11
  plugins: [GasPlugin],
12
12
  });
13
- fs.copyFileSync(config.appsScriptJsonPath, path.join(config.distDir, 'appsscript.json'));
13
+ fs.copyFileSync(appsScriptJsonPath, path.join(distDir, 'appsscript.json'));
14
14
  }
package/dist/config.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { Config } from './types.js';
2
2
  export declare const defaultConfig: Config;
3
- export declare const config: {
3
+ export declare function loadConfigWithDefault(): Promise<{
4
4
  claspJsonPath?: string;
5
5
  appsScriptJsonPath?: string;
6
6
  bundleEntries?: string[];
7
7
  bundleOutfile?: string;
8
8
  srcDir?: string;
9
9
  distDir?: string;
10
- };
10
+ }>;
package/dist/config.js CHANGED
@@ -10,28 +10,29 @@ export const defaultConfig = {
10
10
  srcDir: 'src',
11
11
  distDir: 'dist',
12
12
  };
13
- export const config = loadConfigWithDefault();
14
- function loadConfigWithDefault() {
13
+ // export const config = loadConfigWithDefault();
14
+ export async function loadConfigWithDefault() {
15
15
  const configPath = path.join(process.cwd(), configFileName);
16
- const config = loadConfig(configPath);
16
+ const config = await loadConfig(configPath);
17
17
  return {
18
18
  ...defaultConfig,
19
19
  ...config,
20
20
  };
21
21
  }
22
- function loadConfig(configPath) {
22
+ async function loadConfig(configPath) {
23
23
  try {
24
24
  const configString = fs.readFileSync(configPath, 'utf-8');
25
- const compiledPath = path.join(__dirname, '__config_compiled.js');
25
+ const compiledPath = path.join(process.cwd(), '__config_compiled.js');
26
26
  const compiledCode = tsnode
27
27
  .create()
28
28
  .compile(configString, 'config_dummy.ts');
29
29
  fs.writeFileSync(compiledPath, compiledCode);
30
- const data = require(compiledPath);
30
+ const data = await import(compiledPath);
31
31
  fs.unlinkSync(compiledPath);
32
32
  return data.default;
33
33
  }
34
34
  catch (err) {
35
+ console.error(err);
35
36
  return {};
36
37
  }
37
38
  }
@@ -1 +1,2 @@
1
- export declare function changeEnv(envPath: string): void;
1
+ import { Config } from '../types.js';
2
+ export declare function changeEnv(envPath: string, config: Config): void;
@@ -1,8 +1,7 @@
1
1
  import fs from 'fs-extra';
2
2
  import { updateClaspJson } from '../claspJson.js';
3
- import { config } from '../config.js';
4
3
  import { getEnvData } from './envFile.js';
5
- export function changeEnv(envPath) {
4
+ export function changeEnv(envPath, config) {
6
5
  if (!envPath) {
7
6
  throw new Error(`envPath not found on ${envPath}`);
8
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gasup",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",