-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathupdate-wp-scripts.js
More file actions
33 lines (26 loc) · 908 Bytes
/
update-wp-scripts.js
File metadata and controls
33 lines (26 loc) · 908 Bytes
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
const axios = require('axios');
const fs = require('fs-extra');
const path = require('path');
const glob = require('glob');
async function updateWPScripts() {
try {
const { data } = await axios.get(
'https://registry.npmjs.org/@wordpress/scripts'
);
const latestVersion = data['dist-tags'].latest;
const packageJsonPaths = glob.sync('blocks/*/package.json');
for (const packageJsonPath of packageJsonPaths) {
const packageJson = await fs.readJson(packageJsonPath);
packageJson.devDependencies['@wordpress/scripts'] =
`^${latestVersion}`;
await fs.writeJson(packageJsonPath, packageJson, { spaces: 2 });
console.log(
`Updated @wordpress/scripts in ${path.relative('./', packageJsonPath)}`
);
}
console.log('All package.json files updated successfully');
} catch (error) {
console.error('Failed to update @wordpress/scripts:', error);
}
}
updateWPScripts();