Skip to content

Commit

Permalink
chore: migrate cli to typescript (DimensionDev#2612)
Browse files Browse the repository at this point in the history
* chore: rename cli-dev-build to cli

* chore: migrate to typescript

* chore: move locale-kit to cli

* fix: path error

* chore: split ci task

* chore: simplify code

* fix: netlify build failed

* chore: simplify logic

* fix: review issue

* chore: spawnSync switch to spawn
  • Loading branch information
septs committed Mar 16, 2021
1 parent 787cfc7 commit 9d690ec
Show file tree
Hide file tree
Showing 35 changed files with 366 additions and 219 deletions.
13 changes: 10 additions & 3 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,26 @@ jobs:
key: ${{ runner.os }}-node-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-node-
- run: sudo npm i -g pnpm
- run: sudo npm install --global pnpm
- run: pnpm ci
- run: npx prettier --list-different .
- run: npx build -- echo "Check tsc"
- run: npx locale-kit
- run: npm run lint:typecoverage
working-directory: packages/maskbook
- run: npx locale-kit
- run: npm run lint:report
- name: Upload ESLint Report
uses: actions/upload-artifact@v2
with:
name: eslint
path: ./reports/junit
prettier:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions/setup-node@v2-beta
- run: npx prettier --list-different .
storybook:
runs-on: ubuntu-20.04
continue-on-error: false
Expand Down
2 changes: 1 addition & 1 deletion .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
_
_
2 changes: 1 addition & 1 deletion netlify.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build]
command = "npm run netlify-install && cd packages/cli-dev-build && npx gulp buildNetlify"
command = "./scripts/netlify.sh"
publish = "packages/netlify"
ignore = "git diff --quiet HEAD^ HEAD packages/dashboard packages/storybook-shared packages/theme packages/netlify packages/shared packages/icons"
[build.environment]
Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
"test:ci": "jest --verbose --ci --collectCoverage=true --reporters=default --reporters=jest-junit -w 1 --forceExit",
"test:e2e": "jest --verbose --runInBand --config=jest-e2e.config.js",
"preinstall": "npx only-allow pnpm",
"ci": "pnpm install --frozen-lockfile --store-dir ~/.pnpm/",
"netlify-install": "test \"$CI\" = true && npx pnpm install -r --store=node_modules/.pnpm-store || echo skiping pnpm install"
"ci": "pnpm install --frozen-lockfile --store-dir ~/.pnpm/"
},
"lint-staged": {
"*": "prettier --write --ignore-unknown",
Expand All @@ -47,8 +46,7 @@
"devDependencies": {
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"@dimensiondev/locale-kit": "workspace:*",
"@dimensiondev/maskbook-cli-dev-or-build": "workspace:*",
"@dimensiondev/cli": "workspace:*",
"@magic-works/commonjs-import.meta": "^1.0.0",
"@magic-works/i18n-codegen": "^0.0.5",
"@material-ui/codemod": "^5.0.0-alpha.24",
Expand Down
2 changes: 1 addition & 1 deletion packages/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

## Tools

- [cli-dev-build](cli-dev-build)
- [cli](cli)

Because our project is using TypeScript project reference and code generation, to make the build process work normally, those process must run before any other commands.

Expand Down
14 changes: 0 additions & 14 deletions packages/cli-dev-build/build.js

This file was deleted.

17 changes: 0 additions & 17 deletions packages/cli-dev-build/dev.js

This file was deleted.

2 changes: 0 additions & 2 deletions packages/cli-dev-build/gulpfile.js

This file was deleted.

45 changes: 0 additions & 45 deletions packages/cli-dev-build/netlify.js

This file was deleted.

17 changes: 0 additions & 17 deletions packages/cli-dev-build/package.json

This file was deleted.

25 changes: 0 additions & 25 deletions packages/cli-dev-build/process-lock.js

This file was deleted.

30 changes: 0 additions & 30 deletions packages/cli-dev-build/ts.js

This file was deleted.

15 changes: 0 additions & 15 deletions packages/cli-dev-build/utils.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/cli/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!/build
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# cli-dev-build
# cli

This package provides two commands: `build` and `dev`.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env ts-node
import git from '@nice-labs/git-rev'
import { BUILD_PATH, run } from './utils'
import { BUILD_PATH, run } from '../utils'

const branch = git.branchName()
const types = {
Expand Down
21 changes: 21 additions & 0 deletions packages/cli/build/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env ts-node
import { spawn } from 'child_process'
import { ROOT_PATH } from '../utils'
import onMain from './main'
import { build } from './typescript'

async function main() {
await build()
if (process.argv[2] === '--') {
return spawn(process.argv[3], process.argv.slice(4), {
stdio: 'inherit',
shell: true,
cwd: ROOT_PATH,
})
}
return onMain('build')
}

main().then(({ exitCode }) => {
process.exit(exitCode)
})
22 changes: 22 additions & 0 deletions packages/cli/build/dev.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env ts-node
import { spawn } from 'child_process'
import { ROOT_PATH } from '../utils'
import onMain from './main'
import { build, dev } from './typescript'

async function main() {
await build()
dev()
if (process.argv[2] === '--') {
return spawn(process.argv[3], process.argv.slice(4), {
stdio: 'inherit',
shell: true,
cwd: ROOT_PATH,
})
}
return onMain('dev')
}

main().then(({ exitCode }) => {
process.exit(exitCode)
})
2 changes: 2 additions & 0 deletions packages/cli/build/gulpfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './netlify'
export * from './typescript'
22 changes: 14 additions & 8 deletions packages/cli-dev-build/main.js → packages/cli/build/main.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const { spawn } = require('child_process')
const { resolve } = require('path')
import { spawn } from 'child_process'
import { resolve } from 'path'
import { PKG_PATH } from '../utils'

const presets = ['chromium', 'E2E', 'firefox', 'android', 'iOS', 'base']
const otherFlags = ['beta', 'insider', 'reproducible', 'profile', 'manifest-v3']
const knownTargets = ['-h', '--help', ...presets, ...otherFlags]
/** @param {'dev' | 'build'} mode */
async function main(mode) {

export default async function main(mode: 'dev' | 'build') {
let args = process.argv.slice(2)

if (args.includes('-h') || args.includes('--help')) {
Expand All @@ -22,10 +23,12 @@ async function main(mode) {
choices: otherFlags,
})
args = [...flags, preset]

const command = ['npx', mode === 'dev' ? 'dev' : 'build', ...args]
const { confirm } = await inquirer.prompt({
type: 'confirm',
name: 'confirm',
message: `Command is: "npx ${mode === 'dev' ? 'dev' : 'build'} ${args.join(' ')}". Is that OK?`,
message: `Command is: "${command.join(' ')}". Is that OK?`,
})
if (!confirm) return
}
Expand All @@ -35,9 +38,12 @@ async function main(mode) {
args.filter((x) => !x.startsWith('-')).forEach((target) => {
command.push('--env', target)
if (!knownTargets.includes(target)) {
throw new TypeError('Unknown target ' + target + '. Known targets: ' + knownTargets.join(','))
throw new TypeError(`Unknown target ${target}. Known targets: ${knownTargets}`)
}
})
spawn('npx', ['webpack', ...command], { stdio: 'inherit', shell: true, cwd: resolve(__dirname, '../maskbook/') })
return spawn('npx', ['webpack', ...command], {
stdio: 'inherit',
shell: true,
cwd: resolve(PKG_PATH, 'maskbook'),
})
}
module.exports = main
Loading

0 comments on commit 9d690ec

Please sign in to comment.