@saltcorn/plugins-loader 0.9.6-beta.0 → 0.9.6-beta.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/download_utils.js +7 -10
- package/package.json +2 -2
- package/plugin_installer.js +13 -5
package/download_utils.js
CHANGED
|
@@ -9,17 +9,15 @@ const { createWriteStream, unlink } = require("fs");
|
|
|
9
9
|
const { get } = require("https");
|
|
10
10
|
const npmFetch = require("npm-registry-fetch");
|
|
11
11
|
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
const downloadFromGithub = async (plugin, pluginDir) => {
|
|
12
|
+
const downloadFromGithub = async (plugin, rootFolder, pluginDir) => {
|
|
15
13
|
const tarballUrl = `https://api.github.com/repos/${plugin.location}/tarball`;
|
|
16
14
|
const fileName = plugin.name.split("/").pop();
|
|
17
|
-
const filePath = await loadTarball(tarballUrl, fileName);
|
|
15
|
+
const filePath = await loadTarball(rootFolder, tarballUrl, fileName);
|
|
18
16
|
await mkdir(pluginDir, { recursive: true });
|
|
19
17
|
await extractTarball(filePath, pluginDir);
|
|
20
18
|
};
|
|
21
19
|
|
|
22
|
-
const downloadFromNpm = async (plugin, pluginDir, pckJson) => {
|
|
20
|
+
const downloadFromNpm = async (plugin, rootFolder, pluginDir, pckJson) => {
|
|
23
21
|
const pkgInfo = await npmFetch.json(
|
|
24
22
|
`https://registry.npmjs.org/${plugin.location}`
|
|
25
23
|
);
|
|
@@ -32,14 +30,14 @@ const downloadFromNpm = async (plugin, pluginDir, pckJson) => {
|
|
|
32
30
|
else {
|
|
33
31
|
const tarballUrl = pkgInfo.versions[vToInstall].dist.tarball;
|
|
34
32
|
const fileName = plugin.name.split("/").pop();
|
|
35
|
-
const filePath = await loadTarball(tarballUrl, fileName);
|
|
33
|
+
const filePath = await loadTarball(rootFolder, tarballUrl, fileName);
|
|
36
34
|
await mkdir(pluginDir, { recursive: true });
|
|
37
35
|
await extractTarball(filePath, pluginDir);
|
|
38
36
|
return true;
|
|
39
37
|
}
|
|
40
38
|
};
|
|
41
39
|
|
|
42
|
-
const loadTarball = (url, name) => {
|
|
40
|
+
const loadTarball = (rootFolder, url, name) => {
|
|
43
41
|
const options = {
|
|
44
42
|
headers: {
|
|
45
43
|
"User-Agent": "request",
|
|
@@ -94,7 +92,6 @@ const loadTarball = (url, name) => {
|
|
|
94
92
|
* @param plugin
|
|
95
93
|
*/
|
|
96
94
|
const gitPullOrClone = async (plugin, pluginDir) => {
|
|
97
|
-
await fs.promises.mkdir("git_plugins", { recursive: true });
|
|
98
95
|
let keyfnm,
|
|
99
96
|
setKey = `-c core.sshCommand="ssh -oBatchMode=yes -o 'StrictHostKeyChecking no'" `;
|
|
100
97
|
if (plugin.deploy_private_key) {
|
|
@@ -125,12 +122,12 @@ const extractTarball = async (tarFile, destination) => {
|
|
|
125
122
|
});
|
|
126
123
|
};
|
|
127
124
|
|
|
128
|
-
const tarballExists = async (plugin) => {
|
|
125
|
+
const tarballExists = async (rootFolder, plugin) => {
|
|
129
126
|
const fileName = `${plugin.name.split("/").pop()}.tar.gz`;
|
|
130
127
|
return await pathExists(join(rootFolder, "plugins_folder", fileName));
|
|
131
128
|
};
|
|
132
129
|
|
|
133
|
-
const removeTarball = async (plugin) => {
|
|
130
|
+
const removeTarball = async (rootFolder, plugin) => {
|
|
134
131
|
const fileName = `${plugin.name.split("/").pop()}.tar.gz`;
|
|
135
132
|
await rm(join(rootFolder, "plugins_folder", fileName));
|
|
136
133
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saltcorn/plugins-loader",
|
|
3
|
-
"version": "0.9.6-beta.
|
|
3
|
+
"version": "0.9.6-beta.1",
|
|
4
4
|
"description": "Saltcorn plugin loader",
|
|
5
5
|
"homepage": "https://saltcorn.com",
|
|
6
6
|
"scripts": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"env-paths": "^2.2.0",
|
|
13
13
|
"npm-registry-fetch": "16.0.0",
|
|
14
|
-
"@saltcorn/data": "0.9.6-beta.
|
|
14
|
+
"@saltcorn/data": "0.9.6-beta.1"
|
|
15
15
|
},
|
|
16
16
|
"author": "Christian Hugo",
|
|
17
17
|
"license": "MIT",
|
package/plugin_installer.js
CHANGED
|
@@ -39,7 +39,8 @@ const npmInstallNeeded = (oldPckJSON, newPckJSON) => {
|
|
|
39
39
|
class PluginInstaller {
|
|
40
40
|
constructor(plugin, opts = {}) {
|
|
41
41
|
this.plugin = plugin;
|
|
42
|
-
this.rootFolder =
|
|
42
|
+
this.rootFolder =
|
|
43
|
+
opts.rootFolder || envPaths("saltcorn", { suffix: "plugins" }).data;
|
|
43
44
|
this.tempRootFolder =
|
|
44
45
|
opts.tempRootFolder || envPaths("saltcorn", { suffix: "tmp" }).temp;
|
|
45
46
|
const tokens =
|
|
@@ -75,7 +76,8 @@ class PluginInstaller {
|
|
|
75
76
|
)
|
|
76
77
|
await this.npmInstall(tmpPckJSON);
|
|
77
78
|
await this.movePlugin();
|
|
78
|
-
if (await tarballExists(this.
|
|
79
|
+
if (await tarballExists(this.rootFolder, this.plugin))
|
|
80
|
+
await removeTarball(this.rootFolder, this.plugin);
|
|
79
81
|
}
|
|
80
82
|
pckJSON = await readPackageJson(this.pckJsonPath);
|
|
81
83
|
};
|
|
@@ -123,12 +125,17 @@ class PluginInstaller {
|
|
|
123
125
|
(force && !(await this.versionIsInstalled(pckJSON))) ||
|
|
124
126
|
!folderExists
|
|
125
127
|
) {
|
|
126
|
-
wasLoaded = await downloadFromNpm(
|
|
128
|
+
wasLoaded = await downloadFromNpm(
|
|
129
|
+
this.plugin,
|
|
130
|
+
this.rootFolder,
|
|
131
|
+
this.tempDir,
|
|
132
|
+
pckJSON
|
|
133
|
+
);
|
|
127
134
|
}
|
|
128
135
|
break;
|
|
129
136
|
case "github":
|
|
130
137
|
if (force || !folderExists) {
|
|
131
|
-
await downloadFromGithub(this.plugin, this.tempDir);
|
|
138
|
+
await downloadFromGithub(this.plugin, this.rootFolder, this.tempDir);
|
|
132
139
|
wasLoaded = true;
|
|
133
140
|
}
|
|
134
141
|
break;
|
|
@@ -153,7 +160,8 @@ class PluginInstaller {
|
|
|
153
160
|
const isWindows = process.platform === "win32";
|
|
154
161
|
const ensureFn = async (folder) => {
|
|
155
162
|
const pluginsFolder = join(this.rootFolder, folder);
|
|
156
|
-
if (!(await pathExists(pluginsFolder)))
|
|
163
|
+
if (!(await pathExists(pluginsFolder)))
|
|
164
|
+
await mkdir(pluginsFolder, { recursive: true });
|
|
157
165
|
const symLinkDst = join(pluginsFolder, "node_modules");
|
|
158
166
|
const symLinkSrc = (await isGitCheckout())
|
|
159
167
|
? join(__dirname, "..", "..", "node_modules")
|