-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f9f54b9
commit 97ebcd1
Showing
7 changed files
with
213 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { readFile, writeFile, unlink } from 'node:fs/promises'; | ||
import { join } from 'node:path'; | ||
import chalk from 'chalk'; | ||
import { execa } from 'execa'; | ||
import { mkdirp } from 'mkdirp'; | ||
import { rimraf } from 'rimraf'; | ||
import { x as untar } from 'tar'; | ||
import { packages } from './packages.mjs'; | ||
import { writeFileSync } from 'node:fs'; | ||
|
||
export async function previewPublish() { | ||
const dist = new URL('../dist', import.meta.url).pathname; | ||
const pkgs = packages('@glimmer'); | ||
|
||
await mkdirp(dist); | ||
await rimraf(dist + '/*.tgz', { glob: true }); | ||
|
||
const pack = pkgs.map(async (pkg) => { | ||
try { | ||
await execa('pnpm', ['pack', '--pack-destination', dist], { | ||
cwd: pkg.path, | ||
}); | ||
|
||
console.log(chalk.green(`Successfully packed ${pkg.name}`)); | ||
} catch (error: unknown) { | ||
let message = `Failed to pack ${pkg.name}`; | ||
|
||
if (error instanceof Error) { | ||
message += `\n\n${error.stack}`; | ||
} | ||
|
||
throw new Error(message); | ||
} | ||
}); | ||
|
||
await Promise.all(pack); | ||
|
||
const unpack = pkgs.map(async (pkg) => { | ||
try { | ||
const pkgDest = join(dist, pkg.name); | ||
|
||
await mkdirp(pkgDest); | ||
await rimraf(pkgDest + '/**/*'); | ||
|
||
const tarball = join( | ||
dist, | ||
pkg.name.replace('@', '').replace('/', '-') + `-${pkg.version}.tgz` | ||
); | ||
|
||
await untar({ | ||
file: tarball, | ||
strip: 1, | ||
cwd: pkgDest, | ||
}); | ||
|
||
await unlink(tarball); | ||
|
||
// https://github.com/pnpm/pnpm/issues/881 | ||
const packageJsonPath = join(pkgDest, 'package.json'); | ||
const packageJson = JSON.parse(await readFile(packageJsonPath, { encoding: 'utf8' })); | ||
delete packageJson.devDependencies; | ||
await writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), { | ||
encoding: 'utf8', | ||
}); | ||
|
||
console.log(chalk.green(`Successfully unpacked ${pkg.name}`)); | ||
} catch (error: unknown) { | ||
let message = `Failed to unpack ${pkg.name}`; | ||
|
||
if (error instanceof Error) { | ||
message += `\n\n${error.stack}`; | ||
} | ||
|
||
throw new Error(message); | ||
} | ||
}); | ||
|
||
await Promise.all(unpack); | ||
|
||
const packageJson = `{ | ||
"name": "glimmer-vm", | ||
"private": true, | ||
"overrides": { | ||
${pkgs.map((pkg) => ` "${pkg.name}": "workspace:*"`).join(',\n')} | ||
} | ||
} | ||
`; | ||
|
||
const workspaceYaml = 'packages:\n' + pkgs.map((pkg) => ` - '${pkg.name}'\n`).join(''); | ||
|
||
await writeFile(join(dist, 'package.json'), packageJson, { encoding: 'utf8' }); | ||
await writeFile(join(dist, 'pnpm-workspace.yaml'), workspaceYaml, { encoding: 'utf8' }); | ||
|
||
await execa('pnpm', ['install'], { | ||
cwd: dist, | ||
stdio: 'inherit', | ||
}); | ||
|
||
console.log(chalk.green(`Successfully installed packages`)); | ||
} | ||
|
||
if (import.meta.url === 'file://' + process.argv[1]) { | ||
console.log('Previewing Publish...'); | ||
|
||
await previewPublish(); | ||
} |
Oops, something went wrong.