Skip to content

OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.

move publish script to its own package

Carl-Gerhard Lindesvärdd706e89f68ec
diff --git a/package.json b/package.json
index cae122995..84ca93c7a 100644
--- a/package.json
+++ b/package.json
@@ -6,7 +6,6 @@
"author": "Carl-Gerhard Lindesvärd",
"packageManager": "[email protected]",
"module": "index.ts",
- "type": "module",
"scripts": {
"dev": "pnpm -r dev",
"format": "pnpm -r format --cache --cache-location=\"node_modules/.cache/.prettiercache\"",
@@ -15,11 +14,5 @@
"lint:fix": "pnpm -r lint --fix",
"lint:workspace": "pnpm dlx sherif@latest",
"typecheck": "pnpm -r typecheck"
- },
- "devDependencies": {
- "semver": "^7.5.4"
- },
- "peerDependencies": {
- "typescript": "^5.2.0"
}
}
diff --git a/packages/sdk/package.json b/packages/sdk/package.json
index ae2d00504..f90cacfc9 100644
--- a/packages/sdk/package.json
+++ b/packages/sdk/package.json
@@ -1,7 +1,6 @@
{
"name": "@mixan/sdk",
"version": "0.0.1",
- "type": "module",
"module": "index.ts",
"scripts": {
"lint": "eslint .",
diff --git a/packages/types/package.json b/packages/types/package.json
index cea1460ce..10e68f4e9 100644
--- a/packages/types/package.json
+++ b/packages/types/package.json
@@ -1,7 +1,6 @@
{
"name": "@mixan/types",
"version": "0.0.1",
- "type": "module",
"module": "index.ts",
"scripts": {
"lint": "eslint .",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index dd6e1dbae..295771684 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -6,15 +6,7 @@ settings:
importers:
- .:
- dependencies:
- typescript:
- specifier: ^5.2.0
- version: 5.2.2
- devDependencies:
- semver:
- specifier: ^7.5.4
- version: 7.5.4
+ .: {}
apps/web:
dependencies:
@@ -299,6 +291,28 @@ importers:
specifier: ^5.2.0
version: 5.2.2
+ tooling/publish:
+ dependencies:
+ semver:
+ specifier: ^7.5.4
+ version: 7.5.4
+ devDependencies:
+ '@mixan/prettier-config':
+ specifier: workspace:*
+ version: link:../prettier
+ '@mixan/tsconfig':
+ specifier: workspace:*
+ version: link:../typescript
+ '@types/eslint':
+ specifier: ^8.44.2
+ version: 8.44.6
+ eslint:
+ specifier: ^8.48.0
+ version: 8.52.0
+ typescript:
+ specifier: ^5.2.0
+ version: 5.2.2
+
tooling/typescript: {}
packages:
diff --git a/publish.ts b/publish.ts
deleted file mode 100644
index dd0fb8bab..000000000
--- a/publish.ts
+++ /dev/null
@@ -1,71 +0,0 @@
-import sdkPkg from './packages/sdk/package.json'
-import typesPkg from './packages/types/package.json'
-import fs from 'node:fs'
-import { execSync } from 'node:child_process'
-import semver from 'semver'
-
-function savePackageJson(path: string, data: Record<string, any>) {
- fs.writeFileSync(path, JSON.stringify(data, null, 2), 'utf-8')
-}
-
-function main() {
- const [version] = process.argv.slice(2)
-
- if (!version) {
- return console.error('Missing version')
- }
-
- if (!semver.valid(version)) {
- return console.error('Version is not valid')
- }
-
- const properties = {
- private: false,
- version,
- type: 'module',
- main: './dist/index.js',
- module: './dist/index.mjs',
- types: './dist/index.d.ts',
- files: ['dist'],
- }
-
- savePackageJson('./packages/sdk/package.json', {
- ...sdkPkg,
- ...properties,
- dependencies: Object.entries(sdkPkg.dependencies).reduce(
- (acc, [depName, depVersion]) => ({
- ...acc,
- [depName]: depName.startsWith('@mixan') ? version : depVersion,
- }),
- {}
- ),
- })
-
- savePackageJson('./packages/types/package.json', {
- ...typesPkg,
- ...properties,
- })
-
- try {
- execSync('pnpm dlx tsup', {
- cwd: './packages/sdk',
- })
- execSync('pnpm dlx tsup', {
- cwd: './packages/types',
- })
- } catch (error) {
- console.log('Build failed')
- console.log(error)
- process.exit(1)
- }
-
- execSync('npm publish --access=public', {
- cwd: './packages/sdk',
- })
-
- execSync('npm publish --access=public', {
- cwd: './packages/types',
- })
-}
-
-main()
diff --git a/tooling/publish/package.json b/tooling/publish/package.json
new file mode 100644
index 000000000..e8ac0f615
--- /dev/null
+++ b/tooling/publish/package.json
@@ -0,0 +1,29 @@
+{
+ "name": "@mixan/publish",
+ "version": "0.1.0",
+ "private": true,
+ "license": "MIT",
+ "scripts": {
+ "publish": "pnpm dlx ts-node publish.ts",
+ "lint": "eslint .",
+ "format": "prettier --check \"**/*.{mjs,ts,md,json}\"",
+ "typecheck": "tsc --noEmit"
+ },
+ "devDependencies": {
+ "@mixan/prettier-config": "workspace:*",
+ "@mixan/tsconfig": "workspace:*",
+ "@types/eslint": "^8.44.2",
+ "eslint": "^8.48.0",
+ "typescript": "^5.2.0"
+ },
+ "eslintConfig": {
+ "root": true,
+ "extends": [
+ "./base.js"
+ ]
+ },
+ "prettier": "@mixan/prettier-config",
+ "dependencies": {
+ "semver": "^7.5.4"
+ }
+}
diff --git a/tooling/publish/publish.ts b/tooling/publish/publish.ts
new file mode 100644
index 000000000..6b92adb0a
--- /dev/null
+++ b/tooling/publish/publish.ts
@@ -0,0 +1,98 @@
+import { execSync } from 'node:child_process';
+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 workspacePath = (relativePath: string) =>
+ path.resolve(__dirname, '../../', relativePath);
+
+function savePackageJson(absPath: string, data: Record<string, any>) {
+ fs.writeFileSync(absPath, JSON.stringify(data, null, 2), 'utf-8');
+}
+
+function exit(message: string, error?: unknown) {
+ console.log(`❌ ${message}`);
+ if (error instanceof Error) {
+ console.log(`Error: ${error.message}`);
+ } else if (typeof error === 'string') {
+ console.log(`Error: ${error}`);
+ }
+ process.exit(1);
+}
+
+function main() {
+ const [version] = process.argv.slice(2);
+
+ if (!version) {
+ return console.error('Missing version');
+ }
+
+ if (!semver.valid(version)) {
+ return console.error('Version is not valid');
+ }
+
+ const properties = {
+ private: false,
+ version,
+ type: 'module',
+ main: './dist/index.js',
+ module: './dist/index.mjs',
+ types: './dist/index.d.ts',
+ files: ['dist'],
+ };
+
+ 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,
+ }),
+ {}
+ ),
+ });
+
+ savePackageJson(workspacePath('./packages/types/package.json'), {
+ ...typesPkg,
+ ...properties,
+ });
+ } catch (error) {
+ exit('Update JSON files', error);
+ }
+
+ console.log('✅ Update JSON files');
+
+ try {
+ execSync('pnpm dlx tsup', {
+ cwd: workspacePath('./packages/sdk'),
+ });
+ execSync('pnpm dlx tsup', {
+ cwd: workspacePath('./packages/types'),
+ });
+ } catch (error) {
+ exit('Failed build packages', error);
+ }
+
+ console.log('✅ Built packages');
+
+ try {
+ execSync('npm publish --access=public', {
+ cwd: './packages/sdk',
+ });
+
+ execSync('npm publish --access=public', {
+ cwd: './packages/types',
+ });
+ } catch (error) {
+ exit('Failed publish packages', error);
+ }
+
+ console.log('✅ All done!');
+}
+
+main();
diff --git a/tooling/publish/tsconfig.json b/tooling/publish/tsconfig.json
new file mode 100644
index 000000000..75ade3d66
--- /dev/null
+++ b/tooling/publish/tsconfig.json
@@ -0,0 +1,9 @@
+{
+ "extends": "@mixan/tsconfig/base.json",
+ "compilerOptions": {
+ "module": "CommonJS",
+ "tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json"
+ },
+ "include": ["."],
+ "exclude": ["node_modules"]
+}