@dainprotocol/cli 1.0.12 → 1.0.14
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/commands/config.js
CHANGED
|
@@ -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:
|
package/dist/commands/deploy.js
CHANGED
|
@@ -47,43 +47,84 @@ 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,
|
|
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,
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
+
return [4 /*yield*/, fetch(deployUrl, {
|
|
101
|
+
method: 'POST',
|
|
102
|
+
headers: {
|
|
103
|
+
'Content-Type': 'application/json',
|
|
104
|
+
"X-DAIN-SIGNATORY-ADDRESS": "TODO: X-DAIN-SIGNATORY-ADDRESS",
|
|
105
|
+
"X-DAIN-SIGNATURE": "TODO: X-DAIN-SIGNATORY-SIGNATURE",
|
|
106
|
+
},
|
|
107
|
+
body: JSON.stringify(deployData),
|
|
108
|
+
})];
|
|
109
|
+
case 5:
|
|
110
|
+
response = _a.sent();
|
|
111
|
+
if (!response.ok) {
|
|
112
|
+
throw new Error("Deployment failed: ".concat(response.statusText));
|
|
75
113
|
}
|
|
76
|
-
|
|
114
|
+
return [4 /*yield*/, response.json()];
|
|
115
|
+
case 6:
|
|
116
|
+
result = _a.sent();
|
|
117
|
+
(0, utils_1.logSuccess)("Deployment completed successfully.");
|
|
77
118
|
spinner.succeed("Deployment completed successfully.");
|
|
78
|
-
(0, utils_1.
|
|
79
|
-
return [3 /*break*/,
|
|
80
|
-
case
|
|
119
|
+
(0, utils_1.logInfo)("Deployment result: ".concat(JSON.stringify(result, null, 2)));
|
|
120
|
+
return [3 /*break*/, 8];
|
|
121
|
+
case 7:
|
|
81
122
|
error_1 = _a.sent();
|
|
82
123
|
spinner.fail("Deployment failed.");
|
|
83
124
|
(0, utils_1.logError)("Error during deployment", error_1);
|
|
84
125
|
process.exit(1);
|
|
85
|
-
return [3 /*break*/,
|
|
86
|
-
case
|
|
126
|
+
return [3 /*break*/, 8];
|
|
127
|
+
case 8: return [2 /*return*/];
|
|
87
128
|
}
|
|
88
129
|
});
|
|
89
130
|
});
|
package/package.json
CHANGED