diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3a4648c2e..45ef3356e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -70,6 +70,8 @@ pnpm play:nuxt # Run the playground with Nuxt pnpm clean: all # Clean all node_modules pnpm clean:dist # Clean dist folder in all packages pnpm clean:dts # Clean dts folder in all packages + +pnpm oku # Run Oku CLI (packages/cli) // pnpm oku publish (publish packages) ``` ## Testing diff --git a/package.json b/package.json index bc1c07764..125cbb6b8 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "build": "pnpm nx run-many -t build", "build:skip": "pnpm nx run-many -t build --skip-nx-cache", "p:build": "tsup", + "oku": "pnpm jiti ./scripts/index.ts", "story": "pnpm storybook dev -p 6006 --no-open", "lint": "eslint . --cache ", "lint:fix": "eslint . --fix --cache", @@ -37,6 +38,7 @@ "update:version": "esno scripts/update-version.ts" }, "devDependencies": { + "@clack/prompts": "^0.7.0", "@egoist/tailwindcss-icons": "^1.1.0", "@iconify-json/ph": "^1.1.6", "@oku-ui/alert-dialog": "workspace:^", diff --git a/packages/components/alert-dialog/package.json b/packages/components/alert-dialog/package.json index 540e77794..aaf520939 100644 --- a/packages/components/alert-dialog/package.json +++ b/packages/components/alert-dialog/package.json @@ -1,7 +1,7 @@ { "name": "@oku-ui/alert-dialog", "type": "module", - "version": "0.4.0-alpha.12", + "version": "0.1.1", "license": "MIT", "source": "src/index.ts", "funding": "https://github.com/sponsors/productdevbook", diff --git a/packages/components/alert-dialog/src/alert-dialog-description-warning.ts b/packages/components/alert-dialog/src/alert-dialog-description-warning.ts index 3b3335237..407806be1 100644 --- a/packages/components/alert-dialog/src/alert-dialog-description-warning.ts +++ b/packages/components/alert-dialog/src/alert-dialog-description-warning.ts @@ -1,12 +1,12 @@ import { defineComponent, toRefs, watchEffect } from 'vue' -import { CONTENT_NAME, DESCRIPTION_NAME, DESCRIPTION_WARNING_NAME, dialogDescriptionWarningProps } from './props' +import { CONTENT_NAME, DESCRIPTION_NAME, DESCRIPTION_WARNING_NAME, alertDialogDescriptionWarningProps } from './props' const alertDialogDescriptionWarning = defineComponent({ name: DESCRIPTION_WARNING_NAME, inheritAttrs: false, props: { - ...dialogDescriptionWarningProps.props, + ...alertDialogDescriptionWarningProps.props, }, setup(props, { attrs: _attrs }) { const { contentRef } = toRefs(props) diff --git a/packages/components/alert-dialog/src/alert-dialog-description.ts b/packages/components/alert-dialog/src/alert-dialog-description.ts index a4842ca9a..19d69ddf8 100644 --- a/packages/components/alert-dialog/src/alert-dialog-description.ts +++ b/packages/components/alert-dialog/src/alert-dialog-description.ts @@ -2,13 +2,13 @@ import { defineComponent, h, mergeProps, reactive, toRefs } from 'vue' import { reactiveOmit, useForwardRef } from '@oku-ui/use-composable' import { OkuDialogDescription } from '@oku-ui/dialog' import type { AlertDialogDescriptionNaviteElement } from './props' -import { DESCRIPTION_NAME, alertDialogDescriptionProps, scopeAlertDialogProps, useAlertDialogScope } from './props' +import { DESCRIPTION_NAME, alertDialogDescriptionWarningProps, scopeAlertDialogProps, useAlertDialogScope } from './props' const alertDialogDescription = defineComponent({ name: DESCRIPTION_NAME, inheritAttrs: false, props: { - ...alertDialogDescriptionProps.props, + ...alertDialogDescriptionWarningProps.props, ...scopeAlertDialogProps, }, setup(props, { attrs, slots }) { diff --git a/packages/components/alert-dialog/src/index.ts b/packages/components/alert-dialog/src/index.ts index 08d47ed31..55db805b0 100644 --- a/packages/components/alert-dialog/src/index.ts +++ b/packages/components/alert-dialog/src/index.ts @@ -52,6 +52,6 @@ export { alertDialogPortalProps, alertDialogTitleProps, alertDialogTriggerProps, - dialogDescriptionWarningProps, + alertDialogDescriptionWarningProps, scopeAlertDialogProps, } from './props' diff --git a/packages/components/alert-dialog/src/props.ts b/packages/components/alert-dialog/src/props.ts index afec4be64..e88bba150 100644 --- a/packages/components/alert-dialog/src/props.ts +++ b/packages/components/alert-dialog/src/props.ts @@ -176,7 +176,7 @@ export const alertDialogDescriptionProps = { export type DescriptionWarningProps = { contentRef: HTMLDivElement } -export const dialogDescriptionWarningProps = { +export const alertDialogDescriptionWarningProps = { props: { contentRef: { type: [Object, null] as PropType, diff --git a/packages/components/primitives/package.json b/packages/components/primitives/package.json index 76ee21a4c..649b4691f 100644 --- a/packages/components/primitives/package.json +++ b/packages/components/primitives/package.json @@ -37,6 +37,7 @@ "vue": "^3.3.0" }, "dependencies": { + "@oku-ui/alert-dialog": "latest", "@oku-ui/aspect-ratio": "latest", "@oku-ui/avatar": "latest", "@oku-ui/checkbox": "latest", diff --git a/packages/components/primitives/src/index.ts b/packages/components/primitives/src/index.ts index a60e503bf..2a369991d 100644 --- a/packages/components/primitives/src/index.ts +++ b/packages/components/primitives/src/index.ts @@ -17,3 +17,5 @@ export * from '@oku-ui/slider' export * from '@oku-ui/radio-group' export * from '@oku-ui/hover-card' export * from '@oku-ui/dialog' +export * from '@oku-ui/alert-dialog' +export * from '@oku-ui/scroll-area' diff --git a/packages/components/scroll-area/package.json b/packages/components/scroll-area/package.json index e2b1e8cd0..e78cc20ba 100644 --- a/packages/components/scroll-area/package.json +++ b/packages/components/scroll-area/package.json @@ -1,7 +1,7 @@ { "name": "@oku-ui/scroll-area", "type": "module", - "version": "0.4.0-alpha.11", + "version": "0.0.2", "license": "MIT", "source": "src/index.ts", "funding": "https://github.com/sponsors/productdevbook", diff --git a/packages/core/arrow/package.json b/packages/core/arrow/package.json index 85b4a97e3..bfb6bfaf0 100644 --- a/packages/core/arrow/package.json +++ b/packages/core/arrow/package.json @@ -1,7 +1,7 @@ { "name": "@oku-ui/arrow", "type": "module", - "version": "0.4.0", + "version": "0.5.0", "license": "MIT", "source": "src/index.ts", "funding": "https://github.com/sponsors/productdevbook", diff --git a/packages/core/collection/package.json b/packages/core/collection/package.json index 7f50e97cf..7fa225544 100644 --- a/packages/core/collection/package.json +++ b/packages/core/collection/package.json @@ -1,7 +1,7 @@ { "name": "@oku-ui/collection", "type": "module", - "version": "0.4.0", + "version": "0.5.0", "license": "MIT", "source": "src/index.ts", "funding": "https://github.com/sponsors/productdevbook", diff --git a/packages/core/direction/package.json b/packages/core/direction/package.json index cbcff19aa..fb4f2e2cc 100644 --- a/packages/core/direction/package.json +++ b/packages/core/direction/package.json @@ -1,7 +1,7 @@ { "name": "@oku-ui/direction", "type": "module", - "version": "0.4.0", + "version": "0.5.0", "license": "MIT", "source": "src/index.ts", "funding": "https://github.com/sponsors/productdevbook", diff --git a/packages/core/dismissable-layer/package.json b/packages/core/dismissable-layer/package.json index cfe07e0df..1894a2cd2 100644 --- a/packages/core/dismissable-layer/package.json +++ b/packages/core/dismissable-layer/package.json @@ -1,7 +1,7 @@ { "name": "@oku-ui/dismissable-layer", "type": "module", - "version": "0.4.0", + "version": "0.5.0", "license": "MIT", "source": "src/index.ts", "funding": "https://github.com/sponsors/productdevbook", diff --git a/packages/core/focus-guards/package.json b/packages/core/focus-guards/package.json index cf9c08420..85df16f7f 100644 --- a/packages/core/focus-guards/package.json +++ b/packages/core/focus-guards/package.json @@ -1,7 +1,7 @@ { "name": "@oku-ui/focus-guards", "type": "module", - "version": "0.4.0", + "version": "0.5.0", "license": "MIT", "source": "src/index.ts", "funding": "https://github.com/sponsors/productdevbook", diff --git a/packages/core/focus-scope/package.json b/packages/core/focus-scope/package.json index 010b6062a..4f927262a 100644 --- a/packages/core/focus-scope/package.json +++ b/packages/core/focus-scope/package.json @@ -1,7 +1,7 @@ { "name": "@oku-ui/focus-scope", "type": "module", - "version": "0.4.0", + "version": "0.5.0", "license": "MIT", "source": "src/index.ts", "funding": "https://github.com/sponsors/productdevbook", diff --git a/packages/core/popper/package.json b/packages/core/popper/package.json index 15fc1b511..942f434c9 100644 --- a/packages/core/popper/package.json +++ b/packages/core/popper/package.json @@ -1,7 +1,7 @@ { "name": "@oku-ui/popper", "type": "module", - "version": "0.4.0", + "version": "0.5.0", "license": "MIT", "source": "src/index.ts", "funding": "https://github.com/sponsors/productdevbook", diff --git a/packages/core/portal/package.json b/packages/core/portal/package.json index 3f6c2207d..c19c3f67a 100644 --- a/packages/core/portal/package.json +++ b/packages/core/portal/package.json @@ -1,7 +1,7 @@ { "name": "@oku-ui/portal", "type": "module", - "version": "0.4.0", + "version": "0.5.0", "license": "MIT", "source": "src/index.ts", "funding": "https://github.com/sponsors/productdevbook", diff --git a/packages/core/presence/package.json b/packages/core/presence/package.json index c008c0fa2..15e6d521e 100644 --- a/packages/core/presence/package.json +++ b/packages/core/presence/package.json @@ -1,7 +1,7 @@ { "name": "@oku-ui/presence", "type": "module", - "version": "0.4.0", + "version": "0.5.0", "license": "MIT", "source": "src/index.ts", "funding": "https://github.com/sponsors/productdevbook", diff --git a/packages/core/primitive/package.json b/packages/core/primitive/package.json index 7df3b262a..b75b0f42a 100644 --- a/packages/core/primitive/package.json +++ b/packages/core/primitive/package.json @@ -1,7 +1,7 @@ { "name": "@oku-ui/primitive", "type": "module", - "version": "0.4.0", + "version": "0.5.0", "license": "MIT", "source": "src/index.ts", "funding": "https://github.com/sponsors/productdevbook", diff --git a/packages/core/provide/package.json b/packages/core/provide/package.json index 3406e725d..51a4e005e 100644 --- a/packages/core/provide/package.json +++ b/packages/core/provide/package.json @@ -1,7 +1,7 @@ { "name": "@oku-ui/provide", "type": "module", - "version": "0.4.0", + "version": "0.5.0", "license": "MIT", "source": "src/index.ts", "funding": "https://github.com/sponsors/productdevbook", diff --git a/packages/core/roving-focus/package.json b/packages/core/roving-focus/package.json index 50aa91a28..2aab7b24e 100644 --- a/packages/core/roving-focus/package.json +++ b/packages/core/roving-focus/package.json @@ -1,7 +1,7 @@ { "name": "@oku-ui/roving-focus", "type": "module", - "version": "0.4.0", + "version": "0.5.0", "license": "MIT", "source": "src/index.ts", "funding": "https://github.com/sponsors/productdevbook", diff --git a/packages/core/slot/package.json b/packages/core/slot/package.json index e8a525533..7b47f71ef 100644 --- a/packages/core/slot/package.json +++ b/packages/core/slot/package.json @@ -1,7 +1,7 @@ { "name": "@oku-ui/slot", "type": "module", - "version": "0.4.0", + "version": "0.5.0", "license": "MIT", "source": "src/index.ts", "funding": "https://github.com/sponsors/productdevbook", diff --git a/packages/core/use-composable/package.json b/packages/core/use-composable/package.json index c2a2f533a..0439613a5 100644 --- a/packages/core/use-composable/package.json +++ b/packages/core/use-composable/package.json @@ -1,7 +1,7 @@ { "name": "@oku-ui/use-composable", "type": "module", - "version": "0.4.0", + "version": "0.5.0", "license": "MIT", "source": "src/index.ts", "funding": "https://github.com/sponsors/productdevbook", diff --git a/packages/core/utils/package.json b/packages/core/utils/package.json index 657337b37..ea4cfc9ec 100644 --- a/packages/core/utils/package.json +++ b/packages/core/utils/package.json @@ -1,7 +1,7 @@ { "name": "@oku-ui/utils", "type": "module", - "version": "0.4.0", + "version": "0.5.0", "license": "MIT", "source": "src/index.ts", "funding": "https://github.com/sponsors/productdevbook", diff --git a/packages/core/visually-hidden/package.json b/packages/core/visually-hidden/package.json index 996b02661..6013f92e5 100644 --- a/packages/core/visually-hidden/package.json +++ b/packages/core/visually-hidden/package.json @@ -1,7 +1,7 @@ { "name": "@oku-ui/visually-hidden", "type": "module", - "version": "0.4.0", + "version": "0.5.0", "license": "MIT", "source": "src/index.ts", "funding": "https://github.com/sponsors/productdevbook", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 53889a4ea..74851dfc2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -50,6 +50,9 @@ importers: .: devDependencies: + '@clack/prompts': + specifier: ^0.7.0 + version: 0.7.0 '@egoist/tailwindcss-icons': specifier: ^1.1.0 version: 1.1.0(tailwindcss@3.3.3) @@ -575,6 +578,9 @@ importers: packages/components/primitives: dependencies: + '@oku-ui/alert-dialog': + specifier: workspace:^ + version: link:../alert-dialog '@oku-ui/aspect-ratio': specifier: workspace:^ version: link:../aspect-ratio @@ -2965,6 +2971,23 @@ packages: resolution: {integrity: sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==} dev: true + /@clack/core@0.3.3: + resolution: {integrity: sha512-5ZGyb75BUBjlll6eOa1m/IZBxwk91dooBWhPSL67sWcLS0zt9SnswRL0l26TVdBhb0wnWORRxUn//uH6n4z7+A==} + dependencies: + picocolors: 1.0.0 + sisteransi: 1.0.5 + dev: true + + /@clack/prompts@0.7.0: + resolution: {integrity: sha512-0MhX9/B4iL6Re04jPrttDm+BsP8y6mS7byuv0BvXgdXhbV5PdlsHt55dvNsuBCPZ7xq1oTAOOuotR9NFbQyMSA==} + dependencies: + '@clack/core': 0.3.3 + picocolors: 1.0.0 + sisteransi: 1.0.5 + dev: true + bundledDependencies: + - is-unicode-supported + /@cloudflare/kv-asset-handler@0.3.0: resolution: {integrity: sha512-9CB/MKf/wdvbfkUdfrj+OkEwZ5b7rws0eogJ4293h+7b6KX5toPwym+VQKmILafNB9YiehqY0DlNrDcDhdWHSQ==} dependencies: @@ -16227,7 +16250,7 @@ packages: vue-router: optional: true dependencies: - '@babel/types': 7.22.17 + '@babel/types': 7.23.0 '@rollup/pluginutils': 5.0.4(rollup@3.29.0) '@vue-macros/common': 1.8.0(rollup@3.29.0)(vue@3.3.4) ast-walker-scope: 0.4.2 diff --git a/scripts/README.md b/scripts/README.md deleted file mode 100644 index 93b26bc04..000000000 --- a/scripts/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# update version components -pnpm update:version c update 0.4.1-alpha.0 - -# publish components -pnpm update:version c publish - -# update version packages -pnpm update:version p update 0.4.0-alpha.0 - - -# publish packages -pnpm update:version p publish - diff --git a/scripts/_utils.ts b/scripts/_utils.ts deleted file mode 100644 index e3338c194..000000000 --- a/scripts/_utils.ts +++ /dev/null @@ -1,105 +0,0 @@ -import { promises as fsp } from 'node:fs' -import process from 'node:process' -import { resolve } from 'pathe' -import { execaSync } from 'execa' -import { - determineSemverChange, - getGitDiff, - loadChangelogConfig, - parseCommits, -} from 'changelogen' - -export interface Dep { - name: string - range: string - type: string -} - -type ThenArg = T extends PromiseLike ? U : T -export type Package = ThenArg> - -export async function loadPackage(dir: string) { - const pkgPath = resolve(dir, 'package.json') - const data = JSON.parse( - await fsp.readFile(pkgPath, 'utf-8').catch(() => '{}'), - ) - const save = () => - fsp.writeFile(pkgPath, `${JSON.stringify(data, null, 2)}\n`) - - const updateDeps = (reviver: (dep: Dep) => Dep | void) => { - for (const type of [ - 'dependencies', - 'devDependencies', - 'optionalDependencies', - 'peerDependencies', - ]) { - if (!data[type]) - continue - for (const e of Object.entries(data[type])) { - const dep: Dep = { name: e[0], range: e[1] as string, type } - delete data[type][dep.name] - const updated = reviver(dep) || dep - data[updated.type] = data[updated.type] || {} - data[updated.type][updated.name] = updated.range - } - } - } - - return { - dir, - data, - save, - updateDeps, - } -} - -export async function loadWorkspace(dir: string) { - const workspacePkg = await loadPackage(dir) - - const rename = (from: string, to: string) => { - workspacePkg.data._name = workspacePkg.data.name - workspacePkg.data.name = to - workspacePkg.updateDeps((dep) => { - if (dep.name === from && !dep.range.startsWith('npm:')) - dep.range = `npm:${to}@${dep.range}` - }) - } - - const setVersion = ( - newVersion: string, - // eslint-disable-next-line unused-imports/no-unused-vars - opts: { updateDeps?: boolean } = {}, - ) => { - workspacePkg.data.version = newVersion - } - - const save = () => workspacePkg.save() - - return { - dir, - workspacePkg, - save, - rename, - setVersion, - } -} - -export async function determineBumpType() { - const config = await loadChangelogConfig(process.cwd()) - const commits = await getLatestCommits() - - const bumpType = determineSemverChange(commits, config) - - return bumpType === 'major' ? 'minor' : bumpType -} - -export async function getLatestCommits() { - const config = await loadChangelogConfig(process.cwd()) - const latestTag = execaSync('git', [ - 'describe', - '--tags', - '--abbrev=0', - ]).stdout - - return parseCommits(await getGitDiff(latestTag), config) -} diff --git a/scripts/commands/publish.ts b/scripts/commands/publish.ts new file mode 100644 index 000000000..7396d1f85 --- /dev/null +++ b/scripts/commands/publish.ts @@ -0,0 +1,266 @@ +import { setTimeout } from 'node:timers/promises' +import { readFileSync, writeFileSync } from 'node:fs' +import { resolve } from 'node:path' +import { execSync } from 'node:child_process' +import { exit } from 'node:process' +import { defineCommand } from 'citty' +import type { MultiSelectOptions } from '@clack/prompts' +import { intro, isCancel, multiselect, outro, select } from '@clack/prompts' +import color from 'picocolors' +import { globbySync } from 'globby' + +export default defineCommand({ + meta: { + name: 'publish', + description: 'Oku Primitives CLI Publish', + version: '0.0.1', + }, + async run() { + const corePath = 'packages/core' + const componentsPath = 'packages/components' + const corePackages = globbySync(`${corePath}/*`, { onlyDirectories: true, cwd: process.cwd() }) + const components = globbySync(`${componentsPath}/*`, { onlyDirectories: true, cwd: process.cwd() }) + + console.clear() + + await setTimeout(1000) + + intro(`${color.bgCyan(color.black(' create-app '))}`) + + const type = await select({ + message: 'Pick a folder', + initialValue: 'ts', + maxItems: 5, + options: [ + { value: 'component', name: 'Components Package' }, + { value: 'core', name: 'Core Package' }, + ], + }) + + if (isCancel(type)) { + outro('Commit cancelled') + return + } + + let _packages: string[] = [] + let _tags: 'alpha' | 'beta' | 'rc' | 'latest' = 'latest' + + if (type === 'component') { + const { selectPackages, selectedTags } = await commandsPackages(components) + console.log(selectPackages) + _packages = selectPackages + _tags = selectedTags + } + + if (type === 'core') { + const { selectPackages, selectedTags } = await commandsPackages(corePackages) + console.log(selectPackages) + _packages = selectPackages + _tags = selectedTags + } + const wherePublish = await select({ + message: 'Publish package?', + initialValue: 'ts', + maxItems: 5, + options: [ + { value: 'no', name: 'No' }, + { value: 'npm', name: 'NPM' }, + ], + }) + + if (isCancel(wherePublish)) { + outro('Commit cancelled') + return + } + + if (wherePublish === 'npm') { + for await (const component of _packages) { + const file = readFileSync(resolve(`${component}/package.json`), 'utf8') + const packageJson = JSON.parse(file) + const pkversion = packageJson.version + const isAlphaBetaRc = pkversion.includes('alpha') || pkversion.includes('beta') || pkversion.includes('rc') + if (isAlphaBetaRc) { + if (_tags === 'alpha') { + execSync(`cd ${component} && pnpm build && pnpm publish --access public --no-git-checks --tag alpha`, { + stdio: 'inherit', + }) + } + + if (_tags === 'beta') { + execSync(`cd ${component} && pnpm build && pnpm publish --access public --no-git-checks --tag beta`, { + stdio: 'inherit', + }) + } + + if (_tags === 'rc') { + execSync(`cd ${component} && pnpm build && pnpm publish --access public --no-git-checks --tag rc`, { + stdio: 'inherit', + }) + } + } + + if (_tags === 'latest') { + execSync(`cd ${component} && pnpm build && pnpm publish --access public --no-git-checks`, { + stdio: 'inherit', + }) + } + + outro(`🎉 ${color.bgCyan(color.black(' Publish '))} 🎉`) + } + } + }, +}) + +async function commandsPackages(npmPackages: string[]): Promise<{ + selectPackages: string[] + selectedTags: 'alpha' | 'beta' | 'rc' | 'latest' +}> { + const selectPackages: string[] = [] + + const which = await select({ + message: 'Pick a', + initialValue: 'ts', + maxItems: 5, + options: [ + { value: 'all', name: 'All Components' }, + { value: 'single', name: 'Select Component' }, + ], + }) + + if (isCancel(which)) { + outro('Commit cancelled') + exit(0) + } + + if (which === 'all') + selectPackages.push(...npmPackages) + + if (which === 'single') { + const options = npmPackages.map((component) => { + const name = component.split('/')[2] + return { value: component, label: name } + }) as MultiSelectOptions['options'] + + const seletedComponent = await multiselect({ + message: 'Pick selects components', + options, + }) as string[] + + if (isCancel(seletedComponent)) + outro('Commit cancelled') + + selectPackages.push(...seletedComponent) + } + + const version = await select({ + message: 'Pick a version', + initialValue: 'ts', + maxItems: 5, + options: [ + { value: 'patch', label: 'Patch - v0.0.1' }, + { value: 'minor', label: 'Minor - v0.1.0' }, + { value: 'major', label: 'Major - v1.0.0' }, + { value: 'latest', label: 'v0.1.0-alpha.0 -> v0.1.0' }, + ], + }) + + if (isCancel(version)) { + outro('Commit cancelled') + exit(0) + } + + let selectedTags: 'alpha' | 'beta' | 'rc' | 'latest' = 'latest' + + if (version !== 'patch' && version !== 'latest') { + const selectTags = await select({ + message: 'Add tags?', + initialValue: 'ts', + maxItems: 5, + options: [ + { value: 'no', label: 'No' }, + { value: 'alpha', label: 'Alpha' }, + { value: 'beta', label: 'Beta' }, + { value: 'rc', label: 'RC' }, + { value: 'latest', label: 'Latest' }, + ], + }) + + if (isCancel(selectedTags)) { + outro('Commit cancelled') + exit(0) + } + + selectedTags = selectTags as 'alpha' | 'beta' | 'rc' | 'latest' + } + + for await (const component of selectPackages) { + const file = readFileSync(resolve(`${component}/package.json`), 'utf8') + + const packageJson = JSON.parse(file) + const pkversion = packageJson.version + + const regex = /(\d+\.\d+\.\d+)(?:-.+)?/ + const result = pkversion.match(regex) as RegExpMatchArray + + if (version === 'patch') { + // 1.7.3-alpha.0 -> 1.7.3-alpha.1 or 1.7.3 -> 1.7.4 + packageJson.version = packageJson.version.replace(/(\d+\.\d+\.\d+)(?:-([a-zA-Z]+\.\d+))?/, (match: any, versionPart: any, alphaPart: any) => { + if (alphaPart) { + const alphaNumber = Number.parseInt(alphaPart.split('.')[1]) + return `${versionPart}-${alphaPart.split('.')[0]}.${alphaNumber + 1}` + } + else { + const versionNumbers = versionPart.split('.').map(Number) + versionNumbers[2] += 1 + if (versionNumbers[2] === 10) { + versionNumbers[1] += 1 + versionNumbers[2] = 0 + } + return versionNumbers.join('.') + } + }) + } + if (version === 'minor') { + // 1.7.3-alpha.0 -> 1.8.0 + packageJson.version = result[1].replace(regex, (match, p1) => { + const [major, minor, _patch] = p1.split('.').map(Number) + return `${major}.${minor + 1}.0` + }) + } + if (version === 'major') { + // 1.7.3-alpha.0 -> 2.0.0 + packageJson.version = result[1].replace(regex, (match, p1) => { + const [major, _minor, _patch] = p1.split('.').map(Number) + return `${major + 1}.${0}.0` + }) + } + + selectedTags === 'alpha' && (packageJson.version += '-alpha.0') + selectedTags === 'beta' && (packageJson.version += '-beta.0') + selectedTags === 'rc' && (packageJson.version += '-rc.0') + + if (selectedTags === 'latest' || version === 'latest') { + const regex = /(\d+\.\d+\.\d+)(?:-.+)?/ + const result = packageJson.version.match(regex) as RegExpMatchArray + packageJson.version = result[1] + } + + const newPackage = JSON.stringify(packageJson, null, 2) + writeFileSync(`${component}/package.json`, newPackage) + } + + for await (const component of selectPackages) { + const file = readFileSync(resolve(`${component}/package.json`), 'utf8') + + // diff version + const newVersion = JSON.parse(file).version + const oldPackageJson = execSync(`git show HEAD:${component}/package.json 2>/dev/null`).toString() + const oldVersion = JSON.parse(oldPackageJson).version + console.log(`old version: ${oldVersion} -> new version: ${newVersion}`) + } + + return { + selectPackages, + selectedTags, + } +} diff --git a/scripts/index.ts b/scripts/index.ts new file mode 100644 index 000000000..5237871df --- /dev/null +++ b/scripts/index.ts @@ -0,0 +1,16 @@ +#!/usr/bin/env node + +import { defineCommand, runMain } from 'citty' + +const main = defineCommand({ + meta: { + name: 'pritimives', + version: '0.0.0', + description: 'Oku Primitives', + }, + subCommands: { + publish: () => import('./commands/publish').then(m => m.default), + }, +}) + +runMain(main) diff --git a/scripts/publish.sh b/scripts/publish.sh deleted file mode 100644 index 03c0854ac..000000000 --- a/scripts/publish.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash -componentName=$1 - -# no empty component name -if [ -z "$componentName" ] -then - echo "Component name is required" - exit 1 -fi - -# check if component exists -if [ ! -d "packages/components/$componentName" ] -then - echo "Component does not exist" - exit 1 -fi - -# cd to the component directory -cd packages/components/$componentName -pnpm build - -# publish -pnpm publish --access public --no-git-checks \ No newline at end of file diff --git a/scripts/update-changelog.ts b/scripts/update-changelog.ts deleted file mode 100644 index 63c5473ab..000000000 --- a/scripts/update-changelog.ts +++ /dev/null @@ -1,76 +0,0 @@ -import { execSync } from 'node:child_process' -import process from 'node:process' -import { $fetch } from 'ofetch' -import { inc } from 'semver' -import { generateMarkDown, loadChangelogConfig } from 'changelogen' -import { determineBumpType, getLatestCommits, loadWorkspace } from './_utils' - -async function main() { - const workspace = await loadWorkspace(process.cwd()) - const config = await loadChangelogConfig(process.cwd()) - - const commits = await getLatestCommits().then(commits => commits.filter( - c => config.types[c.type] && !(c.type === 'chore' && c.scope === 'deps' && !c.isBreaking), - )) - const bumpType = await determineBumpType() - - const newVersion = inc(workspace.workspacePkg.data.version, bumpType || 'patch') - const changelog = await generateMarkDown(commits, config) - - // Create and push a branch with bumped versions if it has not already been created - const branchExists = execSync(`git ls-remote --heads origin v${newVersion}`).toString().trim().length > 0 - if (!branchExists) { - execSync('git config --global user.email "hi@productdevbook.com"') - execSync('git config --global user.name "productdevbook"') - execSync(`git checkout -b v${newVersion}`) - - workspace.setVersion(newVersion!) - - await workspace.save() - - execSync(`git commit -am v${newVersion}`) - execSync(`git push -u origin v${newVersion}`) - } - - // Get the current PR for this release, if it exists - const [currentPR] = await $fetch(`https://api.github.com/repos/oku-ui/primitives/pulls?head=oku-ui:v${newVersion}`) - - const releaseNotes = [ - currentPR?.body.replace(/## 👉 Changelog[\s\S]*$/, '') || `> ${newVersion} is the next ${bumpType} release.\n>\n> **Timetable**: to be announced.`, - '## 👉 Changelog', - changelog.replace(/^## v.*?\n/, '').replace('...main', `...v${newVersion}`), - ].join('\n') - - // Create a PR with release notes if none exists - if (!currentPR) { - return await $fetch('https://api.github.com/repos/oku-ui/primitives/pulls', { - method: 'POST', - headers: { - Authorization: `token ${process.env.GITHUB_TOKEN}`, - }, - body: { - title: `v${newVersion}`, - head: `v${newVersion}`, - base: 'main', - body: releaseNotes, - draft: true, - }, - }) - } - - // Update release notes if the pull request does exist - await $fetch(`https://api.github.com/repos/oku-ui/primitives/pulls/${currentPR.number}`, { - method: 'PATCH', - headers: { - Authorization: `token ${process.env.GITHUB_TOKEN}`, - }, - body: { - body: releaseNotes, - }, - }) -} - -main().catch((err) => { - console.error(err) - process.exit(1) -}) diff --git a/scripts/update-version.ts b/scripts/update-version.ts deleted file mode 100644 index 5c55dc25d..000000000 --- a/scripts/update-version.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { readFileSync, writeFileSync } from 'node:fs' -import { execSync } from 'node:child_process' -import process from 'node:process' -import { globbySync } from 'globby' - -// package for reading and writing files - -const corePath = 'packages/core' -const componentsPath = 'packages/components' - -const packages = globbySync(`${corePath}/*`, { onlyDirectories: true }) - -const components = globbySync(`${componentsPath}/*`, { onlyDirectories: true }) - -const selectType = process.argv[2] === 'c' ? components : packages - -function updateVersion() { - selectType.forEach((component) => { - // readFile package.json - const file = readFileSync(`${component}/package.json`, 'utf8') - - if (!file) - return - - // parse package.json - const packageJson = JSON.parse(file) - // get args from process.argv - packageJson.version = process.argv[4] - // stringify package.json - const newPackage = JSON.stringify(packageJson, null, 2) - // writeFile package.json - writeFileSync(`${component}/package.json`, newPackage) - }) -} -function publishVersion() { - selectType.forEach((component) => { - try { - const goBuild = execSync(`cd ${component} && pnpm build`, { encoding: 'utf-8', stdio: 'inherit' }) - console.log(goBuild) - const goSync = execSync(`cd ${component} && pnpm publish --access public --no-git-checks`, { encoding: 'utf-8', stdio: 'inherit' }) - console.log(goSync) - } - catch (error) { - console.log(error) - } - }) -} - -const selectMerge = process.argv[3] - -switch (selectMerge) { - case 'update': - updateVersion() - break - case 'publish': - publishVersion() - break - default: - break -}