|
| 1 | +/** |
| 2 | + * `changeset version` updates the version and adds a changelog file in |
| 3 | + * the example apps, but we don't want to do that. So this script reverts |
| 4 | + * any "version" field changes and deletes the `CHANGELOG.md` file. |
| 5 | + * |
| 6 | + * Source: https://github.com/TooTallNate/nx.js/blob/main/.github/scripts/cleanup-examples.mjs |
| 7 | + */ |
| 8 | + |
| 9 | +import { |
| 10 | + readFileSync, |
| 11 | + readdirSync, |
| 12 | + statSync, |
| 13 | + unlinkSync, |
| 14 | + writeFileSync, |
| 15 | +} from 'node:fs'; |
| 16 | +import {join} from 'path'; |
| 17 | +import {fileURLToPath} from 'url'; |
| 18 | + |
| 19 | +const examplesUrl = new URL('../../examples', import.meta.url); |
| 20 | +const examplesDir = fileURLToPath(examplesUrl); |
| 21 | + |
| 22 | +console.log('Cleaning up examples...', examplesDir); |
| 23 | + |
| 24 | +for (const app of readdirSync(examplesDir)) { |
| 25 | + const appPath = join(examplesDir, app); |
| 26 | + if (statSync(appPath).isDirectory()) { |
| 27 | + const packageJsonPath = join(appPath, 'package.json'); |
| 28 | + const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8')); |
| 29 | + packageJson.version = '0.0.0'; |
| 30 | + writeFileSync( |
| 31 | + packageJsonPath, |
| 32 | + JSON.stringify(packageJson, null, 2) + '\n', |
| 33 | + ); |
| 34 | + |
| 35 | + try { |
| 36 | + const changelogUrl = new URL( |
| 37 | + `examples/${app}/CHANGELOG.md`, |
| 38 | + examplesUrl, |
| 39 | + ); |
| 40 | + console.log('Deleting', changelogUrl); |
| 41 | + unlinkSync(changelogUrl); |
| 42 | + } catch (err) { |
| 43 | + if (err.code !== 'ENOENT') throw err; |
| 44 | + } |
| 45 | + } |
| 46 | +} |
0 commit comments