Skip to content

Commit

Permalink
Invoke shared scripts directly from other packages
Browse files Browse the repository at this point in the history
  • Loading branch information
thobson committed Aug 16, 2024
1 parent 6499709 commit 9c9b24b
Show file tree
Hide file tree
Showing 23 changed files with 34 additions and 149 deletions.
8 changes: 4 additions & 4 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@
],
"scripts": {
"clean": "rimraf ./dist",
"typecheck": "tsc --project tsconfig.build.json --noEmit",
"typecheck": "tsc --noEmit",
"test": "vitest run",
"test:watch": "vitest dev",
"test:ui": "vitest --coverage.enabled=true --ui",
"test:coverage": "vitest run --coverage",
"build": "tsc --project tsconfig.build.json",
"build": "tsc --build",
"build:clean": "pnpm run clean && pnpm run build",
"build:readme": "LATEST=${npm_package_version} tsx scripts/replace-readme-tokens.ts",
"replaceTokens": "LATEST=${npm_package_version} tsx scripts/replace-tokens.ts",
"build:readme": "LATEST=${npm_package_version} tsx ../shared/scripts/replace-readme-tokens.ts ./packages/client",
"replaceTokens": "LATEST=${npm_package_version} tsx ../shared/scripts/replace-tokens.ts ./packages/client",
"build:production": "pnpm run build:clean && pnpm run replaceTokens && echo '' && publint",
"format": "prettier --write \"(src|scripts)/**/*.+(js|ts|json)\"",
"lint": "eslint ./src",
Expand Down
9 changes: 0 additions & 9 deletions packages/client/scripts/replace-readme-tokens.ts

This file was deleted.

11 changes: 0 additions & 11 deletions packages/client/scripts/replace-tokens.ts

This file was deleted.

8 changes: 0 additions & 8 deletions packages/client/tsconfig.build.json

This file was deleted.

1 change: 0 additions & 1 deletion packages/client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"include": [
"./src/**/*.ts",
"./src/**/*.json",
"./scripts/**/*.ts"
],
"exclude": ["./node_modules/**"]
}
8 changes: 4 additions & 4 deletions packages/create-sveltekit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@
],
"scripts": {
"clean": "rimraf ./dist",
"typecheck": "tsc --project tsconfig.build.json --noEmit",
"build": "tsc --project tsconfig.build.json",
"typecheck": "tsc --noEmit",
"build": "tsc --build",
"build:clean": "pnpm run clean && pnpm run build",
"build:readme": "LATEST=${npm_package_version} tsx scripts/replace-readme-tokens.ts",
"replaceTokens": "LATEST=${npm_package_version} tsx scripts/replace-readme-tokens.ts",
"build:readme": "LATEST=${npm_package_version} tsx ../shared/scripts/replace-readme-tokens.ts ./packages/create-sveltekit",
"replaceTokens": "LATEST=${npm_package_version} tsx ../shared/scripts/replace-tokens.ts ./packages/create-sveltekit",
"build:production": "pnpm run build:clean && pnpm run replaceTokens && echo '' && publint",
"format": "prettier --write \"(src|scripts)/**/*.+(js|ts|json)\"",
"lint": "eslint ./src",
Expand Down
9 changes: 0 additions & 9 deletions packages/create-sveltekit/scripts/replace-readme-tokens.ts

This file was deleted.

8 changes: 0 additions & 8 deletions packages/create-sveltekit/tsconfig.build.json

This file was deleted.

1 change: 0 additions & 1 deletion packages/create-sveltekit/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"include": [
"./src/**/*.ts",
"./src/**/*.json",
"./scripts/**/*.ts"
],
"exclude": ["./node_modules/**"]
}
8 changes: 4 additions & 4 deletions packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@
],
"scripts": {
"clean": "rimraf ./dist",
"typecheck": "tsc --project tsconfig.build.json --noEmit",
"typecheck": "tsc --noEmit",
"test": "vitest run",
"test:watch": "vitest dev",
"test:ui": "vitest --coverage.enabled=true --ui",
"test:coverage": "vitest run --coverage",
"build": "tsc --project tsconfig.build.json",
"build": "tsc --build",
"build:clean": "pnpm run clean && pnpm run build",
"build:readme": "LATEST=${npm_package_version} tsx scripts/replace-readme-tokens.ts",
"replaceTokens": "LATEST=${npm_package_version} tsx scripts/replace-tokens.ts",
"build:readme": "LATEST=${npm_package_version} tsx ../shared/scripts/replace-readme-tokens.ts ./packages/node",
"replaceTokens": "LATEST=${npm_package_version} tsx ../shared/scripts/replace-tokens.ts ./packages/node",
"build:production": "pnpm run build:clean && pnpm run replaceTokens && echo '' && publint",
"format": "prettier --write \"(src|scripts)/**/*.+(js|ts|json)\"",
"lint": "eslint ./src",
Expand Down
9 changes: 0 additions & 9 deletions packages/node/scripts/replace-readme-tokens.ts

This file was deleted.

11 changes: 0 additions & 11 deletions packages/node/scripts/replace-tokens.ts

This file was deleted.

8 changes: 0 additions & 8 deletions packages/node/tsconfig.build.json

This file was deleted.

1 change: 0 additions & 1 deletion packages/node/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"include": [
"./src/**/*.ts",
"./src/**/*.json",
"./scripts/**/*.ts"
],
"exclude": ["./node_modules/**"]
}
4 changes: 2 additions & 2 deletions packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"typecheck": "tsc --project tsconfig.build.json --noEmit",
"build": "tsc --project tsconfig.build.json",
"build:clean": "pnpm run clean && pnpm run build",
"build:readme": "LATEST=${npm_package_version} tsx scripts/replace-readme-tokens.ts",
"replaceTokens": "LATEST=${npm_package_version} tsx scripts/replace-tokens.ts",
"build:readme": "LATEST=${npm_package_version} tsx scripts/replace-readme-tokens.ts ./packages/shared",
"replaceTokens": "LATEST=${npm_package_version} tsx scripts/replace-tokens.ts ./packages/shared",
"build:production": "pnpm run build:clean && pnpm run replaceTokens && echo '' && publint",
"format": "prettier --write \"(src|scripts)/**/*.+(js|ts|json)\"",
"lint": "eslint ./src",
Expand Down
9 changes: 5 additions & 4 deletions packages/shared/scripts/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ export const disableConsole = () => {
return _console
}

// callers should pass import.mata.url
export const getPackageDir = (thisFileUrl: string) => {
const thisFilePath = fileURLToPath(thisFileUrl)
return path.resolve(path.dirname(thisFilePath), '../')
// callers should pass something like packages/shared
export const getPackageDir = (pathRelativeToRoot: string) => {
const thisFile = fileURLToPath(import.meta.url)
const root = path.resolve(thisFile, '../../../..')
return path.resolve(root, pathRelativeToRoot)
}

export const restoreConsole = (_console: ReturnType<typeof disableConsole>) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/scripts/replace-code-tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import path from 'node:path'

import { STATIC_VARS, disableConsole, getPackageDir, restoreConsole } from './common.js'

export const replaceCodeTokens = async (thisFilePath: string) => {
export const replaceCodeTokens = async (pathRelativeToRoot: string) => {
// Replace the tokens
const LATEST = process.env['LATEST']
if (!LATEST) {
console.error(kleur.red('Please set LATEST env variable'))
process.exit(-1)
}

const packageDirPath = getPackageDir(thisFilePath)
const packageDirPath = getPackageDir(pathRelativeToRoot)
const distPath = path.resolve(packageDirPath, './dist')

const vars = {
Expand Down
11 changes: 5 additions & 6 deletions packages/shared/scripts/replace-readme-tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { fileURLToPath } from 'node:url'

import { STATIC_VARS, copy, disableConsole, getPackageDir, restoreConsole } from './common.js'

export const replaceReadmeTokens = async (thisFileUrl: string) => {
export const replaceReadmeTokens = async (pathRelativeToRoot: string) => {
console.log(kleur.yellow('Copying README.template.md to README.md'))
const packageDirPath = getPackageDir(thisFileUrl)
const packageDirPath = getPackageDir(pathRelativeToRoot)

// Copy README.template.md to README.md and replace tokens
const readmeTemplate = path.resolve(packageDirPath, './README.template.md')
Expand Down Expand Up @@ -37,8 +37,7 @@ export const replaceReadmeTokens = async (thisFileUrl: string) => {
}
}

// see https://stackoverflow.com/a/60309682
if (process.argv[1] === fileURLToPath(import.meta.url)) {
console.log('Replacing packages/shared tokens')
await replaceReadmeTokens(import.meta.url)
if (process.argv[1] === fileURLToPath(import.meta.url) && process.argv[2]) {
console.log(`Replacing ${process.argv[2]} tokens`)
await replaceReadmeTokens(process.argv[2])
}
9 changes: 4 additions & 5 deletions packages/shared/scripts/replace-tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import { fileURLToPath } from 'node:url'
import { replaceCodeTokens } from './replace-code-tokens.js'
import { replaceReadmeTokens } from './replace-readme-tokens.js'

// see https://stackoverflow.com/a/60309682
if (process.argv[1] === fileURLToPath(import.meta.url)) {
console.log('Replacing packages/shared tokens')
await replaceReadmeTokens(import.meta.url)
await replaceCodeTokens(import.meta.url)
if (process.argv[1] === fileURLToPath(import.meta.url) && process.argv[2]) {
console.log(`Replacing ${process.argv[2]} tokens`)
await replaceReadmeTokens(process.argv[2])
await replaceCodeTokens(process.argv[2])
}
6 changes: 3 additions & 3 deletions packages/sveltekit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
"lint:fix": "pnpm run lint --fix",
"build": "pnpm run check:errors && svelte-package",
"build:clean": "pnpm run clean && pnpm run build",
"build:readme": "LATEST=${npm_package_version} tsx scripts/replace-readme-tokens.ts",
"replaceTokens": "LATEST=${npm_package_version} tsx scripts/replace-tokens.ts",
"build:production": "pnpm run build:clean && pnpm run replaceTokens && echo '' && publint",
"build:readme": "LATEST=${npm_package_version} tsx ../shared/scripts/replace-readme-tokens.ts ./packages/sveltekit",
"replaceTokens": "LATEST=${npm_package_version} tsx ../shared/scripts/replace-tokens.ts ./packages/sveltekit",
"build:production": "pnpm run build:clean && pnpm run replaceTokens && echo '' && publint",
"prepublishOnly": "pnpm run build:production",
"upgrade:deps": "ncu --peer -x effect -x @effect/* -u"
},
Expand Down
8 changes: 0 additions & 8 deletions packages/sveltekit/scripts/replace-readme-tokens.ts

This file was deleted.

10 changes: 0 additions & 10 deletions packages/sveltekit/scripts/replace-tokens.ts

This file was deleted.

22 changes: 1 addition & 21 deletions packages/sveltekit/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,5 @@
"skipLibCheck": true,
"sourceMap": true,
"strict": true
},
"include": [
"ambient.d.ts",
"non-ambient.d.ts",
"./.svelte-kit/types/**/$types.d.ts",
"./vite.config.js",
"./vite.config.ts",
"./src/**/*.js",
"./src/**/*.ts",
"./src/**/*.svelte",
"./tests/**/*.js",
"./tests/**/*.ts",
"./tests/**/*.svelte",
"./scripts/**/*.ts"
],
"exclude": [
"./node_modules/**",
"./src/service-worker.js",
"./src/service-worker.ts",
"./src/service-worker.d.ts"
]
}
}

0 comments on commit 9c9b24b

Please sign in to comment.