-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Expand file tree
/
Copy pathplugins.ts
More file actions
162 lines (142 loc) · 4.36 KB
/
Copy pathplugins.ts
File metadata and controls
162 lines (142 loc) · 4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
'use strict';
import {linkInstaller, checkForMigration} from "ep_etherpad-lite/static/js/pluginfw/installer";
import {persistInstalledPlugins, filterUpdatablePluginNames} from "./commonPlugins";
import fs from "node:fs";
const settings = require('ep_etherpad-lite/node/utils/Settings');
if (process.argv.length === 2) {
console.error('Expected at least one argument!');
process.exit(1);
}
let args = process.argv.slice(2)
const possibleActions = [
"i",
"install",
"rm",
"remove",
"ls",
"list",
"up",
"update"
]
const install = ()=> {
const argsAsString: string = args.join(" ");
const regexRegistryPlugins = /(?<=(?:i|install)\s)(.*?)(?=--github|--path|$)/;
const regexLocalPlugins = /(?<=--path\s)(.*?)(?=--github|$)/;
const regexGithubPlugins = /(?<=--github\s)(.*?)(?=--path|$)/;
const registryPlugins = argsAsString.match(regexRegistryPlugins)?.[0]?.split(" ")?.filter(s => s) || [];
const localPlugins = argsAsString.match(regexLocalPlugins)?.[0]?.split(" ")?.filter(s => s) || [];
const githubPlugins = argsAsString.match(regexGithubPlugins)?.[0]?.split(" ")?.filter(s => s) || [];
async function run() {
for (const plugin of registryPlugins) {
if (possibleActions.includes(plugin)){
continue
}
console.log(`Installing plugin from registry: ${plugin}`)
if (plugin.includes('@')) {
const [name, version] = plugin.split('@');
await linkInstaller.installPlugin(name, version);
continue;
}
await linkInstaller.installPlugin(plugin);
}
for (const plugin of localPlugins) {
console.log(`Installing plugin from path: ${plugin}`);
await linkInstaller.installFromPath(plugin);
}
for (const plugin of githubPlugins) {
console.log(`Installing plugin from github: ${plugin}`);
await linkInstaller.installFromGitHub(plugin);
}
}
(async () => {
await checkForMigration();
await run();
await persistInstalledPlugins();
})();
}
const list = ()=>{
const walk = async () => {
const plugins = fs.readFileSync(settings.root+"/var/installed_plugins.json", "utf-8")
const pluginNames = JSON.parse(plugins).plugins.map((plugin: any) => plugin.name).join(", ")
console.log("Installed plugins are:", pluginNames)
}
(async () => {
await walk();
})();
}
// Re-install every plugin in installed_plugins.json without a version pin so
// the registry-latest gets resolved and overwrites the existing pinned copy
// in src/plugin_packages/. ep_etherpad-lite is the vendored core, never
// installed via the plugin path. filterUpdatablePluginNames also enforces
// the ep_ prefix so a corrupted manifest cannot coerce us into installing
// arbitrary npm packages, and de-duplicates repeats.
const update = ()=> {
(async () => {
const path = settings.root+"/var/installed_plugins.json";
let entries: Array<{name?: unknown}>;
try {
const parsed = JSON.parse(fs.readFileSync(path, "utf-8"));
entries = Array.isArray(parsed?.plugins) ? parsed.plugins : [];
} catch (err: any) {
if (err.code === 'ENOENT') {
console.log("No installed_plugins.json found — nothing to update");
return;
}
throw err;
}
const names = filterUpdatablePluginNames(entries);
if (names.length === 0) {
console.log("No plugins installed — nothing to update");
return;
}
console.log(`Updating plugins to latest from registry: ${names.join(', ')}`);
await checkForMigration();
for (const name of names) {
await linkInstaller.installPlugin(name);
}
await persistInstalledPlugins();
})();
}
const remove = (plugins: string[])=>{
const walk = async () => {
for (const plugin of plugins) {
console.log(`Uninstalling plugin: ${plugin}`)
await linkInstaller.uninstallPlugin(plugin);
}
await persistInstalledPlugins();
}
(async () => {
await checkForMigration();
await walk();
})();
}
let action = args[0];
switch (action) {
case "install":
install();
break;
case "i":
install();
break;
case "ls":
list();
break;
case "list":
list();
break;
case "rm":
remove(args.slice(1));
break;
case "remove":
remove(args.slice(1));
break;
case "up":
update();
break;
case "update":
update();
break;
default:
console.error('Expected at least one argument!');
process.exit(1);
}