Skip to content

Commit

Permalink
impr: Removing dark-mode only logo in README when preparing package. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
iwoplaza authored Sep 9, 2024
1 parent 6e20a8a commit d4d463f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
49 changes: 39 additions & 10 deletions packages/tgpu-dev-cli/prepack.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// @ts-check
/*
* Used as a pre-publishing step.
*/

import { exec } from 'node:child_process';
import * as fs from 'node:fs/promises';
import process from 'node:process';
import { omitBy } from 'remeda';
import { entries, mapValues, omitBy } from 'remeda';
import { Frog } from './log.mjs';

const cwd = new URL(`file:${process.cwd()}/`);
Expand Down Expand Up @@ -62,42 +63,70 @@ function deepMapStrings(value, transform, path = '') {
return value;
}

async function main() {
async function transformPackageJSON() {
const packageJsonUrl = new URL('./package.json', cwd);
const distPackageJsonUrl = new URL('./dist/package.json', cwd);

const packageJson = JSON.parse(await fs.readFile(packageJsonUrl, 'utf-8'));

await promiseExec(
'pnpm build && pnpm -w test:spec && pnpm test:types && biome check .',
);

// Altering paths in the package.json
const distPackageJson = deepMapStrings(packageJson, (_path, value) => {
if (value.startsWith('./dist/')) {
return value.replace(/^\.\/dist/, '.');
}

return value;
});

// Erroring out on any wildcard dependencies
for (const [moduleKey, versionSpec] of [
...entries(distPackageJson.dependencies),
...entries(distPackageJson.devDependencies),
]) {
if (versionSpec === '*' || versionSpec === 'workspace:*') {
throw new Error(
`Cannot depend on a module with a wildcard version. (${moduleKey}: ${versionSpec})`,
);
}
}

distPackageJson.private = false;
distPackageJson.scripts = {};
// Removing any links to other workspace packages.
// Removing any links to other workspace packages in dev dependencies.
distPackageJson.devDependencies = omitBy(
distPackageJson.devDependencies,
(/** @type {string} */ value) => value.startsWith('workspace:'),
);
// Removing workspace specifiers in dependencies.
distPackageJson.dependencies = mapValues(
distPackageJson.dependencies,
(/** @type {string} */ value) => value.replace(/^workspace:/, ''),
);

await fs.writeFile(
distPackageJsonUrl,
JSON.stringify(distPackageJson, undefined, 2),
'utf-8',
);
}

// Copying over README.md
async function transformReadme() {
const readmeUrl = new URL('./README.md', cwd);
const distReadmeUrl = new URL('./dist/README.md', cwd);
await fs.copyFile(readmeUrl, distReadmeUrl);

let readme = await fs.readFile(readmeUrl, 'utf-8');

// npmjs.com does not handle multiple logos well, remove the dark mode only one.
readme = readme.replace(/!.*#gh-dark-mode-only\)/, '');

await fs.writeFile(distReadmeUrl, readme, 'utf-8');
}

async function main() {
await promiseExec(
'pnpm build && pnpm -w test:spec && pnpm test:types && biome check .',
);

await Promise.all([transformPackageJSON(), transformReadme()]);

console.log(
`
Expand Down
6 changes: 3 additions & 3 deletions packages/typegpu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@
"@webgpu/types": "^0.1.43",
"typescript": "^5.3.3",
"tsup": "^8.0.2",
"@typegpu/wgsl-parser": "workspace:*",
"typegpu": "workspace:*",
"@typegpu/tgpu-dev-cli": "workspace:*"
"@typegpu/wgsl-parser": "workspace:0.0.0",
"typegpu": "workspace:0.1.0",
"@typegpu/tgpu-dev-cli": "workspace:0.0.0"
},
"packageManager": "pnpm@8.15.8+sha256.691fe176eea9a8a80df20e4976f3dfb44a04841ceb885638fe2a26174f81e65e",
"dependencies": {
Expand Down

0 comments on commit d4d463f

Please sign in to comment.