@lars_hagemann/mediaserver-create-plugin 0.24.3
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 +229 -0
- package/package.json +27 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
13
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
14
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
15
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
16
|
+
function step(op) {
|
|
17
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
18
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
19
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
20
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
21
|
+
switch (op[0]) {
|
|
22
|
+
case 0: case 1: t = op; break;
|
|
23
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
24
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
25
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
26
|
+
default:
|
|
27
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
28
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
29
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
30
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
31
|
+
if (t[2]) _.ops.pop();
|
|
32
|
+
_.trys.pop(); continue;
|
|
33
|
+
}
|
|
34
|
+
op = body.call(thisArg, _);
|
|
35
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
36
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
var readline = require("readline");
|
|
41
|
+
var fs = require("fs/promises");
|
|
42
|
+
var child_process_1 = require("child_process");
|
|
43
|
+
var frontendTsConfig = {
|
|
44
|
+
compilerOptions: {
|
|
45
|
+
target: "ES2023",
|
|
46
|
+
lib: ["ES2023", "DOM"],
|
|
47
|
+
module: "ESNext",
|
|
48
|
+
skipLibCheck: true,
|
|
49
|
+
/* Bundler mode */
|
|
50
|
+
moduleResolution: "bundler",
|
|
51
|
+
//"allowImportingTsExtensions": true,
|
|
52
|
+
verbatimModuleSyntax: true,
|
|
53
|
+
moduleDetection: "force",
|
|
54
|
+
noEmit: false,
|
|
55
|
+
outDir: "dist",
|
|
56
|
+
/* Linting */
|
|
57
|
+
strict: true,
|
|
58
|
+
noUnusedLocals: true,
|
|
59
|
+
noUnusedParameters: true,
|
|
60
|
+
erasableSyntaxOnly: true,
|
|
61
|
+
noFallthroughCasesInSwitch: true,
|
|
62
|
+
noUncheckedSideEffectImports: true,
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
var backendTsConfig = {
|
|
66
|
+
compilerOptions: {
|
|
67
|
+
target: "ES2023",
|
|
68
|
+
lib: ["ES2023"],
|
|
69
|
+
types: ["node"],
|
|
70
|
+
module: "nodenext",
|
|
71
|
+
skipLibCheck: true,
|
|
72
|
+
outDir: "dist",
|
|
73
|
+
moduleResolution: "nodenext",
|
|
74
|
+
/* Linting */
|
|
75
|
+
strict: true,
|
|
76
|
+
noUnusedLocals: true,
|
|
77
|
+
noUnusedParameters: true,
|
|
78
|
+
erasableSyntaxOnly: true,
|
|
79
|
+
noFallthroughCasesInSwitch: true,
|
|
80
|
+
noUncheckedSideEffectImports: true,
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
var backendDependencies = [
|
|
84
|
+
"@types/node",
|
|
85
|
+
"typescript",
|
|
86
|
+
"@lars_hagemann/mediaserver-backend-plugin-types",
|
|
87
|
+
];
|
|
88
|
+
var frontendDependencies = [
|
|
89
|
+
"typescript",
|
|
90
|
+
"@types/react",
|
|
91
|
+
"@types/react-dom",
|
|
92
|
+
"@lars_hagemann/mediaserver-frontend-plugin-types",
|
|
93
|
+
];
|
|
94
|
+
var backendSkeleton = "\nimport { FileTypePlugin } from \"@lars_hagemann/mediaserver-backend-plugin-types\";\n\nexport const plugin: FileTypePlugin = {\n matcher: (file) => /* Your implementation here */ false,\n thumbnailCreator: async (context) => {\n throw new Error(\"Not implemented\");\n },\n};\n\nexport default plugin;\n";
|
|
95
|
+
var frontendSkeleton = "\nimport type { FileTypePlugin } from \"@lars_hagemann/mediaserver-frontend-plugin-types\";\n\nconst plugin: FileTypePlugin = {\n matcher: (fileType) => /* Your implementation here */ false,\n icon: (ReactIcons) => /* Your implementation here */ ReactIcons.FaFile,\n Render: (context) => {\n context.React.useEffect(() => {\n console.log(\"This worked!\");\n }, []);\n\n return context.React.createElement(\"iframe\", {\n className: \"w-full h-full\",\n src: context.objectUrl,\n });\n },\n Diashow: () => null,\n description: \"Your plugin description here\",\n};\n\nexport default plugin;\n";
|
|
96
|
+
var config = {
|
|
97
|
+
frontend: {
|
|
98
|
+
tsConfig: frontendTsConfig,
|
|
99
|
+
dependencies: frontendDependencies,
|
|
100
|
+
skeleton: frontendSkeleton,
|
|
101
|
+
},
|
|
102
|
+
backend: {
|
|
103
|
+
tsConfig: backendTsConfig,
|
|
104
|
+
dependencies: backendDependencies,
|
|
105
|
+
skeleton: backendSkeleton,
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
var rl = readline.createInterface({
|
|
109
|
+
input: process.stdin,
|
|
110
|
+
output: process.stdout,
|
|
111
|
+
});
|
|
112
|
+
var question = function (query) {
|
|
113
|
+
return new Promise(function (resolve) { return rl.question(query, resolve); });
|
|
114
|
+
};
|
|
115
|
+
var questionOrDefault = function (query, defaultValue) { return __awaiter(void 0, void 0, void 0, function () {
|
|
116
|
+
var answer;
|
|
117
|
+
return __generator(this, function (_a) {
|
|
118
|
+
switch (_a.label) {
|
|
119
|
+
case 0: return [4 /*yield*/, question("".concat(query, " (default: ").concat(defaultValue, "): "))];
|
|
120
|
+
case 1:
|
|
121
|
+
answer = _a.sent();
|
|
122
|
+
return [2 /*return*/, answer.trim() === "" ? defaultValue : answer.trim()];
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}); };
|
|
126
|
+
var validatePluginType = function (type) {
|
|
127
|
+
var validTypes = ["frontend", "backend"];
|
|
128
|
+
return validTypes.includes(type.toLowerCase());
|
|
129
|
+
};
|
|
130
|
+
function main() {
|
|
131
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
132
|
+
var folderPath, pluginType, inputType, pluginName, authorName, validate, pluginFolderPath, pluginSrcPath, packageJsonContent, pluginConfig, tsConfigContent, pluginFileName;
|
|
133
|
+
return __generator(this, function (_a) {
|
|
134
|
+
switch (_a.label) {
|
|
135
|
+
case 0: return [4 /*yield*/, questionOrDefault("Enter the plugin folder path", ".")];
|
|
136
|
+
case 1:
|
|
137
|
+
folderPath = _a.sent();
|
|
138
|
+
pluginType = "";
|
|
139
|
+
_a.label = 2;
|
|
140
|
+
case 2:
|
|
141
|
+
if (!true) return [3 /*break*/, 4];
|
|
142
|
+
return [4 /*yield*/, questionOrDefault("Enter the plugin type (frontend/backend)", "frontend")];
|
|
143
|
+
case 3:
|
|
144
|
+
inputType = _a.sent();
|
|
145
|
+
if (validatePluginType(inputType)) {
|
|
146
|
+
pluginType = inputType.toLowerCase();
|
|
147
|
+
return [3 /*break*/, 4];
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
console.log("Invalid plugin type. Please enter 'frontend' or 'backend'.");
|
|
151
|
+
}
|
|
152
|
+
return [3 /*break*/, 2];
|
|
153
|
+
case 4: return [4 /*yield*/, questionOrDefault("Enter the plugin name", "my-plugin")];
|
|
154
|
+
case 5:
|
|
155
|
+
pluginName = _a.sent();
|
|
156
|
+
return [4 /*yield*/, questionOrDefault("Enter the author name", "Your Name")];
|
|
157
|
+
case 6:
|
|
158
|
+
authorName = _a.sent();
|
|
159
|
+
console.log("\nPlugin Configuration:");
|
|
160
|
+
console.log("Folder Path: ".concat(folderPath));
|
|
161
|
+
console.log("Plugin Type: ".concat(pluginType));
|
|
162
|
+
console.log("Plugin Name: ".concat(pluginName));
|
|
163
|
+
console.log("Author Name: ".concat(authorName));
|
|
164
|
+
return [4 /*yield*/, questionOrDefault("Create plugin? (yes/no)", "yes")];
|
|
165
|
+
case 7:
|
|
166
|
+
validate = _a.sent();
|
|
167
|
+
rl.close();
|
|
168
|
+
if (validate.toLowerCase() !== "yes") {
|
|
169
|
+
console.log("Plugin creation cancelled.");
|
|
170
|
+
return [2 /*return*/];
|
|
171
|
+
}
|
|
172
|
+
pluginFolderPath = folderPath;
|
|
173
|
+
pluginSrcPath = "".concat(pluginFolderPath, "/src");
|
|
174
|
+
return [4 /*yield*/, fs.mkdir(pluginFolderPath, { recursive: true })];
|
|
175
|
+
case 8:
|
|
176
|
+
_a.sent();
|
|
177
|
+
return [4 /*yield*/, fs.mkdir(pluginSrcPath, { recursive: true })];
|
|
178
|
+
case 9:
|
|
179
|
+
_a.sent();
|
|
180
|
+
process.chdir(pluginFolderPath);
|
|
181
|
+
packageJsonContent = {
|
|
182
|
+
name: "".concat(pluginName),
|
|
183
|
+
scripts: {
|
|
184
|
+
build: "tsc",
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
console.log("Writing package.json");
|
|
188
|
+
return [4 /*yield*/, fs.writeFile("".concat(pluginFolderPath, "/package.json"), JSON.stringify(packageJsonContent, null, 2))];
|
|
189
|
+
case 10:
|
|
190
|
+
_a.sent();
|
|
191
|
+
pluginConfig = config[pluginType];
|
|
192
|
+
tsConfigContent = pluginConfig.tsConfig;
|
|
193
|
+
console.log("Writing tsconfig.json");
|
|
194
|
+
return [4 /*yield*/, fs.writeFile("".concat(pluginFolderPath, "/tsconfig.json"), JSON.stringify(tsConfigContent, null, 2))];
|
|
195
|
+
case 11:
|
|
196
|
+
_a.sent();
|
|
197
|
+
console.log("Installing dependencies...");
|
|
198
|
+
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
199
|
+
(0, child_process_1.exec)("npm i -D ".concat(pluginConfig.dependencies.join(" ")), function (error, stdout, stderr) {
|
|
200
|
+
if (error) {
|
|
201
|
+
console.error("Error installing dependencies: ".concat(error.message));
|
|
202
|
+
reject(error);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
if (stderr) {
|
|
206
|
+
console.error("stderr: ".concat(stderr));
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
console.log("stdout: ".concat(stdout));
|
|
210
|
+
resolve(null);
|
|
211
|
+
});
|
|
212
|
+
})];
|
|
213
|
+
case 12:
|
|
214
|
+
_a.sent();
|
|
215
|
+
console.log("Writing skeleton plugin file...");
|
|
216
|
+
pluginFileName = "index.ts";
|
|
217
|
+
return [4 /*yield*/, fs.writeFile("".concat(pluginSrcPath, "/").concat(pluginFileName), pluginConfig.skeleton)];
|
|
218
|
+
case 13:
|
|
219
|
+
_a.sent();
|
|
220
|
+
console.log("Plugin created successfully.");
|
|
221
|
+
return [2 /*return*/];
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
main().catch(function (err) {
|
|
227
|
+
console.error("Error:", err);
|
|
228
|
+
process.exit(1);
|
|
229
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lars_hagemann/mediaserver-create-plugin",
|
|
3
|
+
"version": "0.24.3",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"bin": "dist/index.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/LarsHagemann/mediaserver.git"
|
|
16
|
+
},
|
|
17
|
+
"author": "Lars Hagemann",
|
|
18
|
+
"license": "ISC",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/LarsHagemann/mediaserver/issues"
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://github.com/LarsHagemann/mediaserver#readme",
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/node": "^24.10.0",
|
|
25
|
+
"typescript": "^5.9.3"
|
|
26
|
+
}
|
|
27
|
+
}
|