Skip to content

Commit

Permalink
chore: add publish script
Browse files Browse the repository at this point in the history
  • Loading branch information
matijagaspar committed Nov 18, 2024
1 parent ba75959 commit 0c7167c
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 4 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"test": "turbo test",
"lint": "biome ci",
"biome:check": "biome check --write",
"build": "turbo build --no-cache"
"build": "turbo build --no-cache",
"publish": "turbo publish"
},
"keywords": [
"orama",
Expand Down
3 changes: 3 additions & 0 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
"tsx": "^4.7.0",
"typescript": "^5.1.3"
},
"publishConfig": {
"access": "public"
},
"ts-standard": {
"ignore": [
"dist",
Expand Down
3 changes: 3 additions & 0 deletions packages/react-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
"tsx": "^4.7.0",
"typescript": "^5.1.3"
},
"publishConfig": {
"access": "public"
},
"ts-standard": {
"ignore": [
"dist",
Expand Down
3 changes: 3 additions & 0 deletions packages/secure-proxy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
"tsx": "^4.7.0",
"typescript": "^5.1.3"
},
"publishConfig": {
"access": "public"
},
"ts-standard": {
"ignore": [
"dist",
Expand Down
3 changes: 3 additions & 0 deletions packages/vue-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
"tsx": "^4.7.0",
"typescript": "^5.1.3"
},
"publishConfig": {
"access": "public"
},
"ts-standard": {
"ignore": [
"dist",
Expand Down
76 changes: 76 additions & 0 deletions scripts/publish.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { spawn } from 'node:child_process'
import { resolve, relative } from 'node:path'
import { fileURLToPath } from 'url'

import { exec } from 'child_process'


const getPackages = () => {
return new Promise((resolve, reject) => {
exec('pnpm turbo ls --output=json', (error, stdout, stderr) => {
if (error) {
return reject(error);
}
const result = JSON.parse(stdout);

return resolve(result.packages.items);
});
})
};


const rootDir = fileURLToPath(new URL('../', import.meta.url))

const packages = await getPackages()

function step(message) {
console.log(`\x1b[1m\x1b[32m--- ${message}\x1b[0m`)
}

async function execute(command, args, cwd) {
if (!Array.isArray(args)) {
args = [args]
}

let success, fail
const promise = new Promise((resolve, reject) => {
success = resolve
fail = reject
})

const rFolder = relative(rootDir, cwd)
step(`Executing: ${command} ${args.join(' ')} (from folder ${rFolder.trim() ? rFolder : '.'}) ...`)


const childProcess = spawn(command, args, { cwd, stdio: 'inherit', shell: true })

childProcess.on('error', e=>{
console.log(e)
})
childProcess.on('message', e=>{
console.log(e)
}
)

childProcess.on('close', code => {
if (code !== 0) {
fail(new Error(`Process failed with status code ${code}.`))
}

success()
})

return promise
}

async function main() {
process.env.BUILD_TOKENIZERS = '1'
await execute('pnpm', 'build', rootDir)

for (const {path:pkgPath} of packages) {
const cwd = resolve(rootDir, pkgPath)
await execute('pnpm', 'publish', cwd)
}
}

await main()
3 changes: 0 additions & 3 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
"cache": false,
"dependsOn": ["^build"]
},
"publish":{
"dependsOn": ["build", "^publish"]
},
"lint": {
"dependsOn": ["^lint"]
},
Expand Down

0 comments on commit 0c7167c

Please sign in to comment.