diff --git a/.github/actions/cache-build/action.yml b/.github/actions/cache-build/action.yml index 3d2685dbb..4b5db2a87 100644 --- a/.github/actions/cache-build/action.yml +++ b/.github/actions/cache-build/action.yml @@ -24,6 +24,6 @@ runs: **/dist/** key: ${{ runner.os }}-${{ env.cache-name }}-${{ env.key-1 }}-${{ env.key-2 }}-${{ env.key-3 }}-${{ env.key-4 }} - - run: pnpm build + - run: pnpm build:all if: steps.cache-build.outputs.cache-hit != 'true' shell: bash diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bf4239b53..3911b9223 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -32,19 +32,34 @@ Note: What is Terminals Maganger and Commands -> https://github.com/oku-ui/prim 2. Install the project dependencies `pnpm install` 3. Build the project - `pnpm build` + `pnpm build:all` 4. If new package vue, go to `packages/example-package` example `packages/components` or `packages/core` copy. You can copy this file and build your new build on it. -5. Storybook works with the command `pnpm dev` +5. Storybook works with the command `pnpm dev:all` + +Note: If only working on the core package + +```sh +pnpm dev label # Run only label component (packages/components) check files name +pnpm dev core utils # Run only core and utils package (packages/core) check files name + +pnpm build label # Build only label component (packages/components) check files name +pnpm build core utils # Build only core and utils package (packages/core) check files name +``` ### Scripts ```shell -pnpm build # Build all packages +pnpm dev ${component-file-name} # Run a specific component +pnpm dev core ${core-file-name} # Run a specific core package + +pnpm build ${component-file-name} # Build a specific component +pnpm build core ${core-file-name} # Build a specific core package +pnpm build:all # Build all packages pnpm build:components # Build components package pnpm build:core # Build core package -pnpm dev # Run Storybook +pnpm storybook # Run Storybook pnpm build:storybook # Build Storybook pnpm dev:all # Run all packages diff --git a/package.json b/package.json index ee2fa4350..9acf62b7d 100644 --- a/package.json +++ b/package.json @@ -8,14 +8,16 @@ "node": ">=18" }, "scripts": { + "dev": "esno scripts/dev.ts", + "build": "esno scripts/build.ts", "p:build": "tsup", - "build": "turbo run build --filter='./packages/**'", + "build:all": "turbo run build --filter='./packages/**'", "build:components": "turbo run build --filter='./packages/components/**'", "build:core": "turbo run build --filter='./packages/core/**'", - "dev": "pnpm storybook dev -p 6006 --no-open", "dev:all": "turbo run dev --filter='./packages/**' --concurrency $(($(ls -1 packages/components packages/core | wc -l)+3))", "dev:core": "turbo run dev --filter='./packages/core/**'", "dev:components": "turbo run dev --filter='./packages/components/**' --concurrency $(($(ls -1 packages/components | wc -l)+3))", + "storybook": "pnpm storybook dev -p 6006 --no-open", "lint": "eslint . --cache ", "lint:fix": "eslint . --fix --cache", "play:vue": "pnpm clean:dts && turbo run dev --filter='./playground/vue3/**'", diff --git a/scripts/build.sh b/scripts/build.sh new file mode 100755 index 000000000..d79f34a6b --- /dev/null +++ b/scripts/build.sh @@ -0,0 +1,22 @@ +#!/bin/bash +componentName=$1 +turboDependenciesFilter=[] + +if [ ! -d "packages/components/$componentName" ] +then + echo "Component does not exist" + exit 1 +fi + +dependencies=$(cat packages/components/$componentName/package.json | jq -r '.dependencies | keys[] | select(. | startswith("@oku-ui"))') + +filter_arguments="" +for dependency in $dependencies +do + if [[ "$dependency" == @oku-ui* ]] + then + filter_arguments+="--filter=$dependency " + fi +done + +turbo build $filter_arguments \ No newline at end of file diff --git a/scripts/build.ts b/scripts/build.ts new file mode 100644 index 000000000..173ddbdee --- /dev/null +++ b/scripts/build.ts @@ -0,0 +1,39 @@ +import { readFileSync, readdirSync } from 'node:fs' +import { resolve } from 'node:path' +import process from 'node:process' +import { execaCommandSync } from 'execa' + +const isCore = process.argv[2].endsWith('core') +let where = 'packages' + +if (isCore) + where = where.concat('/core') +else + where = where.concat('/components') + +const componentName = isCore ? process.argv[3] : process.argv[2] + +let turboDependenciesFilter: string = '' + +async function main() { + const componentFile = resolve(process.cwd(), where, componentName) + + if (readdirSync(componentFile).length === 0) { + console.error(`${componentName} does not exist`) + process.exit(1) + } + + const dependencies = readFileSync(resolve(componentFile, 'package.json'), 'utf-8') + const packageName = JSON.parse(dependencies).name + const filteredDependencies = Object.entries(JSON.parse(dependencies).dependencies) + .filter(([name]) => name.startsWith('@oku-ui')) + .filter(([name]) => !turboDependenciesFilter.includes(name)) + .map(([name]) => name) + .map(name => `--filter=${name}`) + .join(' ') + + turboDependenciesFilter = filteredDependencies.concat(` --filter=${packageName}`) +} + +await main() +execaCommandSync(`turbo build ${turboDependenciesFilter}`, { stdio: 'inherit' }) diff --git a/scripts/dev.sh b/scripts/dev.sh new file mode 100755 index 000000000..eead3d7b0 --- /dev/null +++ b/scripts/dev.sh @@ -0,0 +1,22 @@ +#!/bin/bash +componentName=$1 +turboDependenciesFilter=[] + +if [ ! -d "packages/components/$componentName" ] +then + echo "Component does not exist" + exit 1 +fi + +dependencies=$(cat packages/components/$componentName/package.json | jq -r '.dependencies | keys[] | select(. | startswith("@oku-ui"))') + +filter_arguments="" +for dependency in $dependencies +do + if [[ "$dependency" == @oku-ui* ]] + then + filter_arguments+="--filter=$dependency " + fi +done + +turbo dev $filter_arguments \ No newline at end of file diff --git a/scripts/dev.ts b/scripts/dev.ts new file mode 100644 index 000000000..fe5803363 --- /dev/null +++ b/scripts/dev.ts @@ -0,0 +1,39 @@ +import { readFileSync, readdirSync } from 'node:fs' +import { resolve } from 'node:path' +import process from 'node:process' +import { execaCommandSync } from 'execa' + +const isCore = process.argv[2].endsWith('core') +let where = 'packages' + +if (isCore) + where = where.concat('/core') +else + where = where.concat('/components') + +const componentName = isCore ? process.argv[3] : process.argv[2] + +let turboDependenciesFilter: string = '' + +async function main() { + const componentFile = resolve(process.cwd(), where, componentName) + + if (readdirSync(componentFile).length === 0) { + console.error(`${componentName} does not exist`) + process.exit(1) + } + + const dependencies = readFileSync(resolve(componentFile, 'package.json'), 'utf-8') + const packageName = JSON.parse(dependencies).name + const filteredDependencies = Object.entries(JSON.parse(dependencies).dependencies) + .filter(([name]) => name.startsWith('@oku-ui')) + .filter(([name]) => !turboDependenciesFilter.includes(name)) + .map(([name]) => name) + .map(name => `--filter=${name}`) + .join(' ') + + turboDependenciesFilter = filteredDependencies.concat(` --filter=${packageName}`) +} + +await main() +execaCommandSync(`turbo dev ${turboDependenciesFilter}`, { stdio: 'inherit' }) diff --git a/tsconfig.json b/tsconfig.json index 936d6369b..4c73dcdd6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,7 +6,7 @@ "target": "esnext", "useDefineForClassFields": true, "module": "esnext", - "moduleResolution": "node", + "moduleResolution": "Node", "isolatedModules": true, "strict": true, "jsx": "preserve", @@ -35,7 +35,8 @@ "include": [ "packages/**/*", "vitest-setup.ts", - "vitest.config.ts" + "vitest.config.ts", + "scripts/**/*" ], "exclude": [ "**/*/*.stories.ts",