update publish script

This commit is contained in:
Carl-Gerhard Lindesvärd
2023-12-14 09:25:41 +01:00
parent 0a15a773e2
commit 131e6e7fb6
2 changed files with 30 additions and 20 deletions

View File

@@ -3,6 +3,7 @@
"version": "0.0.1",
"module": "index.ts",
"scripts": {
"build": "rm -rf dist && tsup",
"lint": "eslint .",
"format": "prettier --check \"**/*.{mjs,ts,md,json}\"",
"typecheck": "tsc --noEmit"

View File

@@ -3,9 +3,11 @@ import fs from 'node:fs';
import path from 'node:path';
import semver from 'semver';
import sdkPkg from '../../packages/sdk/package.json';
import typesPkg from '../../packages/types/package.json';
const sdkPackages = ['sdk', 'sdk-native', 'sdk-web'];
// const sdkPackages = ['sdk'];
const workspacePath = (relativePath: string) =>
path.resolve(__dirname, '../../', relativePath);
@@ -50,17 +52,20 @@ function main() {
};
try {
savePackageJson(workspacePath('./packages/sdk/package.json'), {
...sdkPkg,
...properties,
dependencies: Object.entries(sdkPkg.dependencies).reduce(
(acc, [depName, depVersion]) => ({
...acc,
[depName]: depName.startsWith('@mixan') ? version : depVersion,
}),
{}
),
});
for (const name of sdkPackages) {
const pkgJson = require(workspacePath(`./packages/${name}/package.json`));
savePackageJson(workspacePath(`./packages/${name}/package.json`), {
...pkgJson,
...properties,
dependencies: Object.entries(pkgJson.dependencies).reduce(
(acc, [depName, depVersion]) => ({
...acc,
[depName]: depName.startsWith('@mixan') ? version : depVersion,
}),
{}
),
});
}
savePackageJson(workspacePath('./packages/types/package.json'), {
...typesPkg,
@@ -73,11 +78,13 @@ function main() {
console.log('✅ Update JSON files');
try {
execSync('pnpm dlx tsup', {
cwd: workspacePath('./packages/sdk'),
});
execSync('pnpm dlx tsup', {
cwd: workspacePath('./packages/types'),
for (const name of sdkPackages) {
execSync('pnpm build', {
cwd: workspacePath(`./packages/${name}`),
});
}
execSync('pnpm build', {
cwd: workspacePath(`./packages/types`),
});
} catch (error) {
exit('Failed build packages', error);
@@ -86,9 +93,11 @@ function main() {
console.log('✅ Built packages');
try {
execSync('npm publish --access=public', {
cwd: workspacePath('./packages/sdk'),
});
for (const name of sdkPackages) {
execSync('npm publish --access=public', {
cwd: workspacePath(`./packages/${name}`),
});
}
execSync('npm publish --access=public', {
cwd: workspacePath('./packages/types'),