@dainprotocol/cli 1.0.5 → 1.0.7

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/index.js CHANGED
@@ -14,7 +14,7 @@ var program = new commander_1.Command();
14
14
  program
15
15
  .name('dain')
16
16
  .description('CLI for Dain Protocol')
17
- .version('1.0.0');
17
+ .version('1.0.7');
18
18
  program
19
19
  .command('init <projectName>')
20
20
  .description('Initialize a new Dain project')
package/dist/utils.js CHANGED
@@ -50,7 +50,18 @@ var path_1 = __importDefault(require("path"));
50
50
  var client_1 = require("@dainprotocol/tunnel/client");
51
51
  var ora_1 = __importDefault(require("ora"));
52
52
  var chalk_1 = __importDefault(require("chalk"));
53
+ var dotenv_1 = __importDefault(require("dotenv"));
54
+ function loadEnvFiles() {
55
+ var envFiles = ['.env.local', '.env', '.env.development', '.env.production'];
56
+ envFiles.forEach(function (file) {
57
+ var envPath = path_1.default.join(process.cwd(), file);
58
+ if (fs_1.default.existsSync(envPath)) {
59
+ dotenv_1.default.config({ path: envPath });
60
+ }
61
+ });
62
+ }
53
63
  function getDainConfig(configFile) {
64
+ loadEnvFiles(); // Load environment variables from files
54
65
  var defaultConfigPath = path_1.default.join(process.cwd(), 'dain.json');
55
66
  var configPath = configFile ? path_1.default.join(process.cwd(), configFile) : defaultConfigPath;
56
67
  if (!fs_1.default.existsSync(configPath)) {
@@ -68,9 +79,15 @@ function getDainConfig(configFile) {
68
79
  config['version'] = config['version'] || '1.0.0';
69
80
  config['out-dir'] = config['out-dir'] || 'dist'; // Default to 'dist' if not specified
70
81
  config['tunnel-base-url'] = config['tunnel-base-url'] || 'wss:///devtunnel.dain-local.com'; // Default value if not specified
71
- // Validate API key if present
72
- if (config['api-key'] && typeof config['api-key'] !== 'string') {
73
- throw new Error("'api-key' must be a string");
82
+ // Handle API key
83
+ if (config['api-key'] === 'env') {
84
+ config['api-key'] = process.env.DAIN_API_KEY;
85
+ if (!config['api-key']) {
86
+ throw new Error("DAIN_API_KEY environment variable is not set");
87
+ }
88
+ }
89
+ else if (config['api-key'] && typeof config['api-key'] !== 'string') {
90
+ throw new Error("'api-key' must be a string or 'env'");
74
91
  }
75
92
  return config;
76
93
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dainprotocol/cli",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "CLI for Dain Protocol",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -21,6 +21,7 @@
21
21
  "chalk": "^4.1.2",
22
22
  "chokidar": "^3.6.0",
23
23
  "commander": "^11.1.0",
24
+ "dotenv": "^16.4.5",
24
25
  "esbuild": "^0.23.1",
25
26
  "fs-extra": "^11.2.0",
26
27
  "localtunnel": "^2.0.2",