@unisphere/cli 1.45.3 → 1.46.0
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/package.json +3 -2
- package/src/lib/commands/runtime/command.js +2 -0
- package/src/lib/commands/runtime/command.js.map +1 -1
- package/src/lib/commands/runtime/serve-languages-command.d.ts +2 -0
- package/src/lib/commands/runtime/serve-languages-command.js +138 -0
- package/src/lib/commands/runtime/serve-languages-command.js.map +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unisphere/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.46.0",
|
|
4
4
|
"bin": {
|
|
5
5
|
"unisphere": "./src/cli.js"
|
|
6
6
|
},
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"rollup-plugin-analyzer": "4.0.0",
|
|
32
32
|
"glob": "8.0.3",
|
|
33
33
|
"rollup-plugin-shim": "1.0.0",
|
|
34
|
-
"debug": "4.
|
|
34
|
+
"debug": "4.4.0",
|
|
35
35
|
"commander": "9.4.1",
|
|
36
36
|
"listr2": "8.2.5",
|
|
37
37
|
"fs-extra": "10.1.0",
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
"csvtojson": "2.0.10",
|
|
44
44
|
"archiver": "5.3.2",
|
|
45
45
|
"fast-glob": "3.2.12",
|
|
46
|
+
"express": "5.1.0",
|
|
46
47
|
"@aws-sdk/client-s3": "3.216.0",
|
|
47
48
|
"@aws-sdk/client-sts": "3.216.0",
|
|
48
49
|
"axios": "1.2.0",
|
|
@@ -5,12 +5,14 @@ const commander_1 = require("commander");
|
|
|
5
5
|
const command_1 = require("./publish/command");
|
|
6
6
|
const build_command_1 = require("./build-command");
|
|
7
7
|
const serve_command_1 = require("./serve-command");
|
|
8
|
+
const serve_languages_command_1 = require("./serve-languages-command");
|
|
8
9
|
const createRuntimeCommand = () => {
|
|
9
10
|
const runtimeCommand = new commander_1.Command('runtime');
|
|
10
11
|
runtimeCommand.description('manage Unisphere runtime in the current project');
|
|
11
12
|
(0, build_command_1.createBuildCommand)(runtimeCommand);
|
|
12
13
|
(0, command_1.createPublishCommand)(runtimeCommand);
|
|
13
14
|
(0, serve_command_1.createServeCommand)(runtimeCommand);
|
|
15
|
+
(0, serve_languages_command_1.createServeLanguagesCommand)(runtimeCommand);
|
|
14
16
|
return runtimeCommand;
|
|
15
17
|
};
|
|
16
18
|
exports.createRuntimeCommand = createRuntimeCommand;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command.js","sourceRoot":"","sources":["../../../../../../../packages/unisphere-cli/src/lib/commands/runtime/command.ts"],"names":[],"mappings":";;;AAAA,yCAAoC;AACpC,+CAAyD;AACzD,mDAAqD;AACrD,mDAAqD;
|
|
1
|
+
{"version":3,"file":"command.js","sourceRoot":"","sources":["../../../../../../../packages/unisphere-cli/src/lib/commands/runtime/command.ts"],"names":[],"mappings":";;;AAAA,yCAAoC;AACpC,+CAAyD;AACzD,mDAAqD;AACrD,mDAAqD;AACrD,uEAAwE;AAEjE,MAAM,oBAAoB,GAAG,GAAY,EAAE;IAChD,MAAM,cAAc,GAAG,IAAI,mBAAO,CAAC,SAAS,CAAC,CAAC;IAC9C,cAAc,CAAC,WAAW,CAAC,iDAAiD,CAAC,CAAC;IAE9E,IAAA,kCAAkB,EAAC,cAAc,CAAC,CAAC;IACnC,IAAA,8BAAoB,EAAC,cAAc,CAAC,CAAC;IACrC,IAAA,kCAAkB,EAAC,cAAc,CAAC,CAAC;IACnC,IAAA,qDAA2B,EAAC,cAAc,CAAC,CAAC;IAC5C,OAAO,cAAc,CAAC;AACxB,CAAC,CAAC;AATW,QAAA,oBAAoB,wBAS/B"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createServeLanguagesCommand = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const debug_1 = require("debug");
|
|
6
|
+
const utils_1 = require("../../utils/utils");
|
|
7
|
+
const workspace_1 = require("../../utils/unisphere/workspace");
|
|
8
|
+
const express = require("express");
|
|
9
|
+
const path = require("path");
|
|
10
|
+
const fs = require("fs");
|
|
11
|
+
const glob = require("glob");
|
|
12
|
+
const debug = (0, debug_1.default)('unisphere:runtime:serve-languages');
|
|
13
|
+
const createServeLanguagesCommand = (parentCommand) => {
|
|
14
|
+
const command = parentCommand.command('serve-languages');
|
|
15
|
+
command
|
|
16
|
+
.description('serve languages')
|
|
17
|
+
.option('--verbose', 'output debug logs', false)
|
|
18
|
+
.option('--cwd <name>', 'the working directory')
|
|
19
|
+
.option('--https', 'use secure protocol')
|
|
20
|
+
.option('--port <port>', 'the port to serve the runtime on')
|
|
21
|
+
.hook('preAction', utils_1.printVerboseHook)
|
|
22
|
+
.action((options) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
+
const { verbose, cwd, port, watch } = options;
|
|
24
|
+
const workingDirectory = cwd || process.cwd();
|
|
25
|
+
const servePort = port || '8001';
|
|
26
|
+
try {
|
|
27
|
+
console.log(`Starting runtime server for languages`);
|
|
28
|
+
debug(`Working directory: ${workingDirectory}`);
|
|
29
|
+
debug(`Port: ${servePort}`);
|
|
30
|
+
const workspace = yield (0, workspace_1.getUnisphereWorkspace)(cwd, {
|
|
31
|
+
suspendRecursion: true,
|
|
32
|
+
});
|
|
33
|
+
if (!workspace) {
|
|
34
|
+
debug(`No .unisphere file found in the directory ${cwd}`);
|
|
35
|
+
throw new Error(`No .unisphere file found in the directory`);
|
|
36
|
+
}
|
|
37
|
+
// Create Express server
|
|
38
|
+
const app = express();
|
|
39
|
+
// Helper function to find package directory by name
|
|
40
|
+
const findPackageDirectory = (packageName) => {
|
|
41
|
+
debug(`Searching for package: ${packageName}`);
|
|
42
|
+
// Define search patterns
|
|
43
|
+
const searchPatterns = [
|
|
44
|
+
{
|
|
45
|
+
packageRootPath: path.join(workingDirectory, 'node_modules', '@unisphere', '*', 'package.json'),
|
|
46
|
+
languagesPath: 'languages',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
packageRootPath: path.join(workingDirectory, 'unisphere', 'packages', '*', 'package.json'),
|
|
50
|
+
languagesPath: 'src/languages/files',
|
|
51
|
+
},
|
|
52
|
+
];
|
|
53
|
+
// Search for package.json files
|
|
54
|
+
const normalizedPackageName = decodeURIComponent(packageName);
|
|
55
|
+
let foundPackagePath = null;
|
|
56
|
+
for (const pattern of searchPatterns) {
|
|
57
|
+
debug(`Searching in pattern: ${pattern.packageRootPath}`);
|
|
58
|
+
const packageJsonFiles = glob.sync(pattern.packageRootPath);
|
|
59
|
+
for (const packageJsonFile of packageJsonFiles) {
|
|
60
|
+
try {
|
|
61
|
+
debug(`Checking package.json at: ${packageJsonFile}`);
|
|
62
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonFile, 'utf8'));
|
|
63
|
+
if (packageJson.name === normalizedPackageName) {
|
|
64
|
+
foundPackagePath = path.dirname(packageJsonFile);
|
|
65
|
+
debug(`Found package at: ${foundPackagePath}, returning ${foundPackagePath}/${pattern.languagesPath}`);
|
|
66
|
+
return path.join(foundPackagePath, pattern.languagesPath);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
debug(`Error parsing package.json at ${packageJsonFile}: ${error.message}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
};
|
|
76
|
+
// Route to handle language file requests
|
|
77
|
+
app.get('/:packageName/:language.json', (req, res) => {
|
|
78
|
+
const { packageName, language } = req.params;
|
|
79
|
+
debug(`Received request for package: ${packageName}, language: ${language}`);
|
|
80
|
+
// Find the package directory
|
|
81
|
+
const packageDir = findPackageDirectory(packageName);
|
|
82
|
+
if (!packageDir) {
|
|
83
|
+
debug(`Package not found: ${packageName}`);
|
|
84
|
+
return res
|
|
85
|
+
.status(404)
|
|
86
|
+
.json({ error: `Package not found: ${packageName}` });
|
|
87
|
+
}
|
|
88
|
+
// Look for language file in the package directory
|
|
89
|
+
const languageFilePath = path.join(packageDir, `${language}.json`);
|
|
90
|
+
debug(`Checking language file: ${languageFilePath}`);
|
|
91
|
+
// Check if the file exists
|
|
92
|
+
if (fs.existsSync(languageFilePath)) {
|
|
93
|
+
try {
|
|
94
|
+
const fileContent = fs.readFileSync(languageFilePath, 'utf8');
|
|
95
|
+
const jsonContent = JSON.parse(fileContent);
|
|
96
|
+
// Set appropriate headers
|
|
97
|
+
res.setHeader('Content-Type', 'application/json');
|
|
98
|
+
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
99
|
+
// Send the JSON content
|
|
100
|
+
res.status(200).json(jsonContent);
|
|
101
|
+
debug(`Successfully served language file: ${languageFilePath}`);
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
debug(`Error reading or parsing language file: ${error.message}`);
|
|
105
|
+
res
|
|
106
|
+
.status(500)
|
|
107
|
+
.json({ error: 'Error reading or parsing language file' });
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
debug(`Language file not found: ${languageFilePath}`);
|
|
112
|
+
res.status(404).json({ error: 'Language file not found' });
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
// Start the server
|
|
116
|
+
const server = app.listen(parseInt(servePort), () => {
|
|
117
|
+
console.log(`Language server running at http://localhost:${servePort}`);
|
|
118
|
+
console.log(`Access language files at http://localhost:${servePort}/[package-name]/[language].json`);
|
|
119
|
+
});
|
|
120
|
+
// Handle server shutdown
|
|
121
|
+
process.on('SIGINT', () => {
|
|
122
|
+
debug('Shutting down language server');
|
|
123
|
+
server.close(() => {
|
|
124
|
+
console.log('Language server stopped');
|
|
125
|
+
process.exit(0);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
debug('Error in serve-languages command:', error);
|
|
131
|
+
console.error(`Error: ${error.message}`);
|
|
132
|
+
process.exit(1);
|
|
133
|
+
}
|
|
134
|
+
}));
|
|
135
|
+
return command;
|
|
136
|
+
};
|
|
137
|
+
exports.createServeLanguagesCommand = createServeLanguagesCommand;
|
|
138
|
+
//# sourceMappingURL=serve-languages-command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serve-languages-command.js","sourceRoot":"","sources":["../../../../../../../packages/unisphere-cli/src/lib/commands/runtime/serve-languages-command.ts"],"names":[],"mappings":";;;;AACA,iCAA0B;AAC1B,6CAAqD;AAErD,+DAAwE;AAGxE,mCAAmC;AACnC,6BAA6B;AAC7B,yBAAyB;AACzB,6BAA6B;AAE7B,MAAM,KAAK,GAAG,IAAA,eAAK,EAAC,mCAAmC,CAAC,CAAC;AAElD,MAAM,2BAA2B,GAAG,CACzC,aAAsB,EACb,EAAE;IACX,MAAM,OAAO,GAAG,aAAa,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAEzD,OAAO;SACJ,WAAW,CAAC,iBAAiB,CAAC;SAC9B,MAAM,CAAC,WAAW,EAAE,mBAAmB,EAAE,KAAK,CAAC;SAC/C,MAAM,CAAC,cAAc,EAAE,uBAAuB,CAAC;SAC/C,MAAM,CAAC,SAAS,EAAE,qBAAqB,CAAC;SACxC,MAAM,CAAC,eAAe,EAAE,kCAAkC,CAAC;SAC3D,IAAI,CAAC,WAAW,EAAE,wBAAgB,CAAC;SACnC,MAAM,CACL,CAAO,OAMN,EAAE,EAAE;QACH,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;QAC9C,MAAM,gBAAgB,GAAG,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;QAC9C,MAAM,SAAS,GAAG,IAAI,IAAI,MAAM,CAAC;QAEjC,IAAI;YACF,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC;YACrD,KAAK,CAA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