@kausal/themes 0.1.1 → 0.1.2
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/index.js +29 -6
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -2,17 +2,39 @@ const fs = require('fs');
|
|
|
2
2
|
const path = require('path');
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
function generateThemeSymlinks(destPath) {
|
|
5
|
+
function generateThemeSymlinks(destPath, opts) {
|
|
6
|
+
const { verbose } = opts || {};
|
|
7
|
+
|
|
8
|
+
if (verbose) {
|
|
9
|
+
const packageData = require('./package.json');
|
|
10
|
+
console.log(`🔗 Generating symlinks for themes (${packageData.name} v${packageData.version})`);
|
|
11
|
+
}
|
|
6
12
|
if (!fs.existsSync(destPath)) {
|
|
7
13
|
fs.mkdirSync(destPath, { recursive: true });
|
|
8
14
|
}
|
|
15
|
+
const themesFile = path.join(__dirname, 'themes.json');
|
|
16
|
+
if (!fs.existsSync(themesFile)) {
|
|
17
|
+
if (verbose) {
|
|
18
|
+
console.log(`No theme list file found, doing nothing`);
|
|
19
|
+
}
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
9
22
|
|
|
10
|
-
const themes = JSON.parse(fs.readFileSync(
|
|
23
|
+
const themes = JSON.parse(fs.readFileSync(themesFile));
|
|
11
24
|
for (const theme of themes) {
|
|
12
25
|
const symlinkPath = path.join(destPath, theme);
|
|
13
26
|
const themePath = path.join(__dirname, 'dist', 'themes', theme)
|
|
14
|
-
if (fs.
|
|
15
|
-
|
|
27
|
+
if (fs.lstatSync(symlinkPath, { throwIfNoEntry: false })) {
|
|
28
|
+
const existingTarget = fs.readlinkSync(symlinkPath);
|
|
29
|
+
if (existingTarget !== themePath) {
|
|
30
|
+
console.log(`Removing existing symlink ${symlinkPath}`);
|
|
31
|
+
fs.unlinkSync(symlinkPath);
|
|
32
|
+
} else {
|
|
33
|
+
if (verbose) {
|
|
34
|
+
console.log(`${symlinkPath} already exists, not linking`);
|
|
35
|
+
}
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
16
38
|
}
|
|
17
39
|
console.log(`🔗 Linking ${themePath} → ${symlinkPath}`);
|
|
18
40
|
fs.symlinkSync(themePath, symlinkPath);
|
|
@@ -20,14 +42,15 @@ function generateThemeSymlinks(destPath) {
|
|
|
20
42
|
}
|
|
21
43
|
|
|
22
44
|
class SymlinkThemesPlugin {
|
|
23
|
-
constructor(destPath) {
|
|
45
|
+
constructor(destPath, opts) {
|
|
46
|
+
this.opts = opts || {};
|
|
24
47
|
this.destPath = destPath;
|
|
25
48
|
}
|
|
26
49
|
apply(compiler) {
|
|
27
50
|
compiler.hooks.beforeRun.tap(
|
|
28
51
|
'Symlink Themes Plugin',
|
|
29
52
|
(stats) => {
|
|
30
|
-
generateThemeSymlinks(this.destPath)
|
|
53
|
+
generateThemeSymlinks(this.destPath, this.opts);
|
|
31
54
|
}
|
|
32
55
|
);
|
|
33
56
|
}
|