Skip to content

Commit

Permalink
chore: smart build and smart dev (#270)
Browse files Browse the repository at this point in the history
* chore: add dev or build smart

* fix: lint issues

* fix: lint
  • Loading branch information
productdevbook committed Aug 5, 2023
1 parent 239d6be commit a1a02d9
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/actions/cache-build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 19 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/**'",
Expand Down
22 changes: 22 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -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
39 changes: 39 additions & 0 deletions scripts/build.ts
Original file line number Diff line number Diff line change
@@ -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' })
22 changes: 22 additions & 0 deletions scripts/dev.sh
Original file line number Diff line number Diff line change
@@ -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
39 changes: 39 additions & 0 deletions scripts/dev.ts
Original file line number Diff line number Diff line change
@@ -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' })
5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"target": "esnext",
"useDefineForClassFields": true,
"module": "esnext",
"moduleResolution": "node",
"moduleResolution": "Node",
"isolatedModules": true,
"strict": true,
"jsx": "preserve",
Expand Down Expand Up @@ -35,7 +35,8 @@
"include": [
"packages/**/*",
"vitest-setup.ts",
"vitest.config.ts"
"vitest.config.ts",
"scripts/**/*"
],
"exclude": [
"**/*/*.stories.ts",
Expand Down

0 comments on commit a1a02d9

Please sign in to comment.