@marsx-dev/launcher 0.0.1 → 0.0.4
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/cli/index.d.ts +4 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +1 -0
- package/dist/cli/init.d.ts +2 -0
- package/dist/cli/init.d.ts.map +1 -0
- package/dist/cli/init.js +67 -36
- package/dist/cli/migrate.d.ts +2 -0
- package/dist/cli/migrate.d.ts.map +1 -0
- package/dist/cli/migrate.js +1 -0
- package/dist/cli/start.d.ts +3 -0
- package/dist/cli/start.d.ts.map +1 -0
- package/dist/cli/start.js +1 -0
- package/dist/configuration.d.ts +24 -0
- package/dist/configuration.d.ts.map +1 -0
- package/dist/configuration.js +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +39 -5
- package/dist/launcher.d.ts +2 -0
- package/dist/launcher.d.ts.map +1 -0
- package/dist/launcher.js +1 -0
- package/dist/loader.d.ts +3 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +1 -0
- package/dist/utils/compile.d.ts +9 -0
- package/dist/utils/compile.d.ts.map +1 -0
- package/dist/utils/compile.js +1 -0
- package/dist/utils/sfc.d.ts +55 -0
- package/dist/utils/sfc.d.ts.map +1 -0
- package/dist/utils/sfc.js +1 -0
- package/dist/utils/utils.d.ts +16 -0
- package/dist/utils/utils.d.ts.map +1 -0
- package/dist/utils/utils.js +1 -0
- package/dist/utils/v3.d.ts +12 -0
- package/dist/utils/v3.d.ts.map +1 -0
- package/dist/utils/v3.js +1 -0
- package/package.json +12 -53
- package/src/cli/index.ts +37 -0
- package/src/cli/init.ts +141 -0
- package/src/cli/migrate.ts +23 -0
- package/src/cli/start.ts +34 -0
- package/src/configuration.ts +53 -0
- package/src/index.ts +5 -0
- package/src/launcher.ts +38 -0
- package/src/loader.ts +65 -0
- package/src/utils/compile.ts +58 -0
- package/src/utils/sfc.ts +178 -0
- package/src/utils/utils.ts +72 -0
- package/src/utils/v3.ts +105 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { promises as fs } from 'fs';
|
|
2
|
+
import _ from 'lodash';
|
|
3
|
+
import { Abortable } from 'node:events';
|
|
4
|
+
import { Mode, ObjectEncodingOptions, OpenMode } from 'node:fs';
|
|
5
|
+
import { Stream } from 'node:stream';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
|
|
8
|
+
export function assert(value: unknown, message = 'value must be defined'): asserts value {
|
|
9
|
+
if (!value) {
|
|
10
|
+
throw new Error(message);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function escapeCloseTag(str: string, tag: string): string {
|
|
15
|
+
return str.replaceAll(`</${tag}>`, `</ ${tag}>`);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function unescapeCloseTag(str: string, tag: string): string {
|
|
19
|
+
return str.replaceAll(`</ ${tag}>`, `</${tag}>`);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function escapeHtmlAttr(str: string): string {
|
|
23
|
+
return str.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function listFilesRecursive(dir: string): Promise<string[]> {
|
|
27
|
+
const entries = await fs.readdir(dir);
|
|
28
|
+
|
|
29
|
+
const files = await Promise.all(
|
|
30
|
+
entries.map(async (entry): Promise<string[]> => {
|
|
31
|
+
const entryPath = path.resolve(dir, entry);
|
|
32
|
+
return (await fs.stat(entryPath)).isDirectory() ? listFilesRecursive(entryPath) : [entryPath];
|
|
33
|
+
}),
|
|
34
|
+
);
|
|
35
|
+
return _.flatten(files);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export async function isFile(filePath: string): Promise<boolean> {
|
|
39
|
+
try {
|
|
40
|
+
return (await fs.stat(filePath)).isFile();
|
|
41
|
+
} catch (e) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export async function isDirectory(dirPath: string): Promise<boolean> {
|
|
47
|
+
try {
|
|
48
|
+
return (await fs.stat(dirPath)).isDirectory();
|
|
49
|
+
} catch (e) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export async function writeFileMakeDir(
|
|
55
|
+
filePath: string,
|
|
56
|
+
data:
|
|
57
|
+
| string
|
|
58
|
+
| NodeJS.ArrayBufferView
|
|
59
|
+
| Iterable<string | NodeJS.ArrayBufferView>
|
|
60
|
+
| AsyncIterable<string | NodeJS.ArrayBufferView>
|
|
61
|
+
| Stream,
|
|
62
|
+
options?:
|
|
63
|
+
| (ObjectEncodingOptions & {
|
|
64
|
+
mode?: Mode | undefined;
|
|
65
|
+
flag?: OpenMode | undefined;
|
|
66
|
+
} & Abortable)
|
|
67
|
+
| BufferEncoding
|
|
68
|
+
| null,
|
|
69
|
+
): Promise<void> {
|
|
70
|
+
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
71
|
+
await fs.writeFile(filePath, data, options);
|
|
72
|
+
}
|
package/src/utils/v3.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { SfcBlock } from './sfc';
|
|
2
|
+
|
|
3
|
+
export type V3MongoBlock = {
|
|
4
|
+
Folder: string;
|
|
5
|
+
Name: string;
|
|
6
|
+
Type: string;
|
|
7
|
+
app?: { name: string };
|
|
8
|
+
} & Record<string, unknown>;
|
|
9
|
+
|
|
10
|
+
const SFC_FIELD_MAP: Record<string, string> = {
|
|
11
|
+
// JSONs
|
|
12
|
+
DataArgs: 'json',
|
|
13
|
+
Page: 'json',
|
|
14
|
+
pages: 'json',
|
|
15
|
+
blocks: 'json',
|
|
16
|
+
Config: 'json',
|
|
17
|
+
langs: 'json',
|
|
18
|
+
// Scripts
|
|
19
|
+
BlockFunction: 'ts',
|
|
20
|
+
Html: 'html',
|
|
21
|
+
HTML: 'html',
|
|
22
|
+
Jsx: 'tsx',
|
|
23
|
+
JsxTranspiled: 'js',
|
|
24
|
+
JsxTranspiledTranspiled: 'js',
|
|
25
|
+
JSX: 'tsx',
|
|
26
|
+
JSXTranspiled: 'js',
|
|
27
|
+
DemoJsx: 'tsx',
|
|
28
|
+
DemoJsxTranspiled: 'js',
|
|
29
|
+
Script: 'ts',
|
|
30
|
+
Css: 'css',
|
|
31
|
+
TestCode: 'ts',
|
|
32
|
+
JestDefinition: 'ts',
|
|
33
|
+
DataForScriptFunction: 'ts',
|
|
34
|
+
// Ignore (part of file path)
|
|
35
|
+
// _id: 'DELETE',
|
|
36
|
+
Name: 'DELETE',
|
|
37
|
+
Type: 'DELETE',
|
|
38
|
+
Folder: 'DELETE',
|
|
39
|
+
// Ignore (will be tracked by git)
|
|
40
|
+
app: 'DELETE',
|
|
41
|
+
Created: 'DELETE',
|
|
42
|
+
LastChanged: 'DELETE',
|
|
43
|
+
createdAt: 'DELETE',
|
|
44
|
+
createdBy: 'DELETE',
|
|
45
|
+
updatedAt: 'DELETE',
|
|
46
|
+
updatedBy: 'DELETE',
|
|
47
|
+
// ... rest of the fields will be saved in metadata
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export function convertV3ToSfc(block: V3MongoBlock): SfcBlock {
|
|
51
|
+
const sfc: SfcBlock = {
|
|
52
|
+
identity: {
|
|
53
|
+
folder: block.Folder,
|
|
54
|
+
name: block.Name,
|
|
55
|
+
blockTypeName: block.Type,
|
|
56
|
+
ext: 'vue',
|
|
57
|
+
fullName: '',
|
|
58
|
+
filePath: '',
|
|
59
|
+
},
|
|
60
|
+
metadata: {},
|
|
61
|
+
jsons: {},
|
|
62
|
+
sources: {},
|
|
63
|
+
rawContent: null,
|
|
64
|
+
};
|
|
65
|
+
for (const [prop, value] of Object.entries(block)) {
|
|
66
|
+
const sfcLang = SFC_FIELD_MAP[prop] || 'METADATA';
|
|
67
|
+
|
|
68
|
+
switch (sfcLang) {
|
|
69
|
+
case 'json':
|
|
70
|
+
if (typeof value !== 'object' && !Array.isArray(value)) throw new Error(`Object or array is expected for ${prop} property`);
|
|
71
|
+
sfc.jsons[prop] = value;
|
|
72
|
+
break;
|
|
73
|
+
case 'DELETE':
|
|
74
|
+
break;
|
|
75
|
+
case 'METADATA':
|
|
76
|
+
sfc.metadata[prop] = value;
|
|
77
|
+
break;
|
|
78
|
+
default:
|
|
79
|
+
if (typeof value !== 'string') throw new Error(`String is expected for ${prop} property`);
|
|
80
|
+
sfc.sources[prop] = { source: value, lang: sfcLang };
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (block.app) {
|
|
86
|
+
sfc.metadata['app'] = { name: block.app.name };
|
|
87
|
+
}
|
|
88
|
+
return sfc;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function convertSfcToV3(sfc: SfcBlock): V3MongoBlock {
|
|
92
|
+
const block: V3MongoBlock = {
|
|
93
|
+
Name: sfc.identity.name,
|
|
94
|
+
Type: sfc.identity.blockTypeName,
|
|
95
|
+
Folder: sfc.identity.folder,
|
|
96
|
+
...sfc.metadata,
|
|
97
|
+
...sfc.jsons,
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
for (const [key, value] of Object.entries(sfc.sources)) {
|
|
101
|
+
block[key] = value.source;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return block;
|
|
105
|
+
}
|