@marsx-dev/launcher 0.0.1
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/LICENSE +201 -0
- package/README.md +5 -0
- package/dist/cli/index.js +40 -0
- package/dist/cli/init.js +98 -0
- package/dist/cli/migrate.js +27 -0
- package/dist/cli/start.js +39 -0
- package/dist/configuration.js +44 -0
- package/dist/index.js +7 -0
- package/dist/launcher.js +38 -0
- package/dist/loader.js +62 -0
- package/dist/utils/compile.js +49 -0
- package/dist/utils/sfc.js +171 -0
- package/dist/utils/utils.js +59 -0
- package/dist/utils/v3.js +97 -0
- package/package.json +117 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.CliError = void 0;
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const commander_1 = require("commander");
|
|
10
|
+
const init_1 = require("./init");
|
|
11
|
+
const migrate_1 = require("./migrate");
|
|
12
|
+
const start_1 = require("./start");
|
|
13
|
+
class CliError extends Error {
|
|
14
|
+
}
|
|
15
|
+
exports.CliError = CliError;
|
|
16
|
+
async function main() {
|
|
17
|
+
try {
|
|
18
|
+
const program = new commander_1.Command();
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
20
|
+
const version = require('../../package.json').version;
|
|
21
|
+
program.name('marsx').description('CLI for MarsX launcher').version(version);
|
|
22
|
+
program.command('start', { isDefault: true }).description('Start MarsX server').action(start_1.start);
|
|
23
|
+
program
|
|
24
|
+
.command('init <project_name>')
|
|
25
|
+
.description('Initialize a new MarsX project named <project_name> in a directory of the same name')
|
|
26
|
+
.action(init_1.initProject);
|
|
27
|
+
program.command('migrate').description('Migrate MarsX V3 project to V4').action(migrate_1.migrateV3ToV4);
|
|
28
|
+
await program.parseAsync();
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
if (e instanceof CliError) {
|
|
32
|
+
console.error(chalk_1.default.red(e.message));
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
console.error(chalk_1.default.red(e));
|
|
36
|
+
}
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
main();
|
package/dist/cli/init.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.initProject = void 0;
|
|
30
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
31
|
+
const child_process_1 = require("child_process");
|
|
32
|
+
const crypto_1 = require("crypto");
|
|
33
|
+
const path_1 = __importDefault(require("path"));
|
|
34
|
+
const util = __importStar(require("util"));
|
|
35
|
+
const utils_1 = require("../utils/utils");
|
|
36
|
+
const index_1 = require("./index");
|
|
37
|
+
const execAsync = util.promisify(child_process_1.exec);
|
|
38
|
+
const DEMO_BOOTER = `<json id="metadata">
|
|
39
|
+
{"version": 4, "restartOnChange": true}
|
|
40
|
+
</json>
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
<script id="BlockFunction" lang="tsx">
|
|
44
|
+
export default async () => {
|
|
45
|
+
console.log('MarsX loaded!')
|
|
46
|
+
};
|
|
47
|
+
</script>`;
|
|
48
|
+
async function initProject(projectName) {
|
|
49
|
+
if (!projectName.match(/^\w+$/) || projectName !== projectName.toLowerCase()) {
|
|
50
|
+
throw new index_1.CliError(`Project name "${projectName}" may contain only lower case alphanumeric characters and underscores (eg. my_project_name)`);
|
|
51
|
+
}
|
|
52
|
+
const projectDir = path_1.default.resolve(projectName);
|
|
53
|
+
if (await (0, utils_1.isDirectory)(projectDir)) {
|
|
54
|
+
throw new index_1.CliError(`Project dir "${projectName}" already exist. Delete it or choose a different name.`);
|
|
55
|
+
}
|
|
56
|
+
console.log(`Creating a new MarsX project in ${chalk_1.default.green(projectDir)}`);
|
|
57
|
+
const packageJson = {
|
|
58
|
+
name: projectName,
|
|
59
|
+
version: '0.0.0',
|
|
60
|
+
private: true,
|
|
61
|
+
scripts: {
|
|
62
|
+
start: 'marsx start',
|
|
63
|
+
},
|
|
64
|
+
dependencies: {
|
|
65
|
+
'@marsx-dev/launcher': '^0.0.1',
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
const packageJsonStr = JSON.stringify(packageJson, null, 2);
|
|
69
|
+
await (0, utils_1.writeFileMakeDir)(path_1.default.join(projectDir, 'package.json'), packageJsonStr);
|
|
70
|
+
const config = {
|
|
71
|
+
production: false,
|
|
72
|
+
port: 3000,
|
|
73
|
+
blocksDir: 'blocks',
|
|
74
|
+
cacheDir: '.cache',
|
|
75
|
+
mongoConn: '<YOUR_MONGO_CONN_STR>',
|
|
76
|
+
mongoDbName: projectName,
|
|
77
|
+
azureStorageConnection: '<CONN_STR>',
|
|
78
|
+
azureStorageAccountName: projectName,
|
|
79
|
+
azureStorageUrl: `https://${projectName}.blob.core.windows.net`,
|
|
80
|
+
webFilesTable: 'webFiles',
|
|
81
|
+
webRecentFilesTable: 'webRecentFiles',
|
|
82
|
+
webFilesBlob: 'web-files',
|
|
83
|
+
secret: (await (0, crypto_1.randomBytes)(48)).toString('hex'),
|
|
84
|
+
importProjects: [{ name: 'mars-ide', url: 'https://ide.marscloud.dev', api_key: '<API_KEY>', git_commit_ish: 'main' }],
|
|
85
|
+
};
|
|
86
|
+
await (0, utils_1.writeFileMakeDir)(path_1.default.join(projectDir, 'config', 'default.json'), JSON.stringify(config, null, 2));
|
|
87
|
+
await (0, utils_1.writeFileMakeDir)(path_1.default.join(projectDir, 'blocks', 'Booter.service.vue'), DEMO_BOOTER);
|
|
88
|
+
console.log('Installing dependencies. This might take a couple of minutes.');
|
|
89
|
+
await execAsync('npm install', { cwd: projectDir });
|
|
90
|
+
await execAsync('git init', { cwd: projectDir });
|
|
91
|
+
await execAsync('git add -A', { cwd: projectDir });
|
|
92
|
+
await execAsync('git commit -m "Initial commit"', { cwd: projectDir });
|
|
93
|
+
console.log('Initialized git repository and created initial commit.');
|
|
94
|
+
console.log(chalk_1.default.yellow(`\nMake sure to update parameters in config/default.json`));
|
|
95
|
+
console.log(`${chalk_1.default.green('Success!')} Created ${projectName} at ${projectDir}`);
|
|
96
|
+
console.log(chalk_1.default.dim(`\nInside that directory, you can start MarsX with\n\n cd ${projectName}\n npm run start\n`));
|
|
97
|
+
}
|
|
98
|
+
exports.initProject = initProject;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.migrateV3ToV4 = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const mongodb_1 = require("mongodb");
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const configuration_1 = require("../configuration");
|
|
11
|
+
const sfc_1 = require("../utils/sfc");
|
|
12
|
+
const utils_1 = require("../utils/utils");
|
|
13
|
+
const v3_1 = require("../utils/v3");
|
|
14
|
+
async function migrateV3ToV4() {
|
|
15
|
+
console.log('Connecting to MongoDB...');
|
|
16
|
+
const mongoConn = await new mongodb_1.MongoClient(configuration_1.config.mongoConn).connect();
|
|
17
|
+
const db = mongoConn.db(configuration_1.config.mongoDbName);
|
|
18
|
+
const allBlocks = await db.collection('blocks').find().toArray();
|
|
19
|
+
console.log(`Downloaded ${allBlocks.length} block(s)`);
|
|
20
|
+
for (const block of allBlocks) {
|
|
21
|
+
const serialized = (0, sfc_1.serializeSfc)((0, v3_1.convertV3ToSfc)(block));
|
|
22
|
+
await (0, utils_1.writeFileMakeDir)(path_1.default.join(configuration_1.config.blocksDir, serialized.filePath), serialized.content);
|
|
23
|
+
console.log(`Saved ${serialized.filePath}`);
|
|
24
|
+
}
|
|
25
|
+
console.log(chalk_1.default.green('\nMigration complete successfully!'));
|
|
26
|
+
}
|
|
27
|
+
exports.migrateV3ToV4 = migrateV3ToV4;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.start = exports.RESTART_EXIT_CODe = void 0;
|
|
7
|
+
const child_process_1 = __importDefault(require("child_process"));
|
|
8
|
+
const configuration_1 = require("../configuration");
|
|
9
|
+
const launcher_1 = require("../launcher");
|
|
10
|
+
const utils_1 = require("../utils/utils");
|
|
11
|
+
exports.RESTART_EXIT_CODe = 9;
|
|
12
|
+
const start = async () => {
|
|
13
|
+
if (configuration_1.config.production || process.env['MARSX_NO_SPAWN']) {
|
|
14
|
+
console.log(`MarsX process ${process.pid} starting...`);
|
|
15
|
+
await (0, launcher_1.launchBooter)();
|
|
16
|
+
console.log(`MarsX process ${process.pid} started`);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
const spawnChildProc = () => {
|
|
20
|
+
(0, utils_1.assert)(process.argv[0]);
|
|
21
|
+
const child = child_process_1.default.spawn(process.argv[0], ['--inspect', '--enable-source-maps', ...process.argv.slice(1)], {
|
|
22
|
+
cwd: process.cwd(),
|
|
23
|
+
env: { ...process.env, MARSX_NO_SPAWN: 'true' },
|
|
24
|
+
stdio: 'inherit',
|
|
25
|
+
});
|
|
26
|
+
child.on('close', (code) => {
|
|
27
|
+
console.log(`MarsX process ${child.pid} terminated with ${code}`);
|
|
28
|
+
if (code === exports.RESTART_EXIT_CODe) {
|
|
29
|
+
setTimeout(spawnChildProc, 100);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
process.exit(code);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
spawnChildProc();
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
exports.start = start;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.config = void 0;
|
|
7
|
+
process.env['SUPPRESS_NO_CONFIG_WARNING'] = 'true';
|
|
8
|
+
const config_1 = __importDefault(require("config"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const utils_1 = require("./utils/utils");
|
|
11
|
+
const ensureType = (typeName) => (configName) => {
|
|
12
|
+
const value = config_1.default.get(configName);
|
|
13
|
+
(0, utils_1.assert)(typeof value === typeName);
|
|
14
|
+
return value;
|
|
15
|
+
};
|
|
16
|
+
const ensureString = ensureType('string');
|
|
17
|
+
const ensureBoolean = ensureType('boolean');
|
|
18
|
+
const ensureNumber = ensureType('number');
|
|
19
|
+
function validatedConfig() {
|
|
20
|
+
if (config_1.default.util.getConfigSources().length === 0) {
|
|
21
|
+
return new Proxy({}, {
|
|
22
|
+
get() {
|
|
23
|
+
throw new Error('Config file not found, ensure you have "config/default.json" file.');
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
production: ensureBoolean('production'),
|
|
29
|
+
port: ensureNumber('port'),
|
|
30
|
+
blocksDir: path_1.default.resolve(ensureString('blocksDir')),
|
|
31
|
+
cacheDir: path_1.default.resolve(ensureString('cacheDir')),
|
|
32
|
+
mongoConn: ensureString('mongoConn'),
|
|
33
|
+
mongoDbName: ensureString('mongoDbName'),
|
|
34
|
+
azureStorageConnection: ensureString('azureStorageConnection'),
|
|
35
|
+
azureStorageAccountName: ensureString('azureStorageAccountName'),
|
|
36
|
+
azureStorageUrl: ensureString('azureStorageUrl'),
|
|
37
|
+
secret: ensureString('secret'),
|
|
38
|
+
webFilesTable: ensureString('webFilesTable'),
|
|
39
|
+
webRecentFilesTable: ensureString('webRecentFilesTable'),
|
|
40
|
+
webFilesBlob: ensureString('webFilesBlob'),
|
|
41
|
+
importProjects: config_1.default.get('importProjects'),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
exports.config = validatedConfig();
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.migrateV3ToV4 = exports.start = void 0;
|
|
4
|
+
var start_1 = require("./cli/start");
|
|
5
|
+
Object.defineProperty(exports, "start", { enumerable: true, get: function () { return start_1.start; } });
|
|
6
|
+
var migrate_1 = require("./cli/migrate");
|
|
7
|
+
Object.defineProperty(exports, "migrateV3ToV4", { enumerable: true, get: function () { return migrate_1.migrateV3ToV4; } });
|
package/dist/launcher.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.launchBooter = void 0;
|
|
4
|
+
const configuration_1 = require("./configuration");
|
|
5
|
+
const loader_1 = require("./loader");
|
|
6
|
+
const compile_1 = require("./utils/compile");
|
|
7
|
+
const sfc_1 = require("./utils/sfc");
|
|
8
|
+
const utils_1 = require("./utils/utils");
|
|
9
|
+
const v3_1 = require("./utils/v3");
|
|
10
|
+
const LAUNCHER_UTILS = {
|
|
11
|
+
config: configuration_1.config,
|
|
12
|
+
parseSFC: sfc_1.parseSFC,
|
|
13
|
+
serializeSfc: sfc_1.serializeSfc,
|
|
14
|
+
convertV3ToSfc: v3_1.convertV3ToSfc,
|
|
15
|
+
convertSfcToV3: v3_1.convertSfcToV3,
|
|
16
|
+
transpileTypescript: compile_1.transpileTypescript,
|
|
17
|
+
compileSfcSource: compile_1.compileSfcSource,
|
|
18
|
+
writeFileMakeDir: utils_1.writeFileMakeDir,
|
|
19
|
+
};
|
|
20
|
+
async function launchBooter(booterBlockName = 'Booter') {
|
|
21
|
+
const allBlocks = await (0, loader_1.loadAllBlocks)();
|
|
22
|
+
const booterBlocks = allBlocks.filter(b => b.identity.name === booterBlockName);
|
|
23
|
+
if (booterBlocks.length === 0)
|
|
24
|
+
throw new Error(`Booter block ${booterBlockName} not found. Ensure you have it locally or it is imported.`);
|
|
25
|
+
// Take last because order of imports matter and local blocks always override imported.
|
|
26
|
+
const booterBlock = booterBlocks[booterBlocks.length - 1];
|
|
27
|
+
(0, utils_1.assert)(booterBlock);
|
|
28
|
+
const compiledBooterPath = await (0, compile_1.compileSfcSource)(booterBlock, 'BlockFunction');
|
|
29
|
+
try {
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
31
|
+
await require(compiledBooterPath).default(allBlocks, LAUNCHER_UTILS);
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
console.error('Booter failed with:', e);
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.launchBooter = launchBooter;
|
package/dist/loader.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.loadAllBlocks = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
9
|
+
const fs_1 = require("fs");
|
|
10
|
+
const json_stable_stringify_1 = __importDefault(require("json-stable-stringify"));
|
|
11
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
12
|
+
const path_1 = __importDefault(require("path"));
|
|
13
|
+
const configuration_1 = require("./configuration");
|
|
14
|
+
const sfc_1 = require("./utils/sfc");
|
|
15
|
+
const utils_1 = require("./utils/utils");
|
|
16
|
+
const v3_1 = require("./utils/v3");
|
|
17
|
+
async function downloadFromExternal(externalImport) {
|
|
18
|
+
const params = { api_key: externalImport.api_key, git_commit_ish: externalImport.git_commit_ish || '' };
|
|
19
|
+
console.log(`Downloading blocks from ${externalImport.url}`);
|
|
20
|
+
try {
|
|
21
|
+
const v4Resp = await axios_1.default.get(`${externalImport.url}/api/GetExportedAppBlocksV4`, { params });
|
|
22
|
+
return v4Resp.data;
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
console.log(`${externalImport.url} does not support V4, fallback to V3`);
|
|
26
|
+
}
|
|
27
|
+
const v3Resp = await axios_1.default.get(`${externalImport.url}/api/GetExportedAppBlocks`, { params });
|
|
28
|
+
return v3Resp.data.map(b => (0, v3_1.convertV3ToSfc)(b));
|
|
29
|
+
}
|
|
30
|
+
async function loadCachedOrDownload(externalImport) {
|
|
31
|
+
const hash = crypto_1.default.createHash('md5').update((0, json_stable_stringify_1.default)(externalImport)).digest('hex');
|
|
32
|
+
const cacheFileName = `${externalImport.name}_${externalImport.git_commit_ish}_${hash}.json`.replace(/[^\w.]+/g, '_');
|
|
33
|
+
const cacheFilePath = path_1.default.join(configuration_1.config.cacheDir, 'imports', cacheFileName);
|
|
34
|
+
if (await (0, utils_1.isFile)(cacheFilePath)) {
|
|
35
|
+
const content = await fs_1.promises.readFile(cacheFilePath);
|
|
36
|
+
console.log(`Loading cached blocks from ${externalImport.url}`);
|
|
37
|
+
return JSON.parse(content.toString('utf-8'));
|
|
38
|
+
}
|
|
39
|
+
const data = await downloadFromExternal(externalImport);
|
|
40
|
+
console.log(`Downloaded ${data.length} blocks from ${externalImport.url}`);
|
|
41
|
+
await (0, utils_1.writeFileMakeDir)(cacheFilePath, JSON.stringify(data, null, 2), 'utf-8');
|
|
42
|
+
return data;
|
|
43
|
+
}
|
|
44
|
+
async function downloadAll(externalImports) {
|
|
45
|
+
const responses = await Promise.all(externalImports.map(loadCachedOrDownload));
|
|
46
|
+
return lodash_1.default.flatten(responses);
|
|
47
|
+
}
|
|
48
|
+
async function readBlockFile(blocksDir, filePath) {
|
|
49
|
+
const content = await fs_1.promises.readFile(filePath);
|
|
50
|
+
const relPath = path_1.default.relative(blocksDir, filePath);
|
|
51
|
+
return (0, sfc_1.parseSFC)(relPath, content);
|
|
52
|
+
}
|
|
53
|
+
async function readBlockFiles(blocksDir) {
|
|
54
|
+
const files = await (0, utils_1.listFilesRecursive)(blocksDir);
|
|
55
|
+
return await Promise.all(files.filter(f => !path_1.default.basename(f).startsWith('.')).map(f => readBlockFile(blocksDir, f)));
|
|
56
|
+
}
|
|
57
|
+
async function loadAllBlocks() {
|
|
58
|
+
const externalBlocks = await downloadAll(configuration_1.config.importProjects);
|
|
59
|
+
const localBlocks = await readBlockFiles(configuration_1.config.blocksDir);
|
|
60
|
+
return [...externalBlocks, ...localBlocks];
|
|
61
|
+
}
|
|
62
|
+
exports.loadAllBlocks = loadAllBlocks;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.compileSfcSource = exports.transpileTypescript = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
9
|
+
const configuration_1 = require("../configuration");
|
|
10
|
+
const utils_1 = require("./utils");
|
|
11
|
+
function genSourceMapComment(sourceMap) {
|
|
12
|
+
return `\n//# sourceMappingURL=data:application/json;base64,${Buffer.from(JSON.stringify(sourceMap)).toString('base64')}`;
|
|
13
|
+
}
|
|
14
|
+
function transpileTypescript(sourceCode, options) {
|
|
15
|
+
const compiledFilePath = options?.compiledFilePath || '<UNKNOWN>.js';
|
|
16
|
+
const originalFilePath = options?.originalFilePath || '<UNKNOWN>.ts';
|
|
17
|
+
if (options?.lineOffset) {
|
|
18
|
+
sourceCode = '\n'.repeat(options.lineOffset) + sourceCode;
|
|
19
|
+
}
|
|
20
|
+
const transpiled = typescript_1.default.transpileModule(sourceCode, {
|
|
21
|
+
compilerOptions: {
|
|
22
|
+
module: typescript_1.default.ModuleKind.CommonJS,
|
|
23
|
+
target: typescript_1.default.ScriptTarget.Latest,
|
|
24
|
+
esModuleInterop: true,
|
|
25
|
+
sourceMap: true,
|
|
26
|
+
// inlineSources: true,
|
|
27
|
+
// inlineSourceMap: true,
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
(0, utils_1.assert)(transpiled.sourceMapText);
|
|
31
|
+
const sourceMap = JSON.parse(transpiled.sourceMapText);
|
|
32
|
+
sourceMap.sourceRoot = options?.sourceRoot || '';
|
|
33
|
+
sourceMap.file = compiledFilePath;
|
|
34
|
+
sourceMap.sources = [originalFilePath];
|
|
35
|
+
const sourceMapComment = genSourceMapComment(sourceMap);
|
|
36
|
+
return transpiled.outputText.replace(/\n\/\/# sourceMappingURL=.+/, '') + sourceMapComment;
|
|
37
|
+
}
|
|
38
|
+
exports.transpileTypescript = transpileTypescript;
|
|
39
|
+
async function compileSfcSource(sfcBlock, sourceId) {
|
|
40
|
+
const sourceCode = sfcBlock.sources[sourceId];
|
|
41
|
+
if (!sourceCode)
|
|
42
|
+
throw new Error(`Source code block ${sourceId} not found in ${sfcBlock.identity.filePath}`);
|
|
43
|
+
const compiledFilePath = path_1.default.join(configuration_1.config.cacheDir, 'compiled', `${sfcBlock.identity.filePath}.${sourceId}.js`);
|
|
44
|
+
const originalFilePath = path_1.default.join(configuration_1.config.blocksDir, sfcBlock.identity.filePath);
|
|
45
|
+
const code = transpileTypescript(sourceCode.source, { compiledFilePath, originalFilePath, lineOffset: sourceCode.lineOffset });
|
|
46
|
+
await (0, utils_1.writeFileMakeDir)(compiledFilePath, code, 'utf-8');
|
|
47
|
+
return compiledFilePath;
|
|
48
|
+
}
|
|
49
|
+
exports.compileSfcSource = compileSfcSource;
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.serializeSfc = exports.parseSFC = exports.serializeSfcIdentity = exports.parseSfcIdentity = exports.SFC_EXT = exports.METADATA = void 0;
|
|
30
|
+
const CompilerDOM = __importStar(require("@vue/compiler-dom"));
|
|
31
|
+
const json_stable_stringify_1 = __importDefault(require("json-stable-stringify"));
|
|
32
|
+
const json5_1 = __importDefault(require("json5"));
|
|
33
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
34
|
+
const path_1 = __importDefault(require("path"));
|
|
35
|
+
const prettier_1 = __importDefault(require("prettier"));
|
|
36
|
+
const utils_1 = require("./utils");
|
|
37
|
+
exports.METADATA = 'metadata';
|
|
38
|
+
exports.SFC_EXT = 'vue';
|
|
39
|
+
const SAVE_EMPTY_SOURCES = true;
|
|
40
|
+
function parseSfcIdentity(filePath) {
|
|
41
|
+
// Blog/BlogPost.page.vue => {id: "BlogPost.page", folder:"Blog", name: "BlogPost", blockTypeName: "page", ext: "vue", fullName: "Blog.BlogPost"}
|
|
42
|
+
const originalParsed = path_1.default.parse(filePath);
|
|
43
|
+
const withoutExt = originalParsed.name;
|
|
44
|
+
const ext = originalParsed.ext.slice(1);
|
|
45
|
+
const parsed = path_1.default.parse(withoutExt);
|
|
46
|
+
if (!parsed.name || !parsed.ext)
|
|
47
|
+
throw new Error(`Invalid block file path: ${filePath}`);
|
|
48
|
+
const blockTypeName = parsed.ext.slice(1);
|
|
49
|
+
const namespace = originalParsed.dir.replace(/\//g, '.');
|
|
50
|
+
const fullName = namespace.length > 0 ? `${namespace}.${parsed.name}` : parsed.name;
|
|
51
|
+
return {
|
|
52
|
+
folder: originalParsed.dir,
|
|
53
|
+
name: parsed.name,
|
|
54
|
+
blockTypeName,
|
|
55
|
+
ext,
|
|
56
|
+
fullName,
|
|
57
|
+
filePath,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
exports.parseSfcIdentity = parseSfcIdentity;
|
|
61
|
+
function serializeSfcIdentity(identity) {
|
|
62
|
+
return path_1.default.join(identity.folder, `${identity.name}.${identity.blockTypeName}.${identity.ext}`);
|
|
63
|
+
}
|
|
64
|
+
exports.serializeSfcIdentity = serializeSfcIdentity;
|
|
65
|
+
const LANG_TAG_MAP = {
|
|
66
|
+
html: 'html',
|
|
67
|
+
pug: 'template',
|
|
68
|
+
js: 'script',
|
|
69
|
+
jsx: 'script',
|
|
70
|
+
ts: 'script',
|
|
71
|
+
tsx: 'script',
|
|
72
|
+
css: 'style',
|
|
73
|
+
scss: 'style',
|
|
74
|
+
less: 'style',
|
|
75
|
+
sass: 'style',
|
|
76
|
+
stylus: 'style',
|
|
77
|
+
text: 'text',
|
|
78
|
+
};
|
|
79
|
+
function getNodeAttr(node, attr) {
|
|
80
|
+
return node.props.map(p => (p.name == attr && p.type === 6 /* ATTRIBUTE */ ? p.value?.content : undefined)).find(p => !!p);
|
|
81
|
+
}
|
|
82
|
+
function parseSFC(filePath, content) {
|
|
83
|
+
const identity = parseSfcIdentity(filePath);
|
|
84
|
+
if (identity.ext !== exports.SFC_EXT) {
|
|
85
|
+
return { identity, metadata: {}, jsons: {}, sources: {}, rawContent: content };
|
|
86
|
+
}
|
|
87
|
+
const errors = [];
|
|
88
|
+
const ast = CompilerDOM.parse(content.toString('utf-8'), {
|
|
89
|
+
// there are no components at SFC parsing level
|
|
90
|
+
isNativeTag: () => true,
|
|
91
|
+
// preserve all whitespaces
|
|
92
|
+
isPreTag: () => true,
|
|
93
|
+
getTextMode: () => 2 /* RAWTEXT */,
|
|
94
|
+
onError: e => errors.push(e),
|
|
95
|
+
});
|
|
96
|
+
const block = {
|
|
97
|
+
identity: parseSfcIdentity(filePath),
|
|
98
|
+
metadata: {},
|
|
99
|
+
jsons: {},
|
|
100
|
+
sources: {},
|
|
101
|
+
rawContent: null,
|
|
102
|
+
};
|
|
103
|
+
const seenIds = new Set();
|
|
104
|
+
ast.children.forEach(node => {
|
|
105
|
+
if (node.type === 1 /* ELEMENT */) {
|
|
106
|
+
const child = node.children.length === 1 ? node.children[0] : null;
|
|
107
|
+
const content = child && child.type === 2 /* TEXT */ ? child.content : null;
|
|
108
|
+
if (content) {
|
|
109
|
+
const sectionId = getNodeAttr(node, 'id');
|
|
110
|
+
if (!sectionId) {
|
|
111
|
+
errors.push({ name: `missing-id`, message: `Id property is missing`, code: 0, loc: node.loc });
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (seenIds.has(sectionId)) {
|
|
115
|
+
errors.push({ name: `duplicate-id`, message: `Duplicate section id: ${sectionId}`, code: 0, loc: node.loc });
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
seenIds.add(sectionId);
|
|
119
|
+
if (node.tag === 'json') {
|
|
120
|
+
try {
|
|
121
|
+
const jsonData = json5_1.default.parse(content);
|
|
122
|
+
if (sectionId === exports.METADATA) {
|
|
123
|
+
block.metadata = jsonData;
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
block.jsons[sectionId] = jsonData;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
catch (e) {
|
|
130
|
+
errors.push({ name: 'invalid-json', message: `${e}`, code: 0, loc: node.loc });
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
const source = (0, utils_1.unescapeCloseTag)(content.slice(1, -1), node.tag);
|
|
135
|
+
const lang = getNodeAttr(node, 'lang');
|
|
136
|
+
const lineOffset = node.loc.start.line;
|
|
137
|
+
block.sources[sectionId] = { source, lang, lineOffset };
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
if (errors.length) {
|
|
143
|
+
throw new Error(`Parsing SFC ${filePath} failed with ${JSON.stringify(errors)}`);
|
|
144
|
+
}
|
|
145
|
+
return block;
|
|
146
|
+
}
|
|
147
|
+
exports.parseSFC = parseSFC;
|
|
148
|
+
const PRETTIER_JSON_CONFIG = { parser: 'json5', printWidth: 120, trailingComma: 'all' };
|
|
149
|
+
function serializeSfc(block) {
|
|
150
|
+
const filePath = serializeSfcIdentity(block.identity);
|
|
151
|
+
if (block.identity.ext !== exports.SFC_EXT) {
|
|
152
|
+
if (block.rawContent === null)
|
|
153
|
+
throw new Error(`SfcBlock must have rawContent if ext!="${exports.SFC_EXT}"`);
|
|
154
|
+
return { filePath, content: block.rawContent };
|
|
155
|
+
}
|
|
156
|
+
if (block.rawContent !== null)
|
|
157
|
+
throw new Error(`SfcBlock cannot have rawContent if ext=="${exports.SFC_EXT}"`);
|
|
158
|
+
let content = '';
|
|
159
|
+
for (const [name, source] of [[exports.METADATA, block.metadata], ...lodash_1.default.sortBy(Object.entries(block.jsons), e => e[0])]) {
|
|
160
|
+
const jsonStr = prettier_1.default.format('(' + (0, json_stable_stringify_1.default)(source) + ')', PRETTIER_JSON_CONFIG);
|
|
161
|
+
content += `<json id="${(0, utils_1.escapeHtmlAttr)(name)}">\n${jsonStr}</json>\n\n`;
|
|
162
|
+
}
|
|
163
|
+
for (const [name, source] of lodash_1.default.sortBy(Object.entries(block.sources), e => e[0])) {
|
|
164
|
+
if (!SAVE_EMPTY_SOURCES && !source.source.trim())
|
|
165
|
+
continue;
|
|
166
|
+
const tag = LANG_TAG_MAP[source.lang || ''] || 'script';
|
|
167
|
+
content += `<${tag} id="${(0, utils_1.escapeHtmlAttr)(name)}" lang="${source.lang}">\n${(0, utils_1.escapeCloseTag)(source.source, tag)}\n</${tag}>\n\n`;
|
|
168
|
+
}
|
|
169
|
+
return { filePath, content: Buffer.from(content, 'utf-8') };
|
|
170
|
+
}
|
|
171
|
+
exports.serializeSfc = serializeSfc;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.writeFileMakeDir = exports.isDirectory = exports.isFile = exports.listFilesRecursive = exports.escapeHtmlAttr = exports.unescapeCloseTag = exports.escapeCloseTag = exports.assert = void 0;
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
function assert(value, message = 'value must be defined') {
|
|
11
|
+
if (!value) {
|
|
12
|
+
throw new Error(message);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.assert = assert;
|
|
16
|
+
function escapeCloseTag(str, tag) {
|
|
17
|
+
return str.replaceAll(`</${tag}>`, `</ ${tag}>`);
|
|
18
|
+
}
|
|
19
|
+
exports.escapeCloseTag = escapeCloseTag;
|
|
20
|
+
function unescapeCloseTag(str, tag) {
|
|
21
|
+
return str.replaceAll(`</ ${tag}>`, `</${tag}>`);
|
|
22
|
+
}
|
|
23
|
+
exports.unescapeCloseTag = unescapeCloseTag;
|
|
24
|
+
function escapeHtmlAttr(str) {
|
|
25
|
+
return str.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
26
|
+
}
|
|
27
|
+
exports.escapeHtmlAttr = escapeHtmlAttr;
|
|
28
|
+
async function listFilesRecursive(dir) {
|
|
29
|
+
const entries = await fs_1.promises.readdir(dir);
|
|
30
|
+
const files = await Promise.all(entries.map(async (entry) => {
|
|
31
|
+
const entryPath = path_1.default.resolve(dir, entry);
|
|
32
|
+
return (await fs_1.promises.stat(entryPath)).isDirectory() ? listFilesRecursive(entryPath) : [entryPath];
|
|
33
|
+
}));
|
|
34
|
+
return lodash_1.default.flatten(files);
|
|
35
|
+
}
|
|
36
|
+
exports.listFilesRecursive = listFilesRecursive;
|
|
37
|
+
async function isFile(filePath) {
|
|
38
|
+
try {
|
|
39
|
+
return (await fs_1.promises.stat(filePath)).isFile();
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.isFile = isFile;
|
|
46
|
+
async function isDirectory(dirPath) {
|
|
47
|
+
try {
|
|
48
|
+
return (await fs_1.promises.stat(dirPath)).isDirectory();
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.isDirectory = isDirectory;
|
|
55
|
+
async function writeFileMakeDir(filePath, data, options) {
|
|
56
|
+
await fs_1.promises.mkdir(path_1.default.dirname(filePath), { recursive: true });
|
|
57
|
+
await fs_1.promises.writeFile(filePath, data, options);
|
|
58
|
+
}
|
|
59
|
+
exports.writeFileMakeDir = writeFileMakeDir;
|
package/dist/utils/v3.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertSfcToV3 = exports.convertV3ToSfc = void 0;
|
|
4
|
+
const SFC_FIELD_MAP = {
|
|
5
|
+
// JSONs
|
|
6
|
+
DataArgs: 'json',
|
|
7
|
+
Page: 'json',
|
|
8
|
+
pages: 'json',
|
|
9
|
+
blocks: 'json',
|
|
10
|
+
Config: 'json',
|
|
11
|
+
langs: 'json',
|
|
12
|
+
// Scripts
|
|
13
|
+
BlockFunction: 'ts',
|
|
14
|
+
Html: 'html',
|
|
15
|
+
HTML: 'html',
|
|
16
|
+
Jsx: 'tsx',
|
|
17
|
+
JsxTranspiled: 'js',
|
|
18
|
+
JsxTranspiledTranspiled: 'js',
|
|
19
|
+
JSX: 'tsx',
|
|
20
|
+
JSXTranspiled: 'js',
|
|
21
|
+
DemoJsx: 'tsx',
|
|
22
|
+
DemoJsxTranspiled: 'js',
|
|
23
|
+
Script: 'ts',
|
|
24
|
+
Css: 'css',
|
|
25
|
+
TestCode: 'ts',
|
|
26
|
+
JestDefinition: 'ts',
|
|
27
|
+
DataForScriptFunction: 'ts',
|
|
28
|
+
// Ignore (part of file path)
|
|
29
|
+
// _id: 'DELETE',
|
|
30
|
+
Name: 'DELETE',
|
|
31
|
+
Type: 'DELETE',
|
|
32
|
+
Folder: 'DELETE',
|
|
33
|
+
// Ignore (will be tracked by git)
|
|
34
|
+
app: 'DELETE',
|
|
35
|
+
Created: 'DELETE',
|
|
36
|
+
LastChanged: 'DELETE',
|
|
37
|
+
createdAt: 'DELETE',
|
|
38
|
+
createdBy: 'DELETE',
|
|
39
|
+
updatedAt: 'DELETE',
|
|
40
|
+
updatedBy: 'DELETE',
|
|
41
|
+
// ... rest of the fields will be saved in metadata
|
|
42
|
+
};
|
|
43
|
+
function convertV3ToSfc(block) {
|
|
44
|
+
const sfc = {
|
|
45
|
+
identity: {
|
|
46
|
+
folder: block.Folder,
|
|
47
|
+
name: block.Name,
|
|
48
|
+
blockTypeName: block.Type,
|
|
49
|
+
ext: 'vue',
|
|
50
|
+
fullName: '',
|
|
51
|
+
filePath: '',
|
|
52
|
+
},
|
|
53
|
+
metadata: {},
|
|
54
|
+
jsons: {},
|
|
55
|
+
sources: {},
|
|
56
|
+
rawContent: null,
|
|
57
|
+
};
|
|
58
|
+
for (const [prop, value] of Object.entries(block)) {
|
|
59
|
+
const sfcLang = SFC_FIELD_MAP[prop] || 'METADATA';
|
|
60
|
+
switch (sfcLang) {
|
|
61
|
+
case 'json':
|
|
62
|
+
if (typeof value !== 'object' && !Array.isArray(value))
|
|
63
|
+
throw new Error(`Object or array is expected for ${prop} property`);
|
|
64
|
+
sfc.jsons[prop] = value;
|
|
65
|
+
break;
|
|
66
|
+
case 'DELETE':
|
|
67
|
+
break;
|
|
68
|
+
case 'METADATA':
|
|
69
|
+
sfc.metadata[prop] = value;
|
|
70
|
+
break;
|
|
71
|
+
default:
|
|
72
|
+
if (typeof value !== 'string')
|
|
73
|
+
throw new Error(`String is expected for ${prop} property`);
|
|
74
|
+
sfc.sources[prop] = { source: value, lang: sfcLang };
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (block.app) {
|
|
79
|
+
sfc.metadata['app'] = { name: block.app.name };
|
|
80
|
+
}
|
|
81
|
+
return sfc;
|
|
82
|
+
}
|
|
83
|
+
exports.convertV3ToSfc = convertV3ToSfc;
|
|
84
|
+
function convertSfcToV3(sfc) {
|
|
85
|
+
const block = {
|
|
86
|
+
Name: sfc.identity.name,
|
|
87
|
+
Type: sfc.identity.blockTypeName,
|
|
88
|
+
Folder: sfc.identity.folder,
|
|
89
|
+
...sfc.metadata,
|
|
90
|
+
...sfc.jsons,
|
|
91
|
+
};
|
|
92
|
+
for (const [key, value] of Object.entries(sfc.sources)) {
|
|
93
|
+
block[key] = value.source;
|
|
94
|
+
}
|
|
95
|
+
return block;
|
|
96
|
+
}
|
|
97
|
+
exports.convertSfcToV3 = convertSfcToV3;
|
package/package.json
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@marsx-dev/launcher",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "MarsX launcher",
|
|
5
|
+
"author": "MarsX team <team@marsx.dev>",
|
|
6
|
+
"homepage": "https://marsx.dev/",
|
|
7
|
+
"license": "Apache-2.0",
|
|
8
|
+
"repository": "github:marsx/launcher",
|
|
9
|
+
"keywords": [
|
|
10
|
+
"marsx",
|
|
11
|
+
"lowcode",
|
|
12
|
+
"nocode",
|
|
13
|
+
"editor",
|
|
14
|
+
"ide"
|
|
15
|
+
],
|
|
16
|
+
"engineStrict": true,
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=16.0.0"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"LICENSE",
|
|
23
|
+
"README.md"
|
|
24
|
+
],
|
|
25
|
+
"bin": {
|
|
26
|
+
"marsx": "./dist/cli/index.js"
|
|
27
|
+
},
|
|
28
|
+
"main": "./dist/index.js",
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"scripts": {
|
|
31
|
+
"validate": "npm run validate:prettier && npm run validate:lint && npm run validate:tsc",
|
|
32
|
+
"validate:prettier": "prettier --ignore-path=.gitignore --list-different \"**/*.+(js|ts|json)\"",
|
|
33
|
+
"validate:lint": "eslint --ignore-path=.gitignore --ext=.js,.ts .",
|
|
34
|
+
"validate:tsc": "tsc --noEmit",
|
|
35
|
+
"fix": "npm run fix:prettier && npm run fix:list",
|
|
36
|
+
"fix:prettier": "prettier --ignore-path=.gitignore --write \"**/*.+(js|ts|json)\"",
|
|
37
|
+
"fix:list": "eslint --ignore-path=.gitignore --ext=.js,.ts --fix .",
|
|
38
|
+
"build": "tsc"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@vue/compiler-sfc": "^3.2.29",
|
|
42
|
+
"axios": "^0.26.1",
|
|
43
|
+
"chalk": "^4.1.2",
|
|
44
|
+
"commander": "^9.1.0",
|
|
45
|
+
"config": "^3.3.7",
|
|
46
|
+
"json-stable-stringify": "^1.0.1",
|
|
47
|
+
"json5": "^2.2.0",
|
|
48
|
+
"lodash": "^4.17.21",
|
|
49
|
+
"mongodb": "^4.3.1",
|
|
50
|
+
"prettier": "^2.5.1",
|
|
51
|
+
"typescript": "^4.5.5"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"@fastify/session": "^6.4.0",
|
|
55
|
+
"@stitches/core": "^1.2.6",
|
|
56
|
+
"@types/accepts": "^1.3.5",
|
|
57
|
+
"@types/bcrypt": "^5.0.0",
|
|
58
|
+
"@types/mkdirp": "^1.0.2",
|
|
59
|
+
"@types/nodegit": "^0.27.9",
|
|
60
|
+
"@types/sharp": "^0.29.5",
|
|
61
|
+
"@types/uuid": "^8.3.4",
|
|
62
|
+
"@types/ws": "^8.5.2",
|
|
63
|
+
"aws-sdk": "^2.1073.0",
|
|
64
|
+
"azure-storage": "^2.10.7",
|
|
65
|
+
"babel-core": "^6.26.3",
|
|
66
|
+
"babel-plugin-transform-react-jsx": "^6.24.1",
|
|
67
|
+
"base-x": "^4.0.0",
|
|
68
|
+
"bcrypt": "^5.0.1",
|
|
69
|
+
"chokidar": "^3.5.3",
|
|
70
|
+
"dotenv": "^16.0.0",
|
|
71
|
+
"fastify": "^3.27.2",
|
|
72
|
+
"fastify-accepts": "^2.1.0",
|
|
73
|
+
"fastify-compress": "^4.0.1",
|
|
74
|
+
"fastify-cookie": "^5.6.0",
|
|
75
|
+
"fastify-cors": "^6.0.3",
|
|
76
|
+
"fastify-csrf": "^3.1.0",
|
|
77
|
+
"fastify-flash": "^2.0.2",
|
|
78
|
+
"fastify-formbody": "^5.2.0",
|
|
79
|
+
"fastify-helmet": "^7.0.1",
|
|
80
|
+
"fastify-multipart": "^5.3.1",
|
|
81
|
+
"fastify-request-context": "^2.2.0",
|
|
82
|
+
"fastify-static": "^4.5.0",
|
|
83
|
+
"fastify-websocket": "^4.2.0",
|
|
84
|
+
"fontverter": "^2.0.0",
|
|
85
|
+
"jsonwebtoken": "^8.5.1",
|
|
86
|
+
"mobile-detect": "^1.4.5",
|
|
87
|
+
"moment-timezone": "^0.5.34",
|
|
88
|
+
"nodegit": "^0.28.0-alpha.10",
|
|
89
|
+
"route-pattern": "^0.0.6",
|
|
90
|
+
"route-sort": "^1.0.0",
|
|
91
|
+
"sharp": "^0.30.1",
|
|
92
|
+
"source-map": "^0.7.3",
|
|
93
|
+
"subset-font": "^1.4.0",
|
|
94
|
+
"uuid": "^8.3.2",
|
|
95
|
+
"xxhash": "^0.3.0"
|
|
96
|
+
},
|
|
97
|
+
"devDependencies": {
|
|
98
|
+
"@types/config": "^0.0.41",
|
|
99
|
+
"@types/json-stable-stringify": "^1.0.34",
|
|
100
|
+
"@types/lodash": "^4.14.178",
|
|
101
|
+
"@types/node": "^17.0.21",
|
|
102
|
+
"@types/prettier": "^2.4.4",
|
|
103
|
+
"@typescript-eslint/eslint-plugin": "^5.10.2",
|
|
104
|
+
"@typescript-eslint/parser": "^5.10.2",
|
|
105
|
+
"eslint": "^8.8.0",
|
|
106
|
+
"eslint-config-prettier": "^8.3.0",
|
|
107
|
+
"eslint-plugin-prettier": "^4.0.0"
|
|
108
|
+
},
|
|
109
|
+
"prettier": {
|
|
110
|
+
"printWidth": 140,
|
|
111
|
+
"tabWidth": 2,
|
|
112
|
+
"endOfLine": "lf",
|
|
113
|
+
"singleQuote": true,
|
|
114
|
+
"trailingComma": "all",
|
|
115
|
+
"arrowParens": "avoid"
|
|
116
|
+
}
|
|
117
|
+
}
|