@youcan/app 2.4.3 → 2.5.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.
@@ -1,5 +1,6 @@
1
1
  import process from 'node:process';
2
2
  import { bootTunnelWorker, bootAppWorker, bootWebWorker, bootExtensionWorker } from '../../services/dev/workers/index.js';
3
+ import { getAppEnvironmentVariables } from '../../services/environment-variables.js';
3
4
  import { APP_CONFIG_FILENAME } from '../../../constants.js';
4
5
  import { AppCommand } from '../../../util/app-command.js';
5
6
  import { load } from '../../../util/app-loader.js';
@@ -145,9 +146,7 @@ class Dev extends AppCommand {
145
146
  throw new Error('app network config is not set');
146
147
  }
147
148
  return {
148
- YOUCAN_API_KEY: this.app.remote_config.client_id,
149
- YOUCAN_API_SECRET: this.app.remote_config.client_secret,
150
- YOUCAN_API_SCOPES: this.app.remote_config.scopes.join(','),
149
+ ...getAppEnvironmentVariables(this.app),
151
150
  APP_URL: this.app.network_config.app_url,
152
151
  PORT: this.app.network_config.app_port.toString(),
153
152
  };
@@ -0,0 +1,10 @@
1
+ import { AppCommand } from '@/util/app-command';
2
+ declare class EnvPull extends AppCommand {
3
+ static description: string;
4
+ static flags: {
5
+ 'env-file': import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
6
+ };
7
+ run(): Promise<any>;
8
+ private writeEnvFile;
9
+ }
10
+ export default EnvPull;
@@ -0,0 +1,40 @@
1
+ import { getAppEnvironmentVariables } from '../../../services/environment-variables.js';
2
+ import { AppCommand } from '../../../../util/app-command.js';
3
+ import { load } from '../../../../util/app-loader.js';
4
+ import { Flags } from '@oclif/core';
5
+ import { Path, Session, Tasks, Filesystem, Color } from '@youcan/cli-kit';
6
+
7
+ class EnvPull extends AppCommand {
8
+ static description = 'Create or update a .env file with app environment variables';
9
+ static flags = {
10
+ 'env-file': Flags.string({
11
+ description: 'Path to the .env file to create or update',
12
+ default: '.env',
13
+ }),
14
+ };
15
+ async run() {
16
+ const { flags } = await this.parse(EnvPull);
17
+ const envFilePath = Path.resolve(flags['env-file']);
18
+ this.app = await load();
19
+ this.session = await Session.authenticate(this);
20
+ await Tasks.run({}, [
21
+ {
22
+ title: 'Syncing app configuration..',
23
+ task: async () => { await this.syncAppConfig(); },
24
+ },
25
+ ]);
26
+ await this.writeEnvFile(envFilePath);
27
+ }
28
+ async writeEnvFile(filePath) {
29
+ const envVars = getAppEnvironmentVariables(this.app);
30
+ const envContent = Object.entries(envVars)
31
+ .map(([key, value]) => `${key}=${value}`)
32
+ .join('\n');
33
+ await Filesystem.writeFile(filePath, `${envContent}\n`);
34
+ this.log();
35
+ this.log(`${Color.green('[OK]')} Environment variables written to ${Color.cyan(filePath)}`);
36
+ this.log();
37
+ }
38
+ }
39
+
40
+ export { EnvPull as default };
@@ -1,3 +1,4 @@
1
+ import { getAppEnvironmentVariables } from '../../../services/environment-variables.js';
1
2
  import { AppCommand } from '../../../../util/app-command.js';
2
3
  import { load } from '../../../../util/app-loader.js';
3
4
  import { Session, Tasks, Color } from '@youcan/cli-kit';
@@ -16,13 +17,11 @@ class EnvShow extends AppCommand {
16
17
  await this.printEnvironmentVariables();
17
18
  }
18
19
  async printEnvironmentVariables() {
19
- if (!this.app.remote_config) {
20
- throw new Error('remote app config not loaded');
21
- }
20
+ const envVars = getAppEnvironmentVariables(this.app);
22
21
  this.log();
23
- this.log(`${Color.yellow('YOUCAN_API_KEY')}=%s`, this.app.remote_config.client_id);
24
- this.log(`${Color.yellow('YOUCAN_API_SECRET')}=%s`, this.app.remote_config.client_secret);
25
- this.log(`${Color.yellow('YOUCAN_API_SCOPES')}=%s`, this.app.remote_config.scopes.join(','));
22
+ for (const [key, value] of Object.entries(envVars)) {
23
+ this.log(`${Color.yellow(key)}=${value}`);
24
+ }
26
25
  }
27
26
  }
28
27
 
@@ -0,0 +1,2 @@
1
+ import type { App } from '@/types';
2
+ export declare function getAppEnvironmentVariables(app: App): Record<string, string>;
@@ -0,0 +1,16 @@
1
+ import { Env } from '@youcan/cli-kit';
2
+
3
+ function getAppEnvironmentVariables(app) {
4
+ if (!app.remote_config) {
5
+ throw new Error('remote app config not loaded');
6
+ }
7
+ return {
8
+ YOUCAN_API_KEY: app.remote_config.client_id,
9
+ YOUCAN_API_SECRET: app.remote_config.client_secret,
10
+ YOUCAN_API_SCOPES: app.remote_config.scopes.join(','),
11
+ YOUCAN_API_URL: `https://${Env.apiHostname()}`,
12
+ YOUCAN_SELLER_AREA_URL: `https://${Env.sellerAreaHostname()}`,
13
+ };
14
+ }
15
+
16
+ export { getAppEnvironmentVariables };
package/package.json CHANGED
@@ -1,10 +1,14 @@
1
1
  {
2
2
  "name": "@youcan/app",
3
3
  "type": "module",
4
- "version": "2.4.3",
4
+ "version": "2.5.1",
5
5
  "description": "OCLIF plugin for building apps",
6
6
  "author": "YouCan <contact@youcan.shop> (https://youcan.shop)",
7
7
  "license": "MIT",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/youcan-shop/cli"
11
+ },
8
12
  "keywords": [
9
13
  "youcan",
10
14
  "youcan-cli",
@@ -17,7 +21,7 @@
17
21
  "dependencies": {
18
22
  "@oclif/core": "^2.15.0",
19
23
  "dayjs": "^1.11.10",
20
- "@youcan/cli-kit": "2.4.3"
24
+ "@youcan/cli-kit": "2.5.1"
21
25
  },
22
26
  "devDependencies": {
23
27
  "@oclif/plugin-legacy": "^1.3.0",