chore: update biome and publish script
This commit is contained in:
@@ -54,8 +54,9 @@
|
|||||||
"useNumberNamespace": "error",
|
"useNumberNamespace": "error",
|
||||||
"noInferrableTypes": "error",
|
"noInferrableTypes": "error",
|
||||||
"noUselessElse": "error",
|
"noUselessElse": "error",
|
||||||
"noNestedTernary": "off",
|
"useDefaultSwitchClause": "off",
|
||||||
"useDefaultSwitchClause": "off"
|
"noParameterProperties": "off",
|
||||||
|
"useConsistentMemberAccessibility": "off"
|
||||||
},
|
},
|
||||||
"correctness": {
|
"correctness": {
|
||||||
"useExhaustiveDependencies": "off",
|
"useExhaustiveDependencies": "off",
|
||||||
@@ -64,7 +65,8 @@
|
|||||||
"performance": {
|
"performance": {
|
||||||
"noDelete": "off",
|
"noDelete": "off",
|
||||||
"noAccumulatingSpread": "off",
|
"noAccumulatingSpread": "off",
|
||||||
"noBarrelFile": "off"
|
"noBarrelFile": "off",
|
||||||
|
"noNamespaceImport": "off"
|
||||||
},
|
},
|
||||||
"suspicious": {
|
"suspicious": {
|
||||||
"noExplicitAny": "off",
|
"noExplicitAny": "off",
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { execSync } from 'node:child_process';
|
import { execSync } from 'node:child_process';
|
||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import { join, resolve } from 'node:path';
|
import { dirname, join, resolve } from 'node:path';
|
||||||
import { dirname } from 'node:path';
|
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
import arg from 'arg';
|
import arg from 'arg';
|
||||||
import type { ReleaseType } from 'semver';
|
import type { ReleaseType } from 'semver';
|
||||||
@@ -47,7 +46,9 @@ const savePackageJson = (absPath: string, data: PackageJson) => {
|
|||||||
|
|
||||||
const exit = (message: string, error?: unknown) => {
|
const exit = (message: string, error?: unknown) => {
|
||||||
console.error(`\n\n❌ ${message}`);
|
console.error(`\n\n❌ ${message}`);
|
||||||
if (error) console.error('Error:', error);
|
if (error) {
|
||||||
|
console.error('Error:', error);
|
||||||
|
}
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -56,7 +57,9 @@ const checkUncommittedChanges = () => {
|
|||||||
const uncommittedFiles = execSync('git status --porcelain')
|
const uncommittedFiles = execSync('git status --porcelain')
|
||||||
.toString()
|
.toString()
|
||||||
.trim();
|
.trim();
|
||||||
if (uncommittedFiles) throw new Error('Uncommitted changes detected');
|
if (uncommittedFiles) {
|
||||||
|
throw new Error('Uncommitted changes detected');
|
||||||
|
}
|
||||||
console.log('✅ No uncommitted changes');
|
console.log('✅ No uncommitted changes');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
exit('Uncommitted changes', error);
|
exit('Uncommitted changes', error);
|
||||||
@@ -65,7 +68,9 @@ const checkUncommittedChanges = () => {
|
|||||||
|
|
||||||
const getNextVersion = (version: string, type: ReleaseType): string => {
|
const getNextVersion = (version: string, type: ReleaseType): string => {
|
||||||
const nextVersion = semver.inc(version, type);
|
const nextVersion = semver.inc(version, type);
|
||||||
if (!nextVersion) throw new Error('Invalid version');
|
if (!nextVersion) {
|
||||||
|
throw new Error('Invalid version');
|
||||||
|
}
|
||||||
return type.startsWith('pre')
|
return type.startsWith('pre')
|
||||||
? nextVersion.replace(/-.*$/, '-rc')
|
? nextVersion.replace(/-.*$/, '-rc')
|
||||||
: nextVersion;
|
: nextVersion;
|
||||||
@@ -73,7 +78,7 @@ const getNextVersion = (version: string, type: ReleaseType): string => {
|
|||||||
|
|
||||||
// Core functions
|
// Core functions
|
||||||
const loadPackages = (
|
const loadPackages = (
|
||||||
releaseType: ReleaseType,
|
releaseType: ReleaseType
|
||||||
): Record<string, PackageInfo> => {
|
): Record<string, PackageInfo> => {
|
||||||
const sdksPath = workspacePath('./packages/sdks');
|
const sdksPath = workspacePath('./packages/sdks');
|
||||||
const sdks = fs
|
const sdks = fs
|
||||||
@@ -85,25 +90,25 @@ const loadPackages = (
|
|||||||
sdks.map((sdk) => {
|
sdks.map((sdk) => {
|
||||||
const pkgPath = join(sdksPath, sdk, 'package.json');
|
const pkgPath = join(sdksPath, sdk, 'package.json');
|
||||||
const pkgJson = JSON.parse(
|
const pkgJson = JSON.parse(
|
||||||
fs.readFileSync(pkgPath, 'utf-8'),
|
fs.readFileSync(pkgPath, 'utf-8')
|
||||||
) as PackageJson;
|
) as PackageJson;
|
||||||
const version = pkgJson.version.replace(/-local$/, '');
|
const version = pkgJson.version.replace(/-local$/, '');
|
||||||
return [
|
return [
|
||||||
pkgJson.name,
|
pkgJson.name,
|
||||||
{
|
{
|
||||||
...pkgJson,
|
...pkgJson,
|
||||||
version: version,
|
version,
|
||||||
nextVersion: getNextVersion(version, releaseType),
|
nextVersion: getNextVersion(version, releaseType),
|
||||||
localPath: `./packages/sdks/${sdk}`,
|
localPath: `./packages/sdks/${sdk}`,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}),
|
})
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const findDependents = (
|
const findDependents = (
|
||||||
packages: Record<string, PackageInfo>,
|
packages: Record<string, PackageInfo>,
|
||||||
targetName: string,
|
targetName: string
|
||||||
): string[] => {
|
): string[] => {
|
||||||
const dependents = new Set([targetName]);
|
const dependents = new Set([targetName]);
|
||||||
const findDeps = (name: string) => {
|
const findDeps = (name: string) => {
|
||||||
@@ -121,7 +126,7 @@ const findDependents = (
|
|||||||
const updatePackageJsonForRelease = (
|
const updatePackageJsonForRelease = (
|
||||||
packages: Record<string, PackageInfo>,
|
packages: Record<string, PackageInfo>,
|
||||||
name: string,
|
name: string,
|
||||||
dependents: string[],
|
dependents: string[]
|
||||||
): void => {
|
): void => {
|
||||||
const { nextVersion, localPath, ...restPkgJson } = packages[name]!;
|
const { nextVersion, localPath, ...restPkgJson } = packages[name]!;
|
||||||
let newPkgJson: PackageJson = {
|
let newPkgJson: PackageJson = {
|
||||||
@@ -137,8 +142,8 @@ const updatePackageJsonForRelease = (
|
|||||||
? packages[depName]?.nextVersion ||
|
? packages[depName]?.nextVersion ||
|
||||||
depVersion.replace(/-local$/, '').replace(/^workspace:/, '')
|
depVersion.replace(/-local$/, '').replace(/^workspace:/, '')
|
||||||
: depVersion.replace(/-local$/, '').replace(/^workspace:/, ''),
|
: depVersion.replace(/-local$/, '').replace(/^workspace:/, ''),
|
||||||
],
|
]
|
||||||
),
|
)
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -200,7 +205,7 @@ const searchAndReplace = (path: string, search: RegExp, replace: string) => {
|
|||||||
|
|
||||||
const transformPackages = (
|
const transformPackages = (
|
||||||
packages: Record<string, PackageInfo>,
|
packages: Record<string, PackageInfo>,
|
||||||
dependents: string[],
|
dependents: string[]
|
||||||
): void => {
|
): void => {
|
||||||
for (const dep of dependents) {
|
for (const dep of dependents) {
|
||||||
const pkg = packages[dep];
|
const pkg = packages[dep];
|
||||||
@@ -210,7 +215,7 @@ const transformPackages = (
|
|||||||
searchAndReplace(
|
searchAndReplace(
|
||||||
workspacePath(pkg.localPath),
|
workspacePath(pkg.localPath),
|
||||||
new RegExp(`${currentVersion}`, 'g'),
|
new RegExp(`${currentVersion}`, 'g'),
|
||||||
nextVersion,
|
nextVersion
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -218,7 +223,7 @@ const transformPackages = (
|
|||||||
|
|
||||||
const buildPackages = (
|
const buildPackages = (
|
||||||
packages: Record<string, PackageInfo>,
|
packages: Record<string, PackageInfo>,
|
||||||
dependents: string[],
|
dependents: string[]
|
||||||
): void => {
|
): void => {
|
||||||
const versionEnvs = dependents.map((dep) => {
|
const versionEnvs = dependents.map((dep) => {
|
||||||
const envName = dep
|
const envName = dep
|
||||||
@@ -245,7 +250,7 @@ const buildPackages = (
|
|||||||
const publishPackages = (
|
const publishPackages = (
|
||||||
packages: Record<string, PackageInfo>,
|
packages: Record<string, PackageInfo>,
|
||||||
dependents: string[],
|
dependents: string[],
|
||||||
config: PublishConfig,
|
config: PublishConfig
|
||||||
): void => {
|
): void => {
|
||||||
if (config.clear) {
|
if (config.clear) {
|
||||||
execSync('rm -rf ~/.local/share/verdaccio/storage/@openpanel');
|
execSync('rm -rf ~/.local/share/verdaccio/storage/@openpanel');
|
||||||
@@ -253,16 +258,19 @@ const publishPackages = (
|
|||||||
|
|
||||||
for (const dep of dependents) {
|
for (const dep of dependents) {
|
||||||
console.log(`🚀 Publishing ${dep} to ${config.registry}`);
|
console.log(`🚀 Publishing ${dep} to ${config.registry}`);
|
||||||
|
console.log(
|
||||||
|
`📦 Install: pnpm install ${dep} --registry ${config.registry}`
|
||||||
|
);
|
||||||
execSync(`npm publish --access=public --registry ${config.registry}`, {
|
execSync(`npm publish --access=public --registry ${config.registry}`, {
|
||||||
cwd: workspacePath(packages[dep]!.localPath),
|
cwd: workspacePath(packages[dep]!.localPath),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (dep === '@openpanel/web') {
|
if (dep === '@openpanel/web') {
|
||||||
execSync(
|
execSync(
|
||||||
`cp ${workspacePath('packages/sdks/web/dist/src/tracker.global.js')} ${workspacePath('./apps/public/public/op1.js')}`,
|
`cp ${workspacePath('packages/sdks/web/dist/src/tracker.global.js')} ${workspacePath('./apps/public/public/op1.js')}`
|
||||||
);
|
);
|
||||||
execSync(
|
execSync(
|
||||||
`cp ${workspacePath('packages/sdks/web/dist/src/replay.global.js')} ${workspacePath('./apps/public/public/op1-replay.js')}`,
|
`cp ${workspacePath('packages/sdks/web/dist/src/replay.global.js')} ${workspacePath('./apps/public/public/op1-replay.js')}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -271,7 +279,7 @@ const publishPackages = (
|
|||||||
const restoreAndUpdateLocal = (
|
const restoreAndUpdateLocal = (
|
||||||
packages: Record<string, PackageInfo>,
|
packages: Record<string, PackageInfo>,
|
||||||
dependents: string[],
|
dependents: string[],
|
||||||
generatedReadmes: string[],
|
generatedReadmes: string[]
|
||||||
): void => {
|
): void => {
|
||||||
const filesToRestore = dependents
|
const filesToRestore = dependents
|
||||||
.map((dep) => join(workspacePath(packages[dep]!.localPath), 'package.json'))
|
.map((dep) => join(workspacePath(packages[dep]!.localPath), 'package.json'))
|
||||||
@@ -303,8 +311,8 @@ const restoreAndUpdateLocal = (
|
|||||||
: packages[depName]
|
: packages[depName]
|
||||||
? `workspace:${packages[depName]!.version}-local`
|
? `workspace:${packages[depName]!.version}-local`
|
||||||
: depVersion,
|
: depVersion,
|
||||||
],
|
]
|
||||||
),
|
)
|
||||||
),
|
),
|
||||||
devDependencies: Object.fromEntries(
|
devDependencies: Object.fromEntries(
|
||||||
Object.entries(restPkgJson.devDependencies || {}).map(
|
Object.entries(restPkgJson.devDependencies || {}).map(
|
||||||
@@ -315,8 +323,8 @@ const restoreAndUpdateLocal = (
|
|||||||
: packages[depName]
|
: packages[depName]
|
||||||
? `${packages[depName]!.version}-local`
|
? `${packages[depName]!.version}-local`
|
||||||
: depVersion,
|
: depVersion,
|
||||||
],
|
]
|
||||||
),
|
)
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -345,7 +353,7 @@ function main() {
|
|||||||
|
|
||||||
if (!RELEASE_TYPES.includes(args['--type'] as ReleaseType)) {
|
if (!RELEASE_TYPES.includes(args['--type'] as ReleaseType)) {
|
||||||
return exit(
|
return exit(
|
||||||
`Invalid release type. Valid types are: ${RELEASE_TYPES.join(', ')}`,
|
`Invalid release type. Valid types are: ${RELEASE_TYPES.join(', ')}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -361,7 +369,7 @@ function main() {
|
|||||||
|
|
||||||
for (const dep of dependents) {
|
for (const dep of dependents) {
|
||||||
console.log(
|
console.log(
|
||||||
`📦 ${dep} · Old Version: ${packages[dep]!.version} · Next Version: ${packages[dep]!.nextVersion}`,
|
`📦 ${dep} · Old Version: ${packages[dep]!.version} · Next Version: ${packages[dep]!.nextVersion}`
|
||||||
);
|
);
|
||||||
updatePackageJsonForRelease(packages, dep, dependents);
|
updatePackageJsonForRelease(packages, dep, dependents);
|
||||||
}
|
}
|
||||||
@@ -377,7 +385,7 @@ function main() {
|
|||||||
registry: args['--npm']
|
registry: args['--npm']
|
||||||
? 'https://registry.npmjs.org'
|
? 'https://registry.npmjs.org'
|
||||||
: 'http://localhost:4873',
|
: 'http://localhost:4873',
|
||||||
clear: args['--clear'] || false,
|
clear: args['--clear'] ?? false,
|
||||||
};
|
};
|
||||||
|
|
||||||
publishPackages(packages, dependents, config);
|
publishPackages(packages, dependents, config);
|
||||||
|
|||||||
Reference in New Issue
Block a user