@codenotch/codenotch.cli 1.0.33 → 1.0.34
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/index.js +2 -0
- package/dist/commands/index.js.map +1 -1
- package/dist/commands/validation/ValidationUtils.d.ts +28 -0
- package/dist/commands/validation/ValidationUtils.js +182 -0
- package/dist/commands/validation/ValidationUtils.js.map +1 -0
- package/dist/commands/validation/files/AppManifestValidator.d.ts +6 -0
- package/dist/commands/validation/files/AppManifestValidator.js +93 -0
- package/dist/commands/validation/files/AppManifestValidator.js.map +1 -0
- package/dist/commands/validation/files/BpmnValidator.d.ts +5 -0
- package/dist/commands/validation/files/BpmnValidator.js +32 -0
- package/dist/commands/validation/files/BpmnValidator.js.map +1 -0
- package/dist/commands/validation/files/DbSchemaValidator.d.ts +5 -0
- package/dist/commands/validation/files/DbSchemaValidator.js +16 -0
- package/dist/commands/validation/files/DbSchemaValidator.js.map +1 -0
- package/dist/commands/validation/files/DocumentValidator.d.ts +5 -0
- package/dist/commands/validation/files/DocumentValidator.js +12 -0
- package/dist/commands/validation/files/DocumentValidator.js.map +1 -0
- package/dist/commands/validation/files/I18nValidator.d.ts +5 -0
- package/dist/commands/validation/files/I18nValidator.js +13 -0
- package/dist/commands/validation/files/I18nValidator.js.map +1 -0
- package/dist/commands/validation/files/JsonValidator.d.ts +5 -0
- package/dist/commands/validation/files/JsonValidator.js +13 -0
- package/dist/commands/validation/files/JsonValidator.js.map +1 -0
- package/dist/commands/validation/files/ManifestCacheValidator.d.ts +5 -0
- package/dist/commands/validation/files/ManifestCacheValidator.js +121 -0
- package/dist/commands/validation/files/ManifestCacheValidator.js.map +1 -0
- package/dist/commands/validation/files/ManifestValidator.d.ts +5 -0
- package/dist/commands/validation/files/ManifestValidator.js +14 -0
- package/dist/commands/validation/files/ManifestValidator.js.map +1 -0
- package/dist/commands/validation/files/ScriptValidator.d.ts +12 -0
- package/dist/commands/validation/files/ScriptValidator.js +128 -0
- package/dist/commands/validation/files/ScriptValidator.js.map +1 -0
- package/dist/commands/validation/files/TableValidator.d.ts +5 -0
- package/dist/commands/validation/files/TableValidator.js +19 -0
- package/dist/commands/validation/files/TableValidator.js.map +1 -0
- package/dist/commands/validation/validate.d.ts +2 -0
- package/dist/commands/validation/validate.js +245 -0
- package/dist/commands/validation/validate.js.map +1 -0
- package/dist/utils/BuildUtils.d.ts +22 -4
- package/dist/utils/BuildUtils.js +45 -16
- package/dist/utils/BuildUtils.js.map +1 -1
- package/dist/utils/FileUtils.d.ts +13 -0
- package/dist/utils/FileUtils.js +30 -0
- package/dist/utils/FileUtils.js.map +1 -1
- package/dist/utils/I18nUtils.js +0 -2
- package/dist/utils/I18nUtils.js.map +1 -1
- package/package.json +14 -6
- package/.github/copilot-instructions.md +0 -3
- package/bin/cli.js +0 -3
- package/docs/ARCHITECTURE.md +0 -179
- package/docs/TODO.md +0 -18
- package/src/bin/cli.ts +0 -4
- package/src/commands/index.ts +0 -13
- package/src/commands/project/compile.ts +0 -20
- package/src/commands/project/deploy.ts +0 -11
- package/src/commands/project/index.ts +0 -28
- package/src/commands/project/inspect.ts +0 -12
- package/src/commands/project/new.ts +0 -11
- package/src/commands/project/open.ts +0 -21
- package/src/commands/project/package.ts +0 -20
- package/src/commands/project/refresh.ts +0 -13
- package/src/commands/project/remove.ts +0 -12
- package/src/commands/project/shared.ts +0 -9
- package/src/commands/project/start.ts +0 -24
- package/src/commands/project/test.ts +0 -15
- package/src/commands/react/build.ts +0 -12
- package/src/commands/react/index.ts +0 -12
- package/src/commands/react/serve.ts +0 -13
- package/src/commands/runtime/clear.ts +0 -11
- package/src/commands/runtime/index.ts +0 -24
- package/src/commands/runtime/info.ts +0 -47
- package/src/commands/runtime/latest.ts +0 -18
- package/src/commands/runtime/portal.ts +0 -20
- package/src/commands/runtime/start.ts +0 -16
- package/src/commands/runtime/stop.ts +0 -13
- package/src/commands/runtime/update.ts +0 -12
- package/src/commands/system/index.ts +0 -9
- package/src/commands/system/info.ts +0 -23
- package/src/commands/system/read.ts +0 -25
- package/src/index.ts +0 -22
- package/src/models/Codenotch.ts +0 -361
- package/src/models/DbModels.ts +0 -428
- package/src/models/OpenApiModels.ts +0 -145
- package/src/utils/BuildUtils.ts +0 -739
- package/src/utils/ConsoleUtils.ts +0 -22
- package/src/utils/FileUtils.ts +0 -266
- package/src/utils/GitHubAuthUtils.ts +0 -83
- package/src/utils/I18nUtils.ts +0 -58
- package/src/utils/OpenAPIUtils.ts +0 -285
- package/src/utils/OsUtils.ts +0 -32
- package/src/utils/ProjectCompilationUtils.ts +0 -1002
- package/src/utils/ProjectUtils.ts +0 -151
- package/src/utils/RuntimeUtils.ts +0 -743
- package/src/utils/ServeUtils.ts +0 -175
- package/src/utils/ShellUtils.ts +0 -26
- package/src/utils/StringUtils.ts +0 -80
- package/tsconfig.json +0 -35
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import chalk from "chalk";
|
|
2
|
-
|
|
3
|
-
export default abstract class ConsoleUtils {
|
|
4
|
-
static check(text: string){
|
|
5
|
-
console.log(`${chalk.green('✓')} ${text}`);
|
|
6
|
-
}
|
|
7
|
-
static checkWarning(text: string){
|
|
8
|
-
console.log(`${chalk.yellow('✓')} ${text}`);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
static proposeCommand(question: string, command: string){
|
|
14
|
-
let data = JSON.stringify({question, command});
|
|
15
|
-
return `\u001b_Gcodenotchcli:proposeCommand:${data}\u001b\\`;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
static proposeOpenUri(question: string, uri: string){
|
|
19
|
-
let data = JSON.stringify({question, uri});
|
|
20
|
-
return `\u001b_Gcodenotchcli:proposeOpenUri:${data}\u001b\\`;
|
|
21
|
-
}
|
|
22
|
-
}
|
package/src/utils/FileUtils.ts
DELETED
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import StringUtils from './StringUtils';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import fse, { CopyOptions, MoveOptions } from 'fs-extra';
|
|
5
|
-
import { platform } from 'os';
|
|
6
|
-
import AdmZip from 'adm-zip';
|
|
7
|
-
|
|
8
|
-
export default abstract class FileUtils {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
public static async zipFolder(targetPath: string, zipFilePath: string) {
|
|
12
|
-
try {
|
|
13
|
-
targetPath = FileUtils.normalize(targetPath);
|
|
14
|
-
zipFilePath = FileUtils.normalize(zipFilePath);
|
|
15
|
-
|
|
16
|
-
// Ensure the directory for the zip file exists
|
|
17
|
-
const zipDir = path.dirname(zipFilePath);
|
|
18
|
-
if (!fs.existsSync(zipDir)) {
|
|
19
|
-
fs.mkdirSync(zipDir, { recursive: true });
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const zip = new AdmZip();
|
|
23
|
-
|
|
24
|
-
const stats = fs.lstatSync(targetPath);
|
|
25
|
-
if (stats.isDirectory()) {
|
|
26
|
-
zip.addLocalFolder(targetPath, '');
|
|
27
|
-
} else {
|
|
28
|
-
zip.addLocalFile(targetPath);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
zip.writeZip(zipFilePath);
|
|
32
|
-
return true;
|
|
33
|
-
} catch (e) {
|
|
34
|
-
console.error(`Error zipping folder "${targetPath}":`, e);
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
public static slash() {
|
|
40
|
-
return platform() === 'win32' ? '\\' : '/';
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
static normalize(path?: string): string {
|
|
44
|
-
if (path === undefined)
|
|
45
|
-
return '';
|
|
46
|
-
|
|
47
|
-
if (path.startsWith("http")) {
|
|
48
|
-
return path.replaceAll('\\', '/');
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
let os = platform();
|
|
52
|
-
if (os === 'win32') {
|
|
53
|
-
path = path.replaceAll("/", '\\');
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
path = path.replaceAll('\\', '/');
|
|
57
|
-
}
|
|
58
|
-
return path;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
public static async exists(filePath: string): Promise<boolean> {
|
|
62
|
-
filePath = FileUtils.normalize(filePath);
|
|
63
|
-
try {
|
|
64
|
-
await fs.promises.access(filePath, fs.constants.F_OK);
|
|
65
|
-
return true;
|
|
66
|
-
} catch (e) {
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
public static async readFileAsync(filePath: string): Promise<string> {
|
|
72
|
-
filePath = FileUtils.normalize(filePath);
|
|
73
|
-
|
|
74
|
-
return await fs.promises.readFile(filePath, { encoding: "utf-8" });
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
public static async readJsonFileAsync<T>(filePath: string): Promise<T | null> {
|
|
78
|
-
filePath = FileUtils.normalize(filePath);
|
|
79
|
-
|
|
80
|
-
const content = await fs.promises.readFile(filePath, { encoding: "utf-8" });
|
|
81
|
-
if(!content || content.trim() === '') {
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return JSON.parse(content) as T;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
public static writeFileSync(filePath: string, content: string): boolean {
|
|
89
|
-
|
|
90
|
-
try {
|
|
91
|
-
filePath = StringUtils.normalizePath(filePath);
|
|
92
|
-
let folder = path.dirname(filePath);
|
|
93
|
-
if (!fs!.existsSync(folder)) {
|
|
94
|
-
fs!.mkdirSync(folder, { recursive: true });
|
|
95
|
-
}
|
|
96
|
-
fs!.writeFileSync(filePath, content, { encoding: "utf-8" });
|
|
97
|
-
return true;
|
|
98
|
-
}
|
|
99
|
-
catch (e) {
|
|
100
|
-
console.error(`Error writing file "${filePath}":`, e);
|
|
101
|
-
return false;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
public static async copyFolder(folderPath: string, copyInto: string, ignoreFolders: string[] = []): Promise<void> {
|
|
106
|
-
folderPath = FileUtils.normalize(folderPath);
|
|
107
|
-
copyInto = FileUtils.normalize(copyInto);
|
|
108
|
-
|
|
109
|
-
if (fse === undefined || path === undefined) {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (!fse.existsSync(copyInto)) {
|
|
114
|
-
// Create destination folder
|
|
115
|
-
fse.mkdirSync(copyInto, { recursive: true });
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
let options: CopyOptions = {
|
|
119
|
-
recursive: true,
|
|
120
|
-
overwrite: true,
|
|
121
|
-
filter: (path) => !ignoreFolders.some(folder => path.includes(folder)) // ignore specified folders
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// if destination is a subdirectory of the copies folder we need to handle things differently
|
|
125
|
-
if (copyInto.includes(folderPath)) {
|
|
126
|
-
|
|
127
|
-
let destFolderName = path.basename(copyInto);
|
|
128
|
-
|
|
129
|
-
// We cannot use copy directly on the root folder because it won't work "to" is a subdirectory of the root folder
|
|
130
|
-
let files = await fse.readdir(folderPath);
|
|
131
|
-
|
|
132
|
-
for (let f of files) {
|
|
133
|
-
|
|
134
|
-
// Ignore destination if it is a subdirectory
|
|
135
|
-
if (f === destFolderName)
|
|
136
|
-
continue;
|
|
137
|
-
|
|
138
|
-
// Or if it belongs to the ignored files/folders
|
|
139
|
-
if (ignoreFolders.some(folder => f === folder)) // ignore specified folders
|
|
140
|
-
continue;
|
|
141
|
-
|
|
142
|
-
let from = path.join(folderPath, f);
|
|
143
|
-
let to = path.join(copyInto, f);
|
|
144
|
-
|
|
145
|
-
await fse.copy(from, to, options);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
await fse.copy(folderPath, copyInto, options);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
public static async moveFolder(folderPath: string, moveInto: string, ignoreFolders: string[] = []): Promise<void> {
|
|
155
|
-
folderPath = FileUtils.normalize(folderPath);
|
|
156
|
-
moveInto = FileUtils.normalize(moveInto);
|
|
157
|
-
|
|
158
|
-
if (fse === undefined || path === undefined) {
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if (!fse.existsSync(moveInto)) {
|
|
163
|
-
// Create destination folder
|
|
164
|
-
fse.mkdirSync(moveInto, { recursive: true });
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
let options: MoveOptions = {
|
|
168
|
-
overwrite: true
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// if destination is a subdirectory of the copies folder we need to handle things differently
|
|
172
|
-
if (moveInto.includes(folderPath)) {
|
|
173
|
-
|
|
174
|
-
let destFolderName = path.basename(moveInto);
|
|
175
|
-
|
|
176
|
-
// We cannot use copy directly on the root folder because it won't work "to" is a subdirectory of the root folder
|
|
177
|
-
let files = await fse.readdir(folderPath);
|
|
178
|
-
|
|
179
|
-
for (let f of files) {
|
|
180
|
-
|
|
181
|
-
// Ignore destination if it is a subdirectory
|
|
182
|
-
if (f === destFolderName)
|
|
183
|
-
continue;
|
|
184
|
-
|
|
185
|
-
// Or if it belongs to the ignored files/folders
|
|
186
|
-
if (ignoreFolders.some(folder => f === folder)) // ignore specified folders
|
|
187
|
-
continue;
|
|
188
|
-
|
|
189
|
-
let from = path.join(folderPath, f);
|
|
190
|
-
let to = path.join(moveInto, f);
|
|
191
|
-
|
|
192
|
-
await fse.move(from, to, options);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
await fse.move(folderPath, moveInto, options);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
public static delete(path: string) {
|
|
203
|
-
path = StringUtils.normalizePath(path);
|
|
204
|
-
if (fs.existsSync(path)) {
|
|
205
|
-
if (fs.lstatSync(path).isDirectory()) {
|
|
206
|
-
fs.rmSync(path, { recursive: true, force: true });
|
|
207
|
-
}
|
|
208
|
-
else {
|
|
209
|
-
fs.unlinkSync(path);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
public static getAllFilesFromPath(path: string, ignoreFolders: string[] = []): string[] {
|
|
215
|
-
|
|
216
|
-
try {
|
|
217
|
-
path = StringUtils.normalizePath(path);
|
|
218
|
-
let isDirectory = fs.lstatSync(path).isDirectory();
|
|
219
|
-
if (isDirectory) {
|
|
220
|
-
|
|
221
|
-
if(ignoreFolders && ignoreFolders.some(c => path.endsWith(`\\${c}`) || path.endsWith(`/${c}`))){
|
|
222
|
-
return [];
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
return this.getAllFiles(path, ignoreFolders);
|
|
226
|
-
}
|
|
227
|
-
else {
|
|
228
|
-
return [path];
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
catch {
|
|
232
|
-
return [];
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
private static getAllFiles(path: string, ignoreFolders: string[] = [], arrayOfFiles?: string[], level?: number): string[] {
|
|
237
|
-
|
|
238
|
-
path = StringUtils.normalizePath(path);
|
|
239
|
-
|
|
240
|
-
if (ignoreFolders.some(c => path.endsWith(`\\${c}`) || path.endsWith(`/${c}`))) {
|
|
241
|
-
return [];
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
let files = fs.readdirSync(path, { withFileTypes: true });
|
|
245
|
-
|
|
246
|
-
arrayOfFiles = arrayOfFiles ? arrayOfFiles : [];
|
|
247
|
-
|
|
248
|
-
for (let i = 0; i < files.length; i++) {
|
|
249
|
-
let file = files[i];
|
|
250
|
-
let nextPath = StringUtils.normalizePath(`${path}\\${file.name}`);
|
|
251
|
-
if (file.isDirectory()) {
|
|
252
|
-
if (ignoreFolders.some(c => nextPath.endsWith(`\\${c}`) || nextPath.endsWith(`/${c}`))) {
|
|
253
|
-
continue;
|
|
254
|
-
}
|
|
255
|
-
else {
|
|
256
|
-
arrayOfFiles = this.getAllFiles(nextPath, ignoreFolders, arrayOfFiles, (level ?? 0) + 1);
|
|
257
|
-
}
|
|
258
|
-
} else {
|
|
259
|
-
|
|
260
|
-
arrayOfFiles!.push(nextPath);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
return arrayOfFiles
|
|
265
|
-
}
|
|
266
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import os from "node:os";
|
|
4
|
-
import readline from "node:readline";
|
|
5
|
-
import chalk from "chalk";
|
|
6
|
-
import { createOAuthDeviceAuth } from "@octokit/auth-oauth-device";
|
|
7
|
-
import { OsUtils } from "./OsUtils";
|
|
8
|
-
import { deletePassword, getPassword, setPassword } from "cross-keychain";
|
|
9
|
-
|
|
10
|
-
const SERVICE_NAME = "codenotch-cli";
|
|
11
|
-
const ACCOUNT_NAME = "github-oauth-token";
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Handles GitHub authentication for the CLI.
|
|
15
|
-
*/
|
|
16
|
-
export default abstract class GitHubAuthUtils {
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Returns a valid GitHub token, prompting the user interactively if needed.
|
|
20
|
-
* @param forceReauth When true, skip cache and always prompt again.
|
|
21
|
-
*/
|
|
22
|
-
static async getToken(forceReauth = false): Promise<string> {
|
|
23
|
-
|
|
24
|
-
// Use PAT if provided via environment variable (e.g. for CI or advanced users)
|
|
25
|
-
if (process.env.GITHUB_TOKEN) {
|
|
26
|
-
return process.env.GITHUB_TOKEN;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Try to get token from cache (keychain)
|
|
30
|
-
try {
|
|
31
|
-
const cachedToken = await getPassword(SERVICE_NAME, ACCOUNT_NAME);
|
|
32
|
-
if (cachedToken) {
|
|
33
|
-
// Do a quick fetch to GitHub to ensure the token hasn't been revoked
|
|
34
|
-
const response = await fetch("https://api.github.com/user", {
|
|
35
|
-
headers: {
|
|
36
|
-
Authorization: `Bearer ${cachedToken}`
|
|
37
|
-
},
|
|
38
|
-
});
|
|
39
|
-
if (response.ok) {
|
|
40
|
-
return cachedToken;
|
|
41
|
-
}
|
|
42
|
-
// Token is invalid/revoked — delete it and fall through to re-auth
|
|
43
|
-
await deletePassword(SERVICE_NAME, ACCOUNT_NAME).catch(() => {});
|
|
44
|
-
}
|
|
45
|
-
} catch (err: any) {
|
|
46
|
-
// If keychain reading fails, silently fall back to running the login flow
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const auth = createOAuthDeviceAuth({
|
|
50
|
-
clientType: "oauth-app",
|
|
51
|
-
clientId: "Ov23liEBS0dxtgGbq4K9",
|
|
52
|
-
scopes: ["repo"],
|
|
53
|
-
onVerification(verification) {
|
|
54
|
-
console.log("Open your browser at:");
|
|
55
|
-
console.log(verification.verification_uri);
|
|
56
|
-
OsUtils.openInBrowser(verification.verification_uri);
|
|
57
|
-
console.log(`\nEnter code: ${verification.user_code}`);
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
const tokenAuthentication = await auth({ type: "oauth" });
|
|
62
|
-
|
|
63
|
-
const token = tokenAuthentication.token;
|
|
64
|
-
|
|
65
|
-
try {
|
|
66
|
-
await setPassword(SERVICE_NAME, ACCOUNT_NAME, token);
|
|
67
|
-
console.log("Login successful! Session saved securely.");
|
|
68
|
-
} catch (err: any) {
|
|
69
|
-
console.error("Warning: Could not save token to system keychain.", err.message);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return token;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
async logout() {
|
|
76
|
-
try {
|
|
77
|
-
await deletePassword(SERVICE_NAME, ACCOUNT_NAME);
|
|
78
|
-
console.log("Logged out successfully. Secure token deleted.");
|
|
79
|
-
} catch (err: any) {
|
|
80
|
-
console.error("Failed to clear local token:", err.message);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
package/src/utils/I18nUtils.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from "fs";
|
|
2
|
-
import FileUtils from "./FileUtils";
|
|
3
|
-
import Papa from "papaparse";
|
|
4
|
-
|
|
5
|
-
export default abstract class I18nUtils {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
public static async getAllI18nFiles(folderPath: string) {
|
|
9
|
-
let files = FileUtils.getAllFilesFromPath(folderPath, ['.codenotch', 'node_modules', 'dist', 'build']).filter(c => c.endsWith('.i18n.csv'));
|
|
10
|
-
let allLines: { key: string, values: { lang: string, value: string }[] }[] = [];
|
|
11
|
-
for (let file of files) {
|
|
12
|
-
|
|
13
|
-
// parse
|
|
14
|
-
let config = { header: true };
|
|
15
|
-
let content = readFileSync(file, { encoding: "utf-8" });
|
|
16
|
-
let lines = Papa.parse<{ [lang: string]: string }>(content, config).data;
|
|
17
|
-
if (lines.length === 0)
|
|
18
|
-
continue;
|
|
19
|
-
|
|
20
|
-
// Ignore import line
|
|
21
|
-
lines = lines.slice(1);
|
|
22
|
-
|
|
23
|
-
for(let line of lines){
|
|
24
|
-
let masterLine = allLines.find(c => c.key === line.key);
|
|
25
|
-
if(masterLine === undefined){
|
|
26
|
-
masterLine = {
|
|
27
|
-
key: line.key,
|
|
28
|
-
values: []
|
|
29
|
-
};
|
|
30
|
-
allLines.push(masterLine);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
let langs = Object.keys(line).filter(c => c !== 'key');
|
|
34
|
-
for(let lang of langs){
|
|
35
|
-
let value = line[lang];
|
|
36
|
-
if(typeof value === 'string' && value.trim() !== ''){
|
|
37
|
-
if(masterLine.values.find(c => c.lang === lang) === undefined){
|
|
38
|
-
masterLine.values.push({
|
|
39
|
-
lang,
|
|
40
|
-
value
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
else{
|
|
44
|
-
// Duplicate value for language 'lang'
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
for(let line of allLines){
|
|
51
|
-
line.values = line.values.sort((a, b) => a.lang.localeCompare(b.lang));
|
|
52
|
-
}
|
|
53
|
-
allLines = allLines.sort((a, b) => a.key.localeCompare(b.key));
|
|
54
|
-
return allLines;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|