fix publish script
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
"typecheck": "tsc --noEmit"
|
"typecheck": "tsc --noEmit"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@openpanel/sdk": "1.0.0",
|
"@openpanel/sdk": "1.0.0-local",
|
||||||
"request-ip": "^3.3.0"
|
"request-ip": "^3.3.0"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
"typecheck": "tsc --noEmit"
|
"typecheck": "tsc --noEmit"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@openpanel/web": "1.0.0"
|
"@openpanel/web": "1.0.0-local"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"next": "^12.0.0 || ^13.0.0 || ^14.0.0",
|
"next": "^12.0.0 || ^13.0.0 || ^14.0.0",
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
"typecheck": "tsc --noEmit"
|
"typecheck": "tsc --noEmit"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@openpanel/sdk": "1.0.0"
|
"@openpanel/sdk": "1.0.0-local"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@openpanel/eslint-config": "workspace:*",
|
"@openpanel/eslint-config": "workspace:*",
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
"typecheck": "tsc --noEmit"
|
"typecheck": "tsc --noEmit"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@openpanel/sdk": "1.0.0"
|
"@openpanel/sdk": "1.0.0-local"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@openpanel/eslint-config": "workspace:*",
|
"@openpanel/eslint-config": "workspace:*",
|
||||||
|
|||||||
16
pnpm-lock.yaml
generated
16
pnpm-lock.yaml
generated
@@ -1168,8 +1168,8 @@ importers:
|
|||||||
packages/sdks/express:
|
packages/sdks/express:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@openpanel/sdk':
|
'@openpanel/sdk':
|
||||||
specifier: 1.0.0
|
specifier: 1.0.0-local
|
||||||
version: 1.0.0
|
version: link:../sdk
|
||||||
express:
|
express:
|
||||||
specifier: ^3.0.0 || ^4.0.0
|
specifier: ^3.0.0 || ^4.0.0
|
||||||
version: 4.18.2
|
version: 4.18.2
|
||||||
@@ -1208,8 +1208,8 @@ importers:
|
|||||||
packages/sdks/nextjs:
|
packages/sdks/nextjs:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@openpanel/web':
|
'@openpanel/web':
|
||||||
specifier: 1.0.0
|
specifier: 1.0.0-local
|
||||||
version: 1.0.0
|
version: link:../web
|
||||||
next:
|
next:
|
||||||
specifier: ^12.0.0 || ^13.0.0 || ^14.0.0
|
specifier: ^12.0.0 || ^13.0.0 || ^14.0.0
|
||||||
version: 14.1.0(react-dom@18.2.0)(react@18.2.0)
|
version: 14.1.0(react-dom@18.2.0)(react@18.2.0)
|
||||||
@@ -1248,8 +1248,8 @@ importers:
|
|||||||
packages/sdks/react-native:
|
packages/sdks/react-native:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@openpanel/sdk':
|
'@openpanel/sdk':
|
||||||
specifier: 1.0.0
|
specifier: 1.0.0-local
|
||||||
version: 1.0.0
|
version: link:../sdk
|
||||||
expo-application:
|
expo-application:
|
||||||
specifier: ^5
|
specifier: ^5
|
||||||
version: 5.3.1(expo@50.0.7)
|
version: 5.3.1(expo@50.0.7)
|
||||||
@@ -1315,8 +1315,8 @@ importers:
|
|||||||
packages/sdks/web:
|
packages/sdks/web:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@openpanel/sdk':
|
'@openpanel/sdk':
|
||||||
specifier: 1.0.0
|
specifier: 1.0.0-local
|
||||||
version: 1.0.0
|
version: link:../sdk
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@openpanel/eslint-config':
|
'@openpanel/eslint-config':
|
||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
|
|||||||
@@ -1,257 +1,296 @@
|
|||||||
import { exec, execSync } from 'node:child_process';
|
import { execSync } from 'node:child_process';
|
||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import arg from 'arg';
|
import arg from 'arg';
|
||||||
import type { ReleaseType } from 'semver';
|
import type { ReleaseType } from 'semver';
|
||||||
import semver, { RELEASE_TYPES } from 'semver';
|
import semver, { RELEASE_TYPES } from 'semver';
|
||||||
|
|
||||||
|
// Types
|
||||||
|
interface PackageJson {
|
||||||
|
name: string;
|
||||||
|
version: string;
|
||||||
|
dependencies?: Record<string, string>;
|
||||||
|
devDependencies?: Record<string, string>;
|
||||||
|
[key: string]: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PackageInfo extends PackageJson {
|
||||||
|
nextVersion: string;
|
||||||
|
localPath: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PublishConfig {
|
||||||
|
registry: string;
|
||||||
|
test: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Utility functions
|
||||||
const workspacePath = (relativePath: string) =>
|
const workspacePath = (relativePath: string) =>
|
||||||
path.resolve(__dirname, '../../', relativePath);
|
path.resolve(__dirname, '../../', relativePath);
|
||||||
|
|
||||||
function savePackageJson(absPath: string, data: Record<string, any>) {
|
const savePackageJson = (absPath: string, data: PackageJson) => {
|
||||||
fs.writeFileSync(absPath, JSON.stringify(data, null, 2), 'utf-8');
|
fs.writeFileSync(absPath, JSON.stringify(data, null, 2), 'utf-8');
|
||||||
}
|
|
||||||
|
|
||||||
function exit(message: string, error?: unknown) {
|
|
||||||
console.log(`\n\n❌ ${message}`);
|
|
||||||
if (error instanceof Error) {
|
|
||||||
console.log(`Error: ${error.message}`);
|
|
||||||
console.log(error);
|
|
||||||
} else if (typeof error === 'string') {
|
|
||||||
console.log(`Error: ${error}`);
|
|
||||||
}
|
|
||||||
console.log('\n');
|
|
||||||
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkUncommittedChanges() {
|
|
||||||
try {
|
|
||||||
const changedFiles = execSync('git ls-files --exclude-standard --others')
|
|
||||||
.toString()
|
|
||||||
.trim();
|
|
||||||
if (changedFiles !== '') {
|
|
||||||
throw new Error('Uncommitted changes');
|
|
||||||
}
|
|
||||||
execSync('git diff HEAD --exit-code');
|
|
||||||
console.log('✅ No uncommitted changes');
|
|
||||||
} catch (error) {
|
|
||||||
exit('Uncommitted changes');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getNextVersion(version: string, type: ReleaseType) {
|
|
||||||
const nextVersion = semver.inc(version, type);
|
|
||||||
if (!nextVersion) {
|
|
||||||
throw new Error('Invalid version');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type.startsWith('pre')) {
|
|
||||||
return nextVersion.replace(/-.*$/, '-beta');
|
|
||||||
}
|
|
||||||
|
|
||||||
return nextVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
type IPackageJson = {
|
|
||||||
type?: string;
|
|
||||||
name: string;
|
|
||||||
version: string;
|
|
||||||
dependencies: Record<string, string>;
|
|
||||||
devDependencies: Record<string, string>;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
type IPackageJsonWithExtra = IPackageJson & {
|
const exit = (message: string, error?: unknown) => {
|
||||||
nextVersion: string;
|
console.error(`\n\n❌ ${message}`);
|
||||||
localPath: string;
|
if (error) console.error('Error:', error);
|
||||||
|
process.exit(1);
|
||||||
|
};
|
||||||
|
|
||||||
|
const checkUncommittedChanges = () => {
|
||||||
|
try {
|
||||||
|
const uncommittedFiles = execSync('git status --porcelain')
|
||||||
|
.toString()
|
||||||
|
.trim();
|
||||||
|
if (uncommittedFiles) throw new Error('Uncommitted changes detected');
|
||||||
|
console.log('✅ No uncommitted changes');
|
||||||
|
} catch (error) {
|
||||||
|
exit('Uncommitted changes', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const getNextVersion = (version: string, type: ReleaseType): string => {
|
||||||
|
const nextVersion = semver.inc(version, type);
|
||||||
|
if (!nextVersion) throw new Error('Invalid version');
|
||||||
|
return type.startsWith('pre')
|
||||||
|
? nextVersion.replace(/-.*$/, '-beta')
|
||||||
|
: nextVersion;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Core functions
|
||||||
|
const loadPackages = (
|
||||||
|
releaseType: ReleaseType
|
||||||
|
): Record<string, PackageInfo> => {
|
||||||
|
const sdksPath = workspacePath('./packages/sdks');
|
||||||
|
const sdks = fs
|
||||||
|
.readdirSync(sdksPath, { withFileTypes: true })
|
||||||
|
.filter((dirent) => dirent.isDirectory() && !dirent.name.startsWith('.'))
|
||||||
|
.map((dirent) => dirent.name);
|
||||||
|
|
||||||
|
return Object.fromEntries(
|
||||||
|
sdks.map((sdk) => {
|
||||||
|
const pkgPath = path.join(sdksPath, sdk, 'package.json');
|
||||||
|
const pkgJson = JSON.parse(
|
||||||
|
fs.readFileSync(pkgPath, 'utf-8')
|
||||||
|
) as PackageJson;
|
||||||
|
return [
|
||||||
|
pkgJson.name,
|
||||||
|
{
|
||||||
|
...pkgJson,
|
||||||
|
version: pkgJson.version.replace(/-local$/, ''),
|
||||||
|
nextVersion: getNextVersion(pkgJson.version, releaseType),
|
||||||
|
localPath: `./packages/sdks/${sdk}`,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
})
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const findDependents = (
|
||||||
|
packages: Record<string, PackageInfo>,
|
||||||
|
targetName: string
|
||||||
|
): string[] => {
|
||||||
|
const dependents = new Set([targetName]);
|
||||||
|
const findDeps = (name: string) => {
|
||||||
|
Object.entries(packages).forEach(([pkgName, pkg]) => {
|
||||||
|
if (pkg.dependencies?.[name] && !dependents.has(pkgName)) {
|
||||||
|
dependents.add(pkgName);
|
||||||
|
findDeps(pkgName);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
findDeps(targetName);
|
||||||
|
return Array.from(dependents);
|
||||||
|
};
|
||||||
|
|
||||||
|
const updatePackageJsonForRelease = (
|
||||||
|
packages: Record<string, PackageInfo>,
|
||||||
|
name: string
|
||||||
|
): void => {
|
||||||
|
const { nextVersion, localPath, ...restPkgJson } = packages[name]!;
|
||||||
|
const newPkgJson: PackageJson = {
|
||||||
|
...restPkgJson,
|
||||||
|
private: false,
|
||||||
|
type: 'module',
|
||||||
|
main: './dist/index.js',
|
||||||
|
module: './dist/index.mjs',
|
||||||
|
types: './dist/index.d.ts',
|
||||||
|
files: ['dist'],
|
||||||
|
exports: {
|
||||||
|
'.': {
|
||||||
|
import: './dist/index.js',
|
||||||
|
require: './dist/index.cjs',
|
||||||
|
types: './dist/index.d.ts',
|
||||||
|
},
|
||||||
|
...(name === '@openpanel/nextjs'
|
||||||
|
? {
|
||||||
|
'./server': {
|
||||||
|
import: './dist/server.js',
|
||||||
|
require: './dist/server.cjs',
|
||||||
|
types: './dist/server.d.ts',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: {}),
|
||||||
|
},
|
||||||
|
version: nextVersion,
|
||||||
|
dependencies: Object.fromEntries(
|
||||||
|
Object.entries(restPkgJson.dependencies || {}).map(
|
||||||
|
([depName, depVersion]) => [
|
||||||
|
depName,
|
||||||
|
packages[depName]?.nextVersion || depVersion,
|
||||||
|
]
|
||||||
|
)
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
if (name === '@openpanel/nextjs') delete newPkgJson.type;
|
||||||
|
|
||||||
|
savePackageJson(workspacePath(`${localPath}/package.json`), newPkgJson);
|
||||||
|
packages[name]!.dependencies = newPkgJson.dependencies;
|
||||||
|
};
|
||||||
|
|
||||||
|
const buildPackages = (
|
||||||
|
packages: Record<string, PackageInfo>,
|
||||||
|
dependents: string[]
|
||||||
|
): void => {
|
||||||
|
const versionEnvs = dependents.map((dep) => {
|
||||||
|
const envName = dep
|
||||||
|
.replace(/@openpanel\//g, '')
|
||||||
|
.toUpperCase()
|
||||||
|
.replace(/[/-]/g, '_');
|
||||||
|
return `--env.${envName}_VERSION=${packages[dep]!.nextVersion}`;
|
||||||
|
});
|
||||||
|
|
||||||
|
dependents.forEach((dep) => {
|
||||||
|
console.log(`🔨 Building ${dep}`);
|
||||||
|
execSync(`pnpm build ${versionEnvs.join(' ')}`, {
|
||||||
|
cwd: workspacePath(packages[dep]!.localPath),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const publishPackages = (
|
||||||
|
packages: Record<string, PackageInfo>,
|
||||||
|
dependents: string[],
|
||||||
|
config: PublishConfig
|
||||||
|
): void => {
|
||||||
|
if (config.test) {
|
||||||
|
execSync('rm -rf ~/.local/share/verdaccio/storage/@openpanel');
|
||||||
|
}
|
||||||
|
|
||||||
|
dependents.forEach((dep) => {
|
||||||
|
console.log(`🚀 Publishing ${dep} to ${config.registry}`);
|
||||||
|
execSync(`npm publish --access=public --registry ${config.registry}`, {
|
||||||
|
cwd: workspacePath(packages[dep]!.localPath),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (dep === '@openpanel/web') {
|
||||||
|
execSync(
|
||||||
|
`cp ${workspacePath('packages/sdks/web/dist/src/tracker.global.js')} ${workspacePath('./apps/public/public/op1.js')}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const restoreAndUpdateLocal = (
|
||||||
|
packages: Record<string, PackageInfo>,
|
||||||
|
dependents: string[]
|
||||||
|
): void => {
|
||||||
|
const filesToRestore = dependents
|
||||||
|
.map((dep) => workspacePath(packages[dep]!.localPath))
|
||||||
|
.join(' ');
|
||||||
|
execSync(`git checkout ${filesToRestore}`);
|
||||||
|
|
||||||
|
dependents.forEach((dep) => {
|
||||||
|
const { nextVersion, localPath, ...restPkgJson } = packages[dep]!;
|
||||||
|
console.log(`🚀 Updating ${dep} (${nextVersion}-local)`);
|
||||||
|
|
||||||
|
const updatedPkgJson: PackageJson = {
|
||||||
|
...restPkgJson,
|
||||||
|
version: `${nextVersion}-local`,
|
||||||
|
dependencies: Object.fromEntries(
|
||||||
|
Object.entries(restPkgJson.dependencies || {}).map(
|
||||||
|
([depName, depVersion]) => [
|
||||||
|
depName,
|
||||||
|
dependents.includes(depName)
|
||||||
|
? `${packages[depName]!.nextVersion}-local`
|
||||||
|
: packages[depName]
|
||||||
|
? `${packages[depName]!.version}-local`
|
||||||
|
: depVersion,
|
||||||
|
]
|
||||||
|
)
|
||||||
|
),
|
||||||
|
devDependencies: Object.fromEntries(
|
||||||
|
Object.entries(restPkgJson.devDependencies || {}).map(
|
||||||
|
([depName, depVersion]) => [
|
||||||
|
depName,
|
||||||
|
dependents.includes(depName)
|
||||||
|
? `${packages[depName]!.nextVersion}-local`
|
||||||
|
: packages[depName]
|
||||||
|
? `${packages[depName]!.version}-local`
|
||||||
|
: depVersion,
|
||||||
|
]
|
||||||
|
)
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
savePackageJson(workspacePath(`${localPath}/package.json`), updatedPkgJson);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
|
// Main execution
|
||||||
const args = arg({
|
const args = arg({
|
||||||
'--name': String,
|
'--name': String,
|
||||||
'--publish': Boolean,
|
'--publish': Boolean,
|
||||||
'--test': Boolean,
|
'--test': Boolean,
|
||||||
'--skip-git': Boolean,
|
'--skip-git': Boolean,
|
||||||
// Semver
|
'--type': String,
|
||||||
'--type': String, // major, minor, patch, premajor, preminor, prepatch, or prerelease
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!args['--skip-git']) {
|
if (!args['--skip-git']) {
|
||||||
checkUncommittedChanges();
|
checkUncommittedChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
const pkgName = args['--name'];
|
if (!args['--name']) {
|
||||||
const type = args['--type'] as ReleaseType;
|
return exit('--name is required');
|
||||||
const test = args['--test'];
|
}
|
||||||
const publish = args['--publish'];
|
|
||||||
const packages: Record<string, IPackageJsonWithExtra> = {};
|
|
||||||
const registry = test
|
|
||||||
? 'http://localhost:4873'
|
|
||||||
: 'https://registry.npmjs.org';
|
|
||||||
|
|
||||||
if (!RELEASE_TYPES.includes(type)) {
|
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(', ')}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pkgName) {
|
const packages = loadPackages(args['--type'] as ReleaseType);
|
||||||
return exit('--name is requred');
|
const target = packages[args['--name']];
|
||||||
}
|
|
||||||
|
|
||||||
// Get all SDKs
|
|
||||||
const sdks = fs
|
|
||||||
.readdirSync(workspacePath('./packages/sdks'), {
|
|
||||||
withFileTypes: true,
|
|
||||||
})
|
|
||||||
.filter((item) => item.isDirectory() && !item.name.match(/^[._]/))
|
|
||||||
.map((item) => item.name);
|
|
||||||
|
|
||||||
// Get all SDK package.json
|
|
||||||
for (const name of sdks) {
|
|
||||||
const pkgJson = fs.readFileSync(
|
|
||||||
workspacePath(`./packages/sdks/${name}/package.json`),
|
|
||||||
'utf-8'
|
|
||||||
);
|
|
||||||
const parsed = JSON.parse(pkgJson) as IPackageJsonWithExtra;
|
|
||||||
parsed.nextVersion = getNextVersion(parsed.version, type);
|
|
||||||
parsed.localPath = `./packages/sdks/${name}`;
|
|
||||||
packages[parsed.name] = parsed;
|
|
||||||
}
|
|
||||||
|
|
||||||
const target = packages[pkgName];
|
|
||||||
|
|
||||||
if (!target) {
|
if (!target) {
|
||||||
return exit('Selected package does not exist');
|
return exit('Selected package does not exist');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find if any package is dependent on the target
|
const dependents = findDependents(packages, target.name);
|
||||||
const dependents: string[] = [target.name];
|
|
||||||
function findDependents(visitPackageName: string) {
|
|
||||||
Object.entries(packages).forEach(([_name, pkg]) => {
|
|
||||||
if (pkg.dependencies?.[visitPackageName]) {
|
|
||||||
dependents.push(pkg.name);
|
|
||||||
findDependents(pkg.name);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
findDependents(target.name);
|
|
||||||
|
|
||||||
function updatePackageJsonForRelease(name: string) {
|
dependents.forEach((dep) => {
|
||||||
const { nextVersion, localPath, ...restPkgJson } = packages[name]!;
|
|
||||||
const newPkgJson = JSON.parse(
|
|
||||||
JSON.stringify({
|
|
||||||
...restPkgJson,
|
|
||||||
private: false,
|
|
||||||
type: 'module',
|
|
||||||
main: './dist/index.js',
|
|
||||||
module: './dist/index.mjs',
|
|
||||||
types: './dist/index.d.ts',
|
|
||||||
files: ['dist'],
|
|
||||||
exports: {
|
|
||||||
'.': {
|
|
||||||
import: './dist/index.js',
|
|
||||||
require: './dist/index.cjs',
|
|
||||||
types: './dist/index.d.ts',
|
|
||||||
},
|
|
||||||
...(name === '@openpanel/nextjs'
|
|
||||||
? {
|
|
||||||
'./server': {
|
|
||||||
import: './dist/server.js',
|
|
||||||
require: './dist/server.cjs',
|
|
||||||
types: './dist/server.d.ts',
|
|
||||||
},
|
|
||||||
}
|
|
||||||
: {}),
|
|
||||||
},
|
|
||||||
version: nextVersion,
|
|
||||||
dependencies: Object.entries(restPkgJson.dependencies || {}).reduce(
|
|
||||||
(acc, [depName, depVersion]) => {
|
|
||||||
const dep = packages[depName];
|
|
||||||
if (!dep) {
|
|
||||||
return { ...acc, [depName]: depVersion };
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
...acc,
|
|
||||||
[depName]: dependents.includes(depName)
|
|
||||||
? dep.nextVersion
|
|
||||||
: depVersion,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
{}
|
|
||||||
),
|
|
||||||
})
|
|
||||||
) as IPackageJson;
|
|
||||||
|
|
||||||
if (name === '@openpanel/nextjs') {
|
|
||||||
delete newPkgJson.type;
|
|
||||||
}
|
|
||||||
|
|
||||||
savePackageJson(workspacePath(`${localPath}/package.json`), newPkgJson);
|
|
||||||
packages[name]!.dependencies = newPkgJson.dependencies;
|
|
||||||
}
|
|
||||||
|
|
||||||
dependents.forEach((dependent) => {
|
|
||||||
console.log(
|
console.log(
|
||||||
`📦 ${dependent} · Old Version: ${packages[dependent]?.version} · Next Version: ${packages[dependent]?.nextVersion}`
|
`📦 ${dep} · Old Version: ${packages[dep]!.version} · Next Version: ${packages[dep]!.nextVersion}`
|
||||||
);
|
);
|
||||||
updatePackageJsonForRelease(dependent);
|
updatePackageJsonForRelease(packages, dep);
|
||||||
});
|
});
|
||||||
|
|
||||||
const versionEnvs = dependents.map((dependent) => {
|
buildPackages(packages, dependents);
|
||||||
const { nextVersion } = packages[dependent]!;
|
|
||||||
const env = dependent
|
|
||||||
.replace(/@openpanel\//g, '')
|
|
||||||
.toUpperCase()
|
|
||||||
.replace(/\//g, '_')
|
|
||||||
.replace('-', '_');
|
|
||||||
return `--env.${env}_VERSION=${nextVersion}`;
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log('versionEnvs', versionEnvs);
|
if (args['--publish']) {
|
||||||
|
const config: PublishConfig = {
|
||||||
|
registry: args['--test']
|
||||||
|
? 'http://localhost:4873'
|
||||||
|
: 'https://registry.npmjs.org',
|
||||||
|
test: args['--test'] || false,
|
||||||
|
};
|
||||||
|
|
||||||
dependents.forEach((dependent) => {
|
publishPackages(packages, dependents, config);
|
||||||
console.log(`🔨 Building ${dependent}`);
|
restoreAndUpdateLocal(packages, dependents);
|
||||||
execSync(`pnpm build ${versionEnvs.join(' ')}`, {
|
|
||||||
cwd: workspacePath(packages[dependent]!.localPath),
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Publish
|
|
||||||
if (publish) {
|
|
||||||
if (test) {
|
|
||||||
execSync('rm -rf ~/.local/share/verdaccio/storage/@openpanel');
|
|
||||||
}
|
|
||||||
dependents.forEach((dependent) => {
|
|
||||||
console.log(`🚀 Publishing ${dependent} to ${registry}`);
|
|
||||||
execSync(`npm publish --access=public --registry ${registry}`, {
|
|
||||||
cwd: workspacePath(packages[dependent]!.localPath),
|
|
||||||
});
|
|
||||||
|
|
||||||
if (dependent === '@openpanel/web') {
|
|
||||||
execSync(
|
|
||||||
`cp ${workspacePath('packages/sdks/web/dist/src/tracker.global.js')} ${workspacePath('./apps/public/public/op1.js')}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Restoring package.json
|
|
||||||
const filesToRestore = dependents
|
|
||||||
.map((dependent) => workspacePath(packages[dependent]!.localPath))
|
|
||||||
.join(' ');
|
|
||||||
|
|
||||||
execSync(`git checkout ${filesToRestore}`);
|
|
||||||
|
|
||||||
// // Save new versions only 😈
|
|
||||||
dependents.forEach((dependent) => {
|
|
||||||
const { nextVersion, localPath, ...restPkgJson } = packages[dependent]!;
|
|
||||||
console.log(`🚀 Saving ${dependent} (${nextVersion})`);
|
|
||||||
savePackageJson(workspacePath(`${localPath}/package.json`), {
|
|
||||||
...restPkgJson,
|
|
||||||
version: nextVersion,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('✅ All done!');
|
console.log('✅ All done!');
|
||||||
|
|||||||
Reference in New Issue
Block a user