@omeps/chat-heatmap 1.0.0
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/README.md +3 -0
- package/chat-heatmap-1.0.0.zip +0 -0
- package/package.json +35 -0
- package/postinstall.js +124 -0
package/README.md
ADDED
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@omeps/chat-heatmap",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Erii Chat Heatmap plugin",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"postinstall": "node postinstall.js"
|
|
7
|
+
},
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"adm-zip": "^0.5.16"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"*.zip",
|
|
13
|
+
"postinstall.js"
|
|
14
|
+
],
|
|
15
|
+
"author": "spcookie",
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/spcookie/oh-my-erii-plugins.git",
|
|
20
|
+
"directory": "oh-my-erii-plugins/distribution/chat-heatmap"
|
|
21
|
+
},
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/spcookie/oh-my-erii-plugins/issues"
|
|
24
|
+
},
|
|
25
|
+
"homepage": "https://github.com/spcookie/oh-my-erii-plugins#readme",
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"erii",
|
|
31
|
+
"plugin",
|
|
32
|
+
"chat",
|
|
33
|
+
"heatmap"
|
|
34
|
+
]
|
|
35
|
+
}
|
package/postinstall.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const AdmZip = require('adm-zip');
|
|
4
|
+
|
|
5
|
+
const pkg = require('./package.json');
|
|
6
|
+
const isWindows = process.platform === 'win32';
|
|
7
|
+
|
|
8
|
+
// Detect install layout (mirrors erii/postinstall.js logic)
|
|
9
|
+
const spcookieFlat = path.resolve(__dirname, '..');
|
|
10
|
+
const spcookieNested = path.join(__dirname, 'node_modules', '@spcookie');
|
|
11
|
+
const nestedExists = fs.existsSync(spcookieNested);
|
|
12
|
+
|
|
13
|
+
function findEriiDir() {
|
|
14
|
+
const candidates = [
|
|
15
|
+
path.join(spcookieFlat, 'erii'),
|
|
16
|
+
path.join(__dirname, 'node_modules', '@spcookie', 'erii'),
|
|
17
|
+
];
|
|
18
|
+
for (const candidate of candidates) {
|
|
19
|
+
if (fs.existsSync(path.join(candidate, 'package.json'))) {
|
|
20
|
+
return candidate;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const eriiDir = findEriiDir();
|
|
27
|
+
const isGlobal = process.env.npm_config_global === 'true';
|
|
28
|
+
|
|
29
|
+
function findProjectRoot() {
|
|
30
|
+
if (isGlobal && eriiDir) {
|
|
31
|
+
return eriiDir;
|
|
32
|
+
}
|
|
33
|
+
return nestedExists ? __dirname : path.resolve(spcookieFlat, '..', '..');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const projectRoot = findProjectRoot();
|
|
37
|
+
|
|
38
|
+
const TAG = `[${pkg.name}]`;
|
|
39
|
+
|
|
40
|
+
function extractZip(zipPath, destDir) {
|
|
41
|
+
const zip = new AdmZip(zipPath);
|
|
42
|
+
zip.extractAllTo(destDir, true);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function createDirLink(target, linkPath) {
|
|
46
|
+
try {
|
|
47
|
+
const existing = fs.readlinkSync(linkPath);
|
|
48
|
+
const resolved = path.resolve(path.dirname(linkPath), existing);
|
|
49
|
+
if (resolved === path.resolve(target)) return 'skipped';
|
|
50
|
+
console.log(TAG, 'WARN: destination exists but points elsewhere, skipping.');
|
|
51
|
+
return 'skipped';
|
|
52
|
+
} catch {
|
|
53
|
+
// Not a symlink, continue
|
|
54
|
+
}
|
|
55
|
+
if (fs.existsSync(linkPath)) {
|
|
56
|
+
console.log(TAG, 'Destination already exists as regular file/dir, skipping.');
|
|
57
|
+
return 'skipped';
|
|
58
|
+
}
|
|
59
|
+
if (isWindows) {
|
|
60
|
+
fs.symlinkSync(target, linkPath, 'junction');
|
|
61
|
+
} else {
|
|
62
|
+
fs.symlinkSync(target, linkPath, 'dir');
|
|
63
|
+
}
|
|
64
|
+
return 'created';
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function main() {
|
|
68
|
+
const zipFiles = fs.readdirSync(__dirname).filter(f => f.endsWith('.zip'));
|
|
69
|
+
if (zipFiles.length === 0) {
|
|
70
|
+
console.log(TAG, 'No .zip found in package, skipping.');
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (zipFiles.length > 1) {
|
|
74
|
+
console.log(TAG, 'WARN: multiple .zip files found, using first:', zipFiles[0]);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const zipName = zipFiles[0];
|
|
78
|
+
const zipPath = path.join(__dirname, zipName);
|
|
79
|
+
const zipBase = zipName.replace(/\.zip$/, '');
|
|
80
|
+
const pluginDir = path.join(__dirname, zipBase);
|
|
81
|
+
|
|
82
|
+
if (!fs.existsSync(pluginDir)) {
|
|
83
|
+
console.log(TAG, `Extracting ${zipName}...`);
|
|
84
|
+
const tmpDir = path.join(__dirname, '.tmp-extract-' + Date.now());
|
|
85
|
+
fs.mkdirSync(tmpDir, {recursive: true});
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
extractZip(zipPath, tmpDir);
|
|
89
|
+
|
|
90
|
+
const entries = fs.readdirSync(tmpDir);
|
|
91
|
+
const dirEntries = entries.filter(e => fs.statSync(path.join(tmpDir, e)).isDirectory());
|
|
92
|
+
|
|
93
|
+
if (entries.length === 1 && dirEntries.length === 1) {
|
|
94
|
+
// Zip has a single root directory: move it to pluginDir
|
|
95
|
+
fs.renameSync(path.join(tmpDir, entries[0]), pluginDir);
|
|
96
|
+
} else {
|
|
97
|
+
// Zip has no root dir or multiple entries: use zipBase as container
|
|
98
|
+
fs.mkdirSync(pluginDir, {recursive: true});
|
|
99
|
+
for (const entry of entries) {
|
|
100
|
+
fs.renameSync(path.join(tmpDir, entry), path.join(pluginDir, entry));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
console.log(TAG, 'Done.');
|
|
104
|
+
} finally {
|
|
105
|
+
fs.rmSync(tmpDir, {recursive: true, force: true});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Link to plugins/
|
|
110
|
+
const pluginsDir = path.join(projectRoot, 'plugins');
|
|
111
|
+
fs.mkdirSync(pluginsDir, {recursive: true});
|
|
112
|
+
|
|
113
|
+
const linkName = path.basename(pluginDir);
|
|
114
|
+
const linkPath = path.join(pluginsDir, linkName);
|
|
115
|
+
|
|
116
|
+
const r = createDirLink(pluginDir, linkPath);
|
|
117
|
+
if (r === 'created') {
|
|
118
|
+
console.log(TAG, 'Linked:', linkName, '-> plugins/');
|
|
119
|
+
} else if (r === 'skipped') {
|
|
120
|
+
console.log(TAG, 'Already linked, skipping.');
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
main();
|