@pega/custom-dx-components 0.25.25 → 0.25.27
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 +1 -1
- package/src/constants.js +2 -0
- package/src/tasks/create-lib/index.js +89 -1
- package/src/tasks/create-version/index.js +68 -21
- package/src/tasks/delete-lib/index.js +43 -15
- package/src/tasks/delete-version/index.js +37 -9
- package/src/tasks/import-archive/index.js +144 -102
- package/src/tasks/import-comp/index.js +33 -14
- package/src/tasks/init/template/package.json.mustache +2 -7
- package/src/tasks/publish/index.js +37 -11
- package/src/tasks/set-perm/index.js +15 -2
- package/src/tasks/switch-lib/index.js +89 -36
- package/src/tasks/switch-version/index.js +74 -14
- package/src/util.js +77 -4
- package/src/tasks/init/template/scripts/components.json +0 -3
- package/src/tasks/init/template/scripts/esbuild.dev.js +0 -34
- package/src/tasks/init/template/scripts/index.mustache +0 -26
- package/src/tasks/init/template/scripts/index.ts +0 -1
- package/src/tasks/init/template/scripts/main.js +0 -75
|
@@ -17,7 +17,12 @@ import {
|
|
|
17
17
|
forceDefaultsUpdate,
|
|
18
18
|
getHaveDependencyDifference,
|
|
19
19
|
cleanUpTemp,
|
|
20
|
-
getLibraryArchiveDirectories
|
|
20
|
+
getLibraryArchiveDirectories,
|
|
21
|
+
getUseInputConfig,
|
|
22
|
+
getInputConfigForCommand,
|
|
23
|
+
convertYNToBoolean,
|
|
24
|
+
hasArchives,
|
|
25
|
+
getLibraryBasedCL
|
|
21
26
|
} from '../../util.js';
|
|
22
27
|
|
|
23
28
|
import { getSwitchLibraryComponentQuestions, getSwitchVersionComponentQuestions } from './helper.js';
|
|
@@ -27,6 +32,10 @@ import { arch } from 'os';
|
|
|
27
32
|
|
|
28
33
|
export default async options => {
|
|
29
34
|
const isLibraryBased = getLibraryBased();
|
|
35
|
+
const isLibraryBasedCL = getLibraryBasedCL();
|
|
36
|
+
|
|
37
|
+
const useInputConfig = getUseInputConfig();
|
|
38
|
+
|
|
30
39
|
if (!isLibraryBased) {
|
|
31
40
|
console.log(`Command only supported for ${chalk.bold.green('library mode')} components.`);
|
|
32
41
|
process.exit();
|
|
@@ -47,58 +56,102 @@ addDebugLog("switchLibrary", "", "+");
|
|
|
47
56
|
|
|
48
57
|
const currentDirectory = process.cwd();
|
|
49
58
|
const componentDirectory = join (currentDirectory, "src", "components");
|
|
59
|
+
const orgLib = getConfigDefaults();
|
|
50
60
|
|
|
51
|
-
//
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
61
|
+
// if we have choosen to use INPUT CONFIG FILE
|
|
62
|
+
// process and no inputs
|
|
63
|
+
if (useInputConfig) {
|
|
64
|
+
const inputConfig = await getInputConfigForCommand("switchLib");
|
|
65
|
+
|
|
66
|
+
if (convertYNToBoolean(inputConfig.okToContinue)) {
|
|
67
|
+
const newLibraryName = inputConfig.libraryName;
|
|
68
|
+
newOrgLib = `${orgLib.organization}_${newLibraryName}`;
|
|
69
|
+
version = inputConfig.libraryVersion;
|
|
70
|
+
const isPermanent = inputConfig.isPermanent;
|
|
71
|
+
let permBuild = convertYNToBoolean(isPermanent);
|
|
72
|
+
|
|
73
|
+
if (isLibraryBasedCL) {
|
|
74
|
+
// no -dev for PegaInfinity
|
|
75
|
+
permBuild = true;
|
|
76
|
+
}
|
|
58
77
|
|
|
78
|
+
const hasArch = await hasArchives();
|
|
79
|
+
if (hasArch) {
|
|
80
|
+
if (orgLib.currentOrgLib === newOrgLib) {
|
|
81
|
+
console.log(`${chalk.bold.red(`Your current library is already ${orgLib.displayLibVersion}`)}`);
|
|
82
|
+
process.exit();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
console.log(`${chalk.bold.red(`No libraries exist.`)}`);
|
|
87
|
+
console.log("You need to create a library first via 'npm run createLib'.\n")
|
|
88
|
+
process.exit();
|
|
89
|
+
}
|
|
59
90
|
|
|
60
|
-
|
|
91
|
+
// version here includes -dev if appropriate
|
|
92
|
+
if (!permBuild) {
|
|
93
|
+
version = version.concat("-dev");
|
|
94
|
+
}
|
|
61
95
|
|
|
62
|
-
if (options.params.length >= 5) {
|
|
63
|
-
inputOrgLib = options.params[3];
|
|
64
|
-
version = options.params[4];
|
|
65
96
|
}
|
|
66
|
-
else
|
|
67
|
-
|
|
97
|
+
else {
|
|
98
|
+
process.exit();
|
|
68
99
|
}
|
|
69
100
|
|
|
70
|
-
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
// params are in different order then questions, because want of VS Code pluggin
|
|
104
|
+
if (options.params.length >= 6) {
|
|
105
|
+
newOrgLib = options.params[3];
|
|
106
|
+
version = options.params[4];
|
|
71
107
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
console.log(chalk.red(`No other available libraries to switch to.`));
|
|
75
|
-
process.exit();
|
|
76
|
-
}
|
|
108
|
+
const okToCont = options.params[5];
|
|
109
|
+
okToContinue = !!(okToCont === 'Y' || okToCont === 'y' || okToCont === true || okToCont === 'true');
|
|
77
110
|
|
|
78
111
|
|
|
79
|
-
|
|
80
|
-
const answers = await inquirer.prompt(questions);
|
|
81
|
-
({ okToContinue, newOrgLib } = answers);
|
|
112
|
+
} else {
|
|
82
113
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
114
|
+
if (options.params.length >= 5) {
|
|
115
|
+
inputOrgLib = options.params[3];
|
|
116
|
+
version = options.params[4];
|
|
117
|
+
}
|
|
118
|
+
else if (options.params.length >= 4) {
|
|
119
|
+
inputOrgLib = options.params[3];
|
|
120
|
+
}
|
|
86
121
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
122
|
+
const orgLib = getConfigDefaults();
|
|
123
|
+
|
|
124
|
+
const archVersionList = await getLibraryArchiveDirectories(orgLib.currentOrgLib);
|
|
125
|
+
if (archVersionList.length === 0) {
|
|
126
|
+
console.log(chalk.red(`No other available libraries to switch to.`));
|
|
127
|
+
process.exit();
|
|
128
|
+
}
|
|
90
129
|
|
|
91
|
-
if (version === "" || version === undefined) {
|
|
92
|
-
const nextQuestion = await getSwitchVersionComponentQuestions(newOrgLib);
|
|
93
|
-
const nextAnswers = await inquirer.prompt(nextQuestion);
|
|
94
|
-
({ version } = nextAnswers);
|
|
95
|
-
}
|
|
96
130
|
|
|
131
|
+
const questions = await getSwitchLibraryComponentQuestions(archVersionList, inputOrgLib);
|
|
132
|
+
const answers = await inquirer.prompt(questions);
|
|
133
|
+
({ okToContinue, newOrgLib } = answers);
|
|
134
|
+
|
|
135
|
+
if (!answers.okToContinue) {
|
|
136
|
+
process.exit()
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (newOrgLib === ""|| newOrgLib === undefined ) {
|
|
140
|
+
newOrgLib = inputOrgLib;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (version === "" || version === undefined) {
|
|
144
|
+
const nextQuestion = await getSwitchVersionComponentQuestions(newOrgLib);
|
|
145
|
+
const nextAnswers = await inquirer.prompt(nextQuestion);
|
|
146
|
+
({ version } = nextAnswers);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
}
|
|
97
150
|
}
|
|
98
151
|
|
|
99
|
-
// in this scenario, version contains "-dev", if appropriate
|
|
100
152
|
|
|
101
|
-
|
|
153
|
+
|
|
154
|
+
// in this scenario, version contains "-dev", if appropriate
|
|
102
155
|
const newVersion = version;
|
|
103
156
|
const existingOrgLib = orgLib.currentOrgLib;
|
|
104
157
|
let oldVersion = orgLib.buildVersion;
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
showVersion,
|
|
11
11
|
getPegaServerConfig,
|
|
12
12
|
getLibraryBased,
|
|
13
|
+
getLibraryBasedCL,
|
|
13
14
|
addDebugLog,
|
|
14
15
|
zipVersionAndArchive,
|
|
15
16
|
restoreFromArchive,
|
|
@@ -18,7 +19,12 @@ import {
|
|
|
18
19
|
getHaveDependencyDifference,
|
|
19
20
|
forceDefaultsUpdate,
|
|
20
21
|
modAddAboutData,
|
|
21
|
-
cleanUpTemp
|
|
22
|
+
cleanUpTemp,
|
|
23
|
+
getUseInputConfig,
|
|
24
|
+
getInputConfigForCommand,
|
|
25
|
+
convertYNToBoolean,
|
|
26
|
+
hasArchives,
|
|
27
|
+
hasLibraryAndVersion
|
|
22
28
|
} from '../../util.js';
|
|
23
29
|
|
|
24
30
|
import { getSwitchVersionComponentQuestions } from './helper.js';
|
|
@@ -27,6 +33,9 @@ import { showCurrentStatus } from '../show-status/index.js';
|
|
|
27
33
|
|
|
28
34
|
export default async options => {
|
|
29
35
|
const isLibraryBased = getLibraryBased();
|
|
36
|
+
const isLibraryBasedCL = getLibraryBasedCL();
|
|
37
|
+
|
|
38
|
+
const useInputConfig = getUseInputConfig();
|
|
30
39
|
if (!isLibraryBased) {
|
|
31
40
|
console.log(`Command only supported for ${chalk.bold.green('library mode')} components.`);
|
|
32
41
|
process.exit();
|
|
@@ -46,31 +55,82 @@ addDebugLog("switchVersion", "", "+");
|
|
|
46
55
|
const serverConfig = await getPegaServerConfig();
|
|
47
56
|
const currentDirectory = process.cwd();
|
|
48
57
|
const componentDirectory = join (currentDirectory, "src", "components");
|
|
58
|
+
const orgLib = getConfigDefaults();
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
// if we have choosen to use INPUT CONFIG FILE
|
|
62
|
+
// process and no inputs
|
|
63
|
+
if (useInputConfig) {
|
|
64
|
+
const inputConfig = await getInputConfigForCommand("switchLibVersion");
|
|
65
|
+
|
|
66
|
+
okToContinue = convertYNToBoolean(inputConfig.okToContinue);
|
|
67
|
+
if (okToContinue) {
|
|
68
|
+
version = inputConfig.libraryVersion;
|
|
69
|
+
const isPermanent = inputConfig.isPermanent;
|
|
70
|
+
let permBuild = convertYNToBoolean(isPermanent);
|
|
71
|
+
|
|
72
|
+
if (isLibraryBasedCL) {
|
|
73
|
+
// no -dev for PegaInfinity
|
|
74
|
+
permBuild = true;
|
|
75
|
+
}
|
|
49
76
|
|
|
77
|
+
const hasArch = await hasArchives();
|
|
78
|
+
const orgLib = getConfigDefaults();
|
|
79
|
+
const hasLib = await hasLibraryAndVersion(orgLib.library, version, !permBuild);
|
|
50
80
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
81
|
+
// version here includes -dev if appropriate
|
|
82
|
+
if (!permBuild) {
|
|
83
|
+
version = version.concat("-dev");
|
|
84
|
+
}
|
|
54
85
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
86
|
+
if (hasArch) {
|
|
87
|
+
if (orgLib.buildVersion == version ) {
|
|
88
|
+
console.log(`${chalk.bold.red(`Your current library/version is already ${orgLib.displayLibVersion}.`)}`);
|
|
89
|
+
process.exit();
|
|
90
|
+
}
|
|
91
|
+
if (!hasLib) {
|
|
92
|
+
console.log(`${chalk.bold.red(`${orgLib.library}/${version} does not exist.`)}`);
|
|
93
|
+
process.exit();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
console.log(`${chalk.bold.red(`No libraries exist.`)}`);
|
|
98
|
+
console.log("You need to create a library first via 'npm run createLib'.\n")
|
|
99
|
+
process.exit();
|
|
59
100
|
}
|
|
101
|
+
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
process.exit();
|
|
60
105
|
}
|
|
61
106
|
|
|
62
|
-
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
if (options.params.length >= 5) {
|
|
110
|
+
const okToCont = options.params[3];
|
|
111
|
+
version = options.params[4];
|
|
112
|
+
|
|
113
|
+
// if have [5] will be "NoAbout" from Jest, to turn off build date
|
|
114
|
+
if (options.params.length >= 6 ) {
|
|
115
|
+
if (options.params[5] === "NoAbout") {
|
|
116
|
+
modAddAboutData(false);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
63
119
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
120
|
+
okToContinue = !!(okToCont === 'Y' || okToCont === 'y' || okToCont === true || okToCont === 'true');
|
|
121
|
+
|
|
122
|
+
} else {
|
|
123
|
+
const questions = await getSwitchVersionComponentQuestions();
|
|
124
|
+
const answers = await inquirer.prompt(questions);
|
|
125
|
+
({ okToContinue, version } = answers);
|
|
126
|
+
}
|
|
68
127
|
}
|
|
69
128
|
|
|
129
|
+
|
|
70
130
|
if (okToContinue) {
|
|
71
131
|
// in this scenario, version contains "-dev", if appropriate
|
|
72
132
|
|
|
73
|
-
|
|
133
|
+
|
|
74
134
|
const newVersion = version;
|
|
75
135
|
const existingOrgLib = orgLib.currentOrgLib;
|
|
76
136
|
const oldVersion = orgLib.buildVersion;
|
package/src/util.js
CHANGED
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
COMPONENTS_DIRECTORY_PATH,
|
|
22
22
|
COMPONENTS_CONFIG_FILE_NAME,
|
|
23
23
|
TASKS_CONFIG_JSON_FILENAME,
|
|
24
|
+
INPUT_CONFIG_JSON_FILENAME,
|
|
24
25
|
PACKAGE_JSON_FILENAME,
|
|
25
26
|
PACKAGE_LOCK_JSON_FILENAME,
|
|
26
27
|
TOKEN_PATH,
|
|
@@ -33,6 +34,7 @@ import {
|
|
|
33
34
|
BOOTSTRAP_CONFIG,
|
|
34
35
|
LIBRARY_BASED,
|
|
35
36
|
LIBRARY_BASED_CL,
|
|
37
|
+
USE_INPUT_CONFIG,
|
|
36
38
|
SHARED_DIRECTORY,
|
|
37
39
|
SHOW_DEBUG,
|
|
38
40
|
COMPONENTS_PATH,
|
|
@@ -69,7 +71,8 @@ let defaultConfigs = {
|
|
|
69
71
|
displayLibVersion: "",
|
|
70
72
|
showDebug: false,
|
|
71
73
|
importRelativePath: "",
|
|
72
|
-
exportRelativePath: ""
|
|
74
|
+
exportRelativePath: "",
|
|
75
|
+
useInputConfig: false
|
|
73
76
|
};
|
|
74
77
|
|
|
75
78
|
let pegaConfig = null;
|
|
@@ -125,7 +128,8 @@ export const setUpDefaults = async () => {
|
|
|
125
128
|
displayLibVersion: "",
|
|
126
129
|
showDebug: false,
|
|
127
130
|
importRelativePath: "",
|
|
128
|
-
exportRelativePath: ""
|
|
131
|
+
exportRelativePath: "",
|
|
132
|
+
useInputConfig: false
|
|
129
133
|
};
|
|
130
134
|
|
|
131
135
|
// retrievedConfigData
|
|
@@ -143,14 +147,18 @@ export const setUpDefaults = async () => {
|
|
|
143
147
|
retrievedConfigData.importRelativePath = data[IMPORT_RELATIVE_PATH];
|
|
144
148
|
}
|
|
145
149
|
|
|
146
|
-
|
|
147
150
|
if (data[EXPORT_RELATIVE_PATH]) {
|
|
148
151
|
retrievedConfigData.exportRelativePath = data[EXPORT_RELATIVE_PATH];
|
|
149
152
|
}
|
|
150
153
|
|
|
154
|
+
if (data[USE_INPUT_CONFIG]) {
|
|
155
|
+
retrievedConfigData.useInputConfig = data[USE_INPUT_CONFIG];
|
|
156
|
+
}
|
|
157
|
+
|
|
151
158
|
if (data[LIBRARY_BASED]) {
|
|
152
159
|
retrievedConfigData.isLibraryBased = data[LIBRARY_BASED];
|
|
153
160
|
}
|
|
161
|
+
|
|
154
162
|
retrievedConfigData.library = data.component.library;
|
|
155
163
|
retrievedConfigData.version = data.component.version;
|
|
156
164
|
|
|
@@ -189,6 +197,63 @@ export const setUpDefaults = async () => {
|
|
|
189
197
|
return JSON.parse(JSON.stringify(retrievedConfigData));
|
|
190
198
|
}
|
|
191
199
|
|
|
200
|
+
export const convertYNToBoolean = (inputYN) => {
|
|
201
|
+
switch (inputYN) {
|
|
202
|
+
case 'Y':
|
|
203
|
+
case 'y':
|
|
204
|
+
case 'Yes':
|
|
205
|
+
case 'YES':
|
|
206
|
+
case 't':
|
|
207
|
+
case 'true':
|
|
208
|
+
case 'True':
|
|
209
|
+
case 'TRUE':
|
|
210
|
+
return true;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export const getInputConfigForCommand = async (commandName) => {
|
|
217
|
+
// retrievedConfigData
|
|
218
|
+
const currentDirectory = process.cwd();
|
|
219
|
+
const inputConfigJsonPath = join(currentDirectory, INPUT_CONFIG_JSON_FILENAME);
|
|
220
|
+
const isLibraryBased = getLibraryBased();
|
|
221
|
+
|
|
222
|
+
try {
|
|
223
|
+
// force to throw error and not console log
|
|
224
|
+
await checkPathAccess(inputConfigJsonPath, {}, true);
|
|
225
|
+
|
|
226
|
+
let data = fs.readFileSync(inputConfigJsonPath, { encoding: 'utf8' });
|
|
227
|
+
data = JSON.parse(data);
|
|
228
|
+
|
|
229
|
+
if (isLibraryBased) {
|
|
230
|
+
const libraryCommands = data["libraryMode"];
|
|
231
|
+
|
|
232
|
+
if (libraryCommands[commandName]) {
|
|
233
|
+
return libraryCommands[commandName];
|
|
234
|
+
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
const standardCommands = data["standard"];
|
|
239
|
+
|
|
240
|
+
if (standardCommands[commandName]) {
|
|
241
|
+
return standardCommands[commandName];
|
|
242
|
+
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
catch (ex) {
|
|
248
|
+
// when can't find it, always be false, assume no library based.
|
|
249
|
+
// This is IMPORTANT for init (npx install)
|
|
250
|
+
return {};
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
return {};
|
|
254
|
+
|
|
255
|
+
}
|
|
256
|
+
|
|
192
257
|
// initialize
|
|
193
258
|
// await setUpDefaults();
|
|
194
259
|
|
|
@@ -410,6 +475,13 @@ if (showDebug) addDebugLog("getLibraryBasedCL", "", "");
|
|
|
410
475
|
return defaultConfigs.isLibraryBasedCL;
|
|
411
476
|
}
|
|
412
477
|
|
|
478
|
+
export const getUseInputConfig = () => {
|
|
479
|
+
if (showDebug) addDebugLog("getUseInputConfig", "", "");
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
return defaultConfigs.useInputConfig;
|
|
483
|
+
}
|
|
484
|
+
|
|
413
485
|
export const setLibraryBased = async (isLibraryBased) => {
|
|
414
486
|
if (showDebug) addDebugLog("setLibraryBased", "", "");
|
|
415
487
|
const currentDirectory = process.cwd();
|
|
@@ -1572,7 +1644,8 @@ if (showDebug) addDebugLog("updateC11NB2SForInfinity", "", "");
|
|
|
1572
1644
|
|
|
1573
1645
|
const objOauthData = JSON.parse(OAuthData);
|
|
1574
1646
|
objOauthData["C11NB2S"] = bootstrap.tokens.C11NB2S;
|
|
1575
|
-
objOauthData["appStaticContentServer"] = bootstrap.serviceConfig.appStaticContentServer;
|
|
1647
|
+
// objOauthData["appStaticContentServer"] = bootstrap.serviceConfig.appStaticContentServer;
|
|
1648
|
+
objOauthData["appStaticContentServer"] = (bootstrap.serviceConfig.appStaticContentServer != "no-cdn" && bootstrap.serviceConfig.appStaticContentServer != "") ? bootstrap.serviceConfig.appStaticContentServer : bootstrap.serviceConfig.staticContentServer;
|
|
1576
1649
|
|
|
1577
1650
|
// write out file
|
|
1578
1651
|
fs.writeFileSync(TOKEN_PATH, JSON.stringify(objOauthData), { encoding: 'utf8',flag:'w' });
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import esbuild from 'esbuild';
|
|
2
|
-
|
|
3
|
-
async function startDevServer() {
|
|
4
|
-
const ctx = await esbuild.context({
|
|
5
|
-
entryPoints: ['scripts/index.ts'],
|
|
6
|
-
bundle: true,
|
|
7
|
-
outdir: 'dist',
|
|
8
|
-
sourcemap: true,
|
|
9
|
-
loader: { '.js': 'jsx' },
|
|
10
|
-
platform: 'browser',
|
|
11
|
-
logLevel: 'info',
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
// Initial build
|
|
15
|
-
await ctx.rebuild();
|
|
16
|
-
console.log('✨ Initial build complete');
|
|
17
|
-
|
|
18
|
-
// Watch for changes
|
|
19
|
-
await ctx.watch();
|
|
20
|
-
console.log('👀 Watching for changes...');
|
|
21
|
-
|
|
22
|
-
let { host, port } = await ctx.serve({
|
|
23
|
-
servedir: 'dist',
|
|
24
|
-
port: 3030,
|
|
25
|
-
host: 'localhost'
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
console.log(`🚀 Development server running at http://${host}:${port}`);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
startDevServer().catch((err) => {
|
|
32
|
-
console.error('Error:', err);
|
|
33
|
-
process.exit(1);
|
|
34
|
-
});
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export const loadable = (importFn: () => Promise<any>, componentName: string) => {
|
|
2
|
-
return async () => {
|
|
3
|
-
if (!PCore.getComponentsRegistry().lazyMap[componentName]) {
|
|
4
|
-
const component = await importFn();
|
|
5
|
-
PCore.getComponentsRegistry().lazyMap[componentName] = component.default;
|
|
6
|
-
}
|
|
7
|
-
};
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
const reactComponentsMap = {
|
|
11
|
-
{{#components}}
|
|
12
|
-
{{name}}: {
|
|
13
|
-
modules: [
|
|
14
|
-
loadable(
|
|
15
|
-
() =>
|
|
16
|
-
import(
|
|
17
|
-
/* webpackChunkName: "{{name}}" */ "../src/components/{{name}}/index"
|
|
18
|
-
),
|
|
19
|
-
"{{name}}"
|
|
20
|
-
),
|
|
21
|
-
],
|
|
22
|
-
scripts: [],
|
|
23
|
-
},
|
|
24
|
-
{{/components}}
|
|
25
|
-
};
|
|
26
|
-
PCore.getComponentsRegistry().mergeComponentsMap(reactComponentsMap);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/* entry point for component map */
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { fileURLToPath } from 'url';
|
|
4
|
-
import Mustache from 'mustache';
|
|
5
|
-
|
|
6
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
-
const __dirname = path.dirname(__filename);
|
|
8
|
-
|
|
9
|
-
const componentsDir = path.join(__dirname, '../src/components');
|
|
10
|
-
const componentsJsonPath = path.join(__dirname, './components.json');
|
|
11
|
-
|
|
12
|
-
async function populateComponents() {
|
|
13
|
-
try {
|
|
14
|
-
if (!fs.existsSync(componentsDir)) {
|
|
15
|
-
throw new Error(`Components directory not found: ${componentsDir}`);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const componentNames = fs.readdirSync(componentsDir)
|
|
19
|
-
.filter(file => {
|
|
20
|
-
const componentPath = path.join(componentsDir, file);
|
|
21
|
-
const configPath = path.join(componentPath, 'config.json');
|
|
22
|
-
return fs.statSync(componentPath).isDirectory() && fs.existsSync(configPath);
|
|
23
|
-
})
|
|
24
|
-
.map(dir => {
|
|
25
|
-
const configPath = path.join(componentsDir, dir, 'config.json');
|
|
26
|
-
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
27
|
-
return config.componentKey || dir;
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
const data = { components: componentNames };
|
|
31
|
-
fs.writeFileSync(componentsJsonPath, JSON.stringify(data, null, 2));
|
|
32
|
-
console.log('Components list updated:', componentNames);
|
|
33
|
-
return componentNames;
|
|
34
|
-
} catch (err) {
|
|
35
|
-
console.error('Error populating components:', err.message);
|
|
36
|
-
process.exit(1);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
async function generateIndex(components) {
|
|
41
|
-
try {
|
|
42
|
-
const templatePath = path.join(__dirname, './index.mustache');
|
|
43
|
-
const outputPath = path.join(__dirname, './index.ts');
|
|
44
|
-
|
|
45
|
-
if (!fs.existsSync(templatePath)) {
|
|
46
|
-
throw new Error('Template file missing: index.mustache');
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const template = fs.readFileSync(templatePath, 'utf-8');
|
|
50
|
-
const templateData = {
|
|
51
|
-
components: components.map(name => ({ name }))
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const output = Mustache.render(template, templateData);
|
|
55
|
-
|
|
56
|
-
// Ensure src directory exists
|
|
57
|
-
const srcDir = path.dirname(outputPath);
|
|
58
|
-
if (!fs.existsSync(srcDir)) {
|
|
59
|
-
fs.mkdirSync(srcDir, { recursive: true });
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
fs.writeFileSync(outputPath, output, 'utf-8');
|
|
63
|
-
console.log('Generated exports for components:', components);
|
|
64
|
-
} catch (err) {
|
|
65
|
-
console.error('Error generating index:', err.message);
|
|
66
|
-
process.exit(1);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
async function main() {
|
|
71
|
-
const components = await populateComponents();
|
|
72
|
-
await generateIndex(components);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
main();
|