@serenityjs/plugins 0.3.2 → 0.3.3-beta-20240611195516
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/index.js +29 -16
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -36,7 +36,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
36
36
|
|
|
37
37
|
// src/plugins.ts
|
|
38
38
|
var import_node_child_process = require("child_process");
|
|
39
|
-
var
|
|
39
|
+
var import_node_fs2 = require("fs");
|
|
40
40
|
var import_node_path = require("path");
|
|
41
41
|
var import_node_process = __toESM(require("process"));
|
|
42
42
|
var import_logger = require("@serenityjs/logger");
|
|
@@ -73,6 +73,19 @@ var TSCONFIG_TEMPLATE = (
|
|
|
73
73
|
`
|
|
74
74
|
);
|
|
75
75
|
|
|
76
|
+
// src/utils/exists.ts
|
|
77
|
+
var import_node_fs = require("fs");
|
|
78
|
+
function exists(path) {
|
|
79
|
+
try {
|
|
80
|
+
(0, import_node_fs.lstatSync)(path, {
|
|
81
|
+
throwIfNoEntry: true
|
|
82
|
+
});
|
|
83
|
+
return true;
|
|
84
|
+
} catch {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
76
89
|
// src/plugins.ts
|
|
77
90
|
var Plugins = class extends import_emitter.default {
|
|
78
91
|
/**
|
|
@@ -109,22 +122,22 @@ var Plugins = class extends import_emitter.default {
|
|
|
109
122
|
this.logger.warn("Plugins are set to be disabled.");
|
|
110
123
|
return;
|
|
111
124
|
}
|
|
112
|
-
if (!(
|
|
125
|
+
if (!exists(this.path)) {
|
|
113
126
|
try {
|
|
114
|
-
await (0,
|
|
127
|
+
await (0, import_node_fs2.mkdirSync)(this.path);
|
|
115
128
|
} catch (reason) {
|
|
116
129
|
this.logger.error(`Failed to create plugins directory!`, reason);
|
|
117
130
|
}
|
|
118
131
|
}
|
|
119
|
-
const directories = (0,
|
|
132
|
+
const directories = (0, import_node_fs2.readdirSync)(this.path, {
|
|
120
133
|
withFileTypes: true
|
|
121
134
|
}).filter((dirent) => dirent.isDirectory());
|
|
122
135
|
for (const directory of directories) {
|
|
123
136
|
const path = (0, import_node_path.resolve)(this.path, directory.name);
|
|
124
|
-
if (!(
|
|
137
|
+
if (!exists((0, import_node_path.resolve)(path, "plugin.json"))) {
|
|
125
138
|
try {
|
|
126
139
|
const config2 = PLUGIN_TEMPLATE.replace("plugin-name", directory.name);
|
|
127
|
-
(0,
|
|
140
|
+
(0, import_node_fs2.writeFileSync)((0, import_node_path.resolve)(path, "plugin.json"), config2);
|
|
128
141
|
} catch {
|
|
129
142
|
this.logger.error(
|
|
130
143
|
`Failed to create plugin.json for ${directory.name}`
|
|
@@ -132,10 +145,10 @@ var Plugins = class extends import_emitter.default {
|
|
|
132
145
|
}
|
|
133
146
|
}
|
|
134
147
|
const config = JSON.parse(
|
|
135
|
-
(0,
|
|
148
|
+
(0, import_node_fs2.readFileSync)((0, import_node_path.resolve)(path, "plugin.json"), "utf8")
|
|
136
149
|
);
|
|
137
150
|
if (config.node === true) {
|
|
138
|
-
if (!(
|
|
151
|
+
if (!exists((0, import_node_path.resolve)(path, "package.json"))) {
|
|
139
152
|
try {
|
|
140
153
|
(0, import_node_child_process.execSync)("npm init -y", { stdio: "ignore", cwd: path });
|
|
141
154
|
} catch (reason) {
|
|
@@ -145,7 +158,7 @@ var Plugins = class extends import_emitter.default {
|
|
|
145
158
|
);
|
|
146
159
|
}
|
|
147
160
|
}
|
|
148
|
-
if (!(
|
|
161
|
+
if (!exists((0, import_node_path.resolve)(path, "package-lock.json"))) {
|
|
149
162
|
try {
|
|
150
163
|
this.logger.info(
|
|
151
164
|
`Installing dependencies for ${config.name}@${config.version}...`
|
|
@@ -160,9 +173,9 @@ var Plugins = class extends import_emitter.default {
|
|
|
160
173
|
}
|
|
161
174
|
}
|
|
162
175
|
if (config.typescript === true) {
|
|
163
|
-
if (!(
|
|
176
|
+
if (!exists((0, import_node_path.resolve)(path, "tsconfig.json"))) {
|
|
164
177
|
try {
|
|
165
|
-
await (0,
|
|
178
|
+
await (0, import_node_fs2.writeFileSync)(
|
|
166
179
|
(0, import_node_path.resolve)(path, "tsconfig.json"),
|
|
167
180
|
TSCONFIG_TEMPLATE
|
|
168
181
|
);
|
|
@@ -177,7 +190,7 @@ var Plugins = class extends import_emitter.default {
|
|
|
177
190
|
);
|
|
178
191
|
}
|
|
179
192
|
}
|
|
180
|
-
if (!(
|
|
193
|
+
if (!exists((0, import_node_path.resolve)(path, "dist")) || config.mode === "development") {
|
|
181
194
|
try {
|
|
182
195
|
this.logger.info(
|
|
183
196
|
`Building typescript files for ${config.name}@${config.version}...`
|
|
@@ -194,7 +207,7 @@ var Plugins = class extends import_emitter.default {
|
|
|
194
207
|
try {
|
|
195
208
|
const path2 = (0, import_node_path.resolve)(this.path, directory.name);
|
|
196
209
|
const config2 = JSON.parse(
|
|
197
|
-
(0,
|
|
210
|
+
(0, import_node_fs2.readFileSync)((0, import_node_path.resolve)(path2, "plugin.json"), "utf8")
|
|
198
211
|
);
|
|
199
212
|
const instance = await import(`file://${(0, import_node_path.resolve)(path2, config2.entry)}`);
|
|
200
213
|
const module2 = instance["default"];
|
|
@@ -218,9 +231,9 @@ var Plugins = class extends import_emitter.default {
|
|
|
218
231
|
);
|
|
219
232
|
const s = plugins.length > 1 ? "s" : "";
|
|
220
233
|
this.logger.success(
|
|
221
|
-
`Successfully initialized a total of ${plugins.length} plugin${s}! ${plugins.join(
|
|
222
|
-
", "
|
|
223
|
-
)}`
|
|
234
|
+
`Successfully initialized a total of ${plugins.length} plugin${s}! \xA7c${plugins.join(
|
|
235
|
+
"\xA7r, \xA7c"
|
|
236
|
+
)}\xA7r`
|
|
224
237
|
);
|
|
225
238
|
}
|
|
226
239
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serenityjs/plugins",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3-beta-20240611195516",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"repository": "https://github.com/SerenityJS/serenity",
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
"preset": "@serenityjs/jest-presets/jest/node"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@serenityjs/eslint-config": "
|
|
22
|
-
"@serenityjs/jest-presets": "
|
|
23
|
-
"@serenityjs/typescript-config": "
|
|
21
|
+
"@serenityjs/eslint-config": "0.3.3-beta-20240611195516",
|
|
22
|
+
"@serenityjs/jest-presets": "0.3.3-beta-20240611195516",
|
|
23
|
+
"@serenityjs/typescript-config": "0.3.3-beta-20240611195516",
|
|
24
24
|
"@types/jest": "^29.5.12",
|
|
25
25
|
"@types/node": "^20.11.24",
|
|
26
26
|
"jest": "^29.7.0",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"typescript": "^5.4.2"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@serenityjs/emitter": "
|
|
32
|
-
"@serenityjs/logger": "
|
|
31
|
+
"@serenityjs/emitter": "0.3.3-beta-20240611195516",
|
|
32
|
+
"@serenityjs/logger": "0.3.3-beta-20240611195516"
|
|
33
33
|
}
|
|
34
34
|
}
|