@dainprotocol/cli 1.0.7 → 1.0.9

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.
@@ -115,7 +115,7 @@ function dev(options) {
115
115
  if (!config['api-key']) {
116
116
  throw new Error("'api-key' is required when using development proxy");
117
117
  }
118
- return [4 /*yield*/, (0, utils_1.setupProxy)(options.port, config['api-key'])];
118
+ return [4 /*yield*/, (0, utils_1.setupProxy)(options.port, config['api-key'], config)];
119
119
  case 2:
120
120
  proxyServer = _a.sent();
121
121
  _a.label = 3;
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.7');
17
+ .version(require('../package.json').version);
18
18
  program
19
19
  .command('init <projectName>')
20
20
  .description('Initialize a new Dain project')
@@ -0,0 +1 @@
1
+ DAIN_API_KEY=
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "project-id": "",
3
- "api-key": "",
3
+ "api-key": "MUST PUT IN .env.development as DAIN_API_KEY=YOUR_API_KEY",
4
4
  "main-file": "src/index.ts",
5
5
  "static-dir": "static",
6
6
  "out-dir": "dist",
package/dist/utils.js CHANGED
@@ -52,7 +52,12 @@ var ora_1 = __importDefault(require("ora"));
52
52
  var chalk_1 = __importDefault(require("chalk"));
53
53
  var dotenv_1 = __importDefault(require("dotenv"));
54
54
  function loadEnvFiles() {
55
- var envFiles = ['.env.local', '.env', '.env.development', '.env.production'];
55
+ var envFiles = [
56
+ ".env.local",
57
+ ".env",
58
+ ".env.development",
59
+ ".env.production",
60
+ ];
56
61
  envFiles.forEach(function (file) {
57
62
  var envPath = path_1.default.join(process.cwd(), file);
58
63
  if (fs_1.default.existsSync(envPath)) {
@@ -62,32 +67,33 @@ function loadEnvFiles() {
62
67
  }
63
68
  function getDainConfig(configFile) {
64
69
  loadEnvFiles(); // Load environment variables from files
65
- var defaultConfigPath = path_1.default.join(process.cwd(), 'dain.json');
66
- var configPath = configFile ? path_1.default.join(process.cwd(), configFile) : defaultConfigPath;
70
+ var defaultConfigPath = path_1.default.join(process.cwd(), "dain.json");
71
+ var configPath = configFile
72
+ ? path_1.default.join(process.cwd(), configFile)
73
+ : defaultConfigPath;
74
+ console.log("Config path: ", configPath);
67
75
  if (!fs_1.default.existsSync(configPath)) {
68
76
  throw new Error("Configuration file not found: ".concat(configPath));
69
77
  }
70
78
  try {
71
- var configData = fs_1.default.readFileSync(configPath, 'utf8');
79
+ var configData = fs_1.default.readFileSync(configPath, "utf8");
72
80
  var config = JSON.parse(configData);
73
81
  // Validate required fields
74
- if (!config['main-file']) {
82
+ if (!config["main-file"]) {
75
83
  throw new Error("Configuration must include 'main-file'");
76
84
  }
77
85
  // Set default values for optional fields
78
- config['environment'] = config['environment'] || 'development';
79
- config['version'] = config['version'] || '1.0.0';
80
- config['out-dir'] = config['out-dir'] || 'dist'; // Default to 'dist' if not specified
81
- config['tunnel-base-url'] = config['tunnel-base-url'] || 'wss:///devtunnel.dain-local.com'; // Default value if not specified
86
+ config["environment"] = config["environment"] || "development";
87
+ config["version"] = config["version"] || "1.0.0";
88
+ config["out-dir"] = config["out-dir"] || "dist"; // Default to 'dist' if not specified
89
+ config["tunnel-base-url"] =
90
+ config["tunnel-base-url"] || "wss:///devtunnel.dain-local.com"; // Default value if not specified
82
91
  // 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
- }
92
+ if (!config["api-key"] || config["api-key"] === "env" || config["api-key"] === "MUST PUT IN .env.development as DAIN_API_KEY=YOUR_API_KEY") {
93
+ config["api-key"] = process.env.DAIN_API_KEY;
88
94
  }
89
- else if (config['api-key'] && typeof config['api-key'] !== 'string') {
90
- throw new Error("'api-key' must be a string or 'env'");
95
+ if (!config["api-key"]) {
96
+ throw new Error("API key is not set in config or DAIN_API_KEY environment variable");
91
97
  }
92
98
  return config;
93
99
  }
@@ -95,18 +101,17 @@ function getDainConfig(configFile) {
95
101
  throw new Error("Error reading or parsing configuration file: ".concat(error));
96
102
  }
97
103
  }
98
- function setupProxy(port, apiKey) {
104
+ function setupProxy(port, apiKey, config) {
99
105
  return __awaiter(this, void 0, void 0, function () {
100
- var spinner, config, client, tunnelUrl, error_1;
106
+ var spinner, client, tunnelUrl, error_1;
101
107
  return __generator(this, function (_a) {
102
108
  switch (_a.label) {
103
109
  case 0:
104
- spinner = (0, ora_1.default)('Setting up proxy...').start();
110
+ spinner = (0, ora_1.default)("Setting up proxy...").start();
105
111
  _a.label = 1;
106
112
  case 1:
107
113
  _a.trys.push([1, 3, , 4]);
108
- config = getDainConfig();
109
- client = new client_1.DainTunnel(config['tunnel-base-url'] || 'wss:///tunnel.dain-local.com', apiKey);
114
+ client = new client_1.DainTunnel(config["tunnel-base-url"] || "wss:///tunnel.dain-local.com", apiKey);
110
115
  return [4 /*yield*/, client.start(parseInt(port))];
111
116
  case 2:
112
117
  tunnelUrl = _a.sent();
@@ -114,7 +119,7 @@ function setupProxy(port, apiKey) {
114
119
  return [2 /*return*/, client];
115
120
  case 3:
116
121
  error_1 = _a.sent();
117
- spinner.fail(chalk_1.default.red('Error setting up proxy'));
122
+ spinner.fail(chalk_1.default.red("Error setting up proxy"));
118
123
  console.error(chalk_1.default.red(error_1));
119
124
  return [3 /*break*/, 4];
120
125
  case 4: return [2 /*return*/];
@@ -135,5 +140,5 @@ function logInfo(message) {
135
140
  console.log(chalk_1.default.blue("Info: ".concat(message)));
136
141
  }
137
142
  function getStaticFilesPath() {
138
- return path_1.default.join(process.cwd(), 'static');
143
+ return path_1.default.join(process.cwd(), "static");
139
144
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dainprotocol/cli",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "CLI for Dain Protocol",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -0,0 +1 @@
1
+ DAIN_API_KEY=
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "project-id": "",
3
- "api-key": "",
3
+ "api-key": "MUST PUT IN .env.development as DAIN_API_KEY=YOUR_API_KEY",
4
4
  "main-file": "src/index.ts",
5
5
  "static-dir": "static",
6
6
  "out-dir": "dist",