@dainprotocol/cli 1.0.12 → 1.0.13

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.
@@ -70,6 +70,10 @@ function config(action, key, value) {
70
70
  (0, utils_1.logError)('Invalid runtime. Use "node" or "workers"');
71
71
  return [2 /*return*/];
72
72
  }
73
+ if (key === 'platform-base-url' && !value.startsWith('http')) {
74
+ (0, utils_1.logError)('Invalid platform-base-url. It should start with http:// or https://');
75
+ return [2 /*return*/];
76
+ }
73
77
  config_1[key] = value;
74
78
  return [4 /*yield*/, fs_extra_1.default.writeJSON(configPath, config_1, { spaces: 2 })];
75
79
  case 4:
@@ -47,43 +47,85 @@ var fs_extra_1 = __importDefault(require("fs-extra"));
47
47
  var path_1 = __importDefault(require("path"));
48
48
  function deploy(options) {
49
49
  return __awaiter(this, void 0, void 0, function () {
50
- var config, spinner, outDir, staticFilesPath, error_1;
50
+ var config, spinner, outDir_1, platformBaseUrl, deployUrl, files, deployFiles, deployData, response, result, error_1;
51
+ var _this = this;
51
52
  return __generator(this, function (_a) {
52
53
  switch (_a.label) {
53
54
  case 0:
54
55
  config = (0, utils_1.getDainConfig)(options.config);
56
+ if (config.runtime !== 'workers') {
57
+ (0, utils_1.logError)("Deployment is only supported for 'workers' runtime.");
58
+ process.exit(1);
59
+ }
55
60
  spinner = (0, ora_1.default)("Deploying project...").start();
56
61
  _a.label = 1;
57
62
  case 1:
58
- _a.trys.push([1, 3, , 4]);
63
+ _a.trys.push([1, 7, , 8]);
59
64
  // First, build the project
60
65
  return [4 /*yield*/, (0, build_1.default)({ config: options.config })];
61
66
  case 2:
62
67
  // First, build the project
63
68
  _a.sent();
64
- outDir = config['out-dir'] || 'build';
65
- // Here you would add your deployment logic
66
- // For example, uploading the outDir/index.js file and static files to your server
67
- (0, utils_1.logInfo)("Deployment logic to be implemented");
68
- staticFilesPath = path_1.default.join(outDir, 'static');
69
- if (fs_extra_1.default.existsSync(staticFilesPath)) {
70
- (0, utils_1.logInfo)("Static files are available at: ".concat(staticFilesPath));
71
- // Here you would implement the logic to deploy these static files
72
- }
73
- else {
74
- (0, utils_1.logInfo)("No static files to deploy.");
69
+ outDir_1 = config['out-dir'] || 'build';
70
+ platformBaseUrl = config['platform-base-url'] || 'https://platform.dain.org';
71
+ deployUrl = "".concat(platformBaseUrl, "/api/platform-api/v1/service/deploy");
72
+ return [4 /*yield*/, fs_extra_1.default.readdir(outDir_1)];
73
+ case 3:
74
+ files = _a.sent();
75
+ return [4 /*yield*/, Promise.all(files.map(function (file) { return __awaiter(_this, void 0, void 0, function () {
76
+ var fileType, content;
77
+ return __generator(this, function (_a) {
78
+ switch (_a.label) {
79
+ case 0:
80
+ fileType = path_1.default.extname(file).slice(1);
81
+ if (!['js', 'mjs', 'wasm'].includes(fileType)) return [3 /*break*/, 2];
82
+ return [4 /*yield*/, fs_extra_1.default.readFile(path_1.default.join(outDir_1, file), 'utf-8')];
83
+ case 1:
84
+ content = _a.sent();
85
+ return [2 /*return*/, {
86
+ name: file,
87
+ content: content,
88
+ type: fileType,
89
+ }];
90
+ case 2: return [2 /*return*/, null];
91
+ }
92
+ });
93
+ }); })).then(function (files) { return files.filter(Boolean); })];
94
+ case 4:
95
+ deployFiles = _a.sent();
96
+ deployData = {
97
+ serviceIdentifer: config['project-id'],
98
+ files: deployFiles,
99
+ };
100
+ console.log(deployData);
101
+ return [4 /*yield*/, fetch(deployUrl, {
102
+ method: 'POST',
103
+ headers: {
104
+ 'Content-Type': 'application/json',
105
+ "X-DAIN-SIGNATORY-ADDRESS": "TODO: X-DAIN-SIGNATORY-ADDRESS",
106
+ "X-DAIN-SIGNATURE": "TODO: X-DAIN-SIGNATORY-SIGNATURE",
107
+ },
108
+ body: JSON.stringify(deployData),
109
+ })];
110
+ case 5:
111
+ response = _a.sent();
112
+ if (!response.ok) {
113
+ throw new Error("Deployment failed: ".concat(response.statusText));
75
114
  }
76
- (0, utils_1.logSuccess)("Deployment completed successfully. (NO LOGIC HERE YET, JUST EXAMPLE)");
115
+ return [4 /*yield*/, response.json()];
116
+ case 6:
117
+ result = _a.sent();
118
+ (0, utils_1.logSuccess)("Deployment completed successfully.");
77
119
  spinner.succeed("Deployment completed successfully.");
78
- (0, utils_1.logSuccess)("Project deployed and running.");
79
- return [3 /*break*/, 4];
80
- case 3:
120
+ (0, utils_1.logInfo)("Deployment result: ".concat(JSON.stringify(result, null, 2)));
121
+ return [3 /*break*/, 8];
122
+ case 7:
81
123
  error_1 = _a.sent();
82
124
  spinner.fail("Deployment failed.");
83
125
  (0, utils_1.logError)("Error during deployment", error_1);
84
126
  process.exit(1);
85
- return [3 /*break*/, 4];
86
- case 4: return [2 /*return*/];
127
+ return [3 /*break*/, 8];
128
+ case 8: return [2 /*return*/];
87
129
  }
88
130
  });
89
131
  });
@@ -7,5 +7,6 @@
7
7
  "environment": "development",
8
8
  "version": "1.0.0",
9
9
  "tunnel-base-url": "wss:///devtunnel.dain-local.com",
10
+ "platform-base-url": "https://platform.dain.org",
10
11
  "runtime": "workers"
11
12
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dainprotocol/cli",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "description": "CLI for Dain Protocol",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -7,5 +7,6 @@
7
7
  "environment": "development",
8
8
  "version": "1.0.0",
9
9
  "tunnel-base-url": "wss:///devtunnel.dain-local.com",
10
+ "platform-base-url": "https://platform.dain.org",
10
11
  "runtime": "workers"
11
12
  }