-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpostversion.js
47 lines (43 loc) · 1.34 KB
/
postversion.js
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
const fs = require('fs');
const path = require('path');
fs.readdir(path.join(__dirname), { withFileTypes: true }, (err, files) => {
if (err) {
console.error('Error reading directory:', err);
reject(err);
return;
}
const packageJson = fs.readFileSync(path.join(__dirname, 'package.json'));
const rootPackageJson = JSON.parse(packageJson);
// Filter subdirectories
const subDirectories = files.filter(
(file) =>
file.isDirectory() &&
!file.name.startsWith('.') &&
file.name !== 'node_modules' &&
file.name !== 'tagspacespro',
);
subDirectories.map((dir) => {
const pluginJsonPath = path.join(__dirname, dir.name, 'package.json');
try {
const packageJsonContent = fs.readFileSync(pluginJsonPath);
const packageJsonObj = JSON.parse(packageJsonContent);
if (packageJsonObj.version !== rootPackageJson.version) {
packageJsonObj.version = rootPackageJson.version;
fs.writeFile(
pluginJsonPath,
JSON.stringify(packageJsonObj, null, 2),
'utf8',
() => {
console.log(
'Successfully update version:' + packageJsonObj.version,
);
},
);
}
} catch (ex) {
console.debug(
'Update package.json version: ' + dir.name + ' error:' + ex.message,
);
}
});
});