|
1 | 1 | import assert from 'node:assert';
|
2 | 2 | import { readFileSync, writeFileSync } from 'node:fs';
|
3 | 3 | import { tmpdir } from 'node:os';
|
4 |
| -import { mkdtemp, copyFile, cp } from 'node:fs/promises'; |
| 4 | +import { mkdtemp, copyFile, cp, rm } from 'node:fs/promises'; |
5 | 5 | import { join, basename } from 'node:path';
|
6 | 6 | import { $ } from 'execa';
|
7 | 7 | import { globby } from 'globby';
|
@@ -34,14 +34,28 @@ async function publicPackages() {
|
34 | 34 | return publicPaths;
|
35 | 35 | }
|
36 | 36 |
|
37 |
| -async function buildAll() { |
| 37 | +async function buildAll(tag) { |
38 | 38 | let publicPaths = await publicPackages();
|
| 39 | + |
| 40 | + if (!tag) { |
| 41 | + return await Promise.all( |
| 42 | + publicPaths.map((pkgPath) => { |
| 43 | + return $({ preferLocal: true, shell: true, cwd: pkgPath })(`pnpm pack`); |
| 44 | + }) |
| 45 | + ); |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +async function deleteTars() { |
| 50 | + let tars = await globby('packages/**/*.tgz', { ignore: ['**/node_modules', '**/dist'] }); |
| 51 | + |
39 | 52 | await Promise.all(
|
40 |
| - publicPaths.map((pkgPath) => { |
41 |
| - return $({ preferLocal: true, shell: true, cwd: pkgPath })(`pnpm pack`); |
| 53 | + tars.map((tar) => { |
| 54 | + return rm(tar); |
42 | 55 | })
|
43 | 56 | );
|
44 | 57 | }
|
| 58 | + |
45 | 59 | async function copyTars(toDir) {
|
46 | 60 | let tars = await globby('packages/**/*.tgz', { ignore: ['**/node_modules', '**/dist'] });
|
47 | 61 |
|
@@ -183,17 +197,22 @@ function banner(text) {
|
183 | 197 | `);
|
184 | 198 | }
|
185 | 199 |
|
186 |
| -async function main() { |
187 |
| - const [, , packageManager] = process.argv; |
| 200 | +const SUPPORTED = new Set(['npm', 'yarn', 'pnpm']); |
| 201 | +const TAGS = new Set(['alpha', 'beta', 'stable']); |
188 | 202 |
|
189 |
| - const SUPPORTED = new Set(['npm', 'yarn', 'pnpm']); |
| 203 | +async function main() { |
| 204 | + const [, , packageManager, tag] = process.argv; |
190 | 205 |
|
191 | 206 | assert(
|
192 | 207 | SUPPORTED.has(packageManager),
|
193 | 208 | `Expected passed arg, the packageManager (${packageManager}), to be one of ${[...SUPPORTED.values()].join(', ')}`
|
194 | 209 | );
|
195 | 210 |
|
196 |
| - await buildAll(); |
| 211 | + assert(TAGS.has(tag), `Expected passed arg, the tag (${tag}), to be one of ${[...TAGS.values()].join(', ')}`); |
| 212 | + |
| 213 | + await deleteTars(); |
| 214 | + await buildAll(tag); |
| 215 | + |
197 | 216 | let tmpDir = await createTempFolder();
|
198 | 217 | let projectDir = await copyProject(tmpDir);
|
199 | 218 |
|
|
0 commit comments