Skip to content

Commit

Permalink
fix: pk add 完成
Browse files Browse the repository at this point in the history
  • Loading branch information
罗学 committed Apr 19, 2021
1 parent 45f6cdc commit ee2ce9c
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 112 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist
node_modules
**/*.d.ts
packages
34 changes: 18 additions & 16 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
name: Node CI

on: [push]
# on: [push]
on:
push:
branches:
- master

jobs:
build:
build-and-deploy:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [10.x, 11.x, 12.x]

steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
- name: Checkout
uses: actions/checkout@v2 # If you're using actions/checkout@v2 you must set persist-credentials to false in most cases for the deployment to work correctly.
with:
node-version: ${{ matrix.node-version }}
- name: npm install, build, and test
persist-credentials: false
- name: Install and Build
run: |
npm ci
npm run build --if-present
env:
CI: true
npm install
npm run build
- name: Deploy
uses: JamesIves/github-pages-deploy-action@releases/v3
with:
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
BRANCH: master
FOLDER: dist
58 changes: 11 additions & 47 deletions packages/cli/lib/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,70 +3,34 @@
* @use
* pk add <paluginName>
*/

const oriRequie = require

// eslint-disable-next-line
require = (path) => {
if (/^[@pkb]/.test(path)) {
const name = path.replace('@pkb/', '')
try {
return oriRequie(`../../${name}`)
} catch (error) {
oriRequie(path)
}
}

return oriRequie(path)
}

// -------------以上为本地调试,修改了 require-------------------
const {
chalk,
semver,
resolveModule
} = require('@pkb/shared-utils')
const {
resolvePluginId,
log,
error,
resolvePluginId,
isOfficialPlugin
} = require('@pkb/shared-utils')
const invoke = require('./invoke')
const PackageManager = require('./util/ProjectPackageManager')
const confirmIfGitDirty = require('./util/confirmIfGitDirty')

async function add(pluginName, options = {}, context = process.cwd()) {
if (!(await confirmIfGitDirty(context))) {
return
}
const PackageManager = require('../util/ProjectPackageManager')

async function add(pluginName) {
const packageName = resolvePluginId(pluginName)

console.log(packageName)
if (!packageName) {
console.log(chalk.red(`${pluginName} 不是插件`))
process.exit(0)
}

log()
log(`📦 正在安装 ${chalk.cyan(packageName)}...`)
log(`📦 正在安装 ${chalk.cyan(packageName)} ...`)
log()

const pm = new PackageManager({ context })
const pm = new PackageManager({ context: process.cwd() })

const cliVersion = require('@pkb/shared-utils/package.json').version
if (isOfficialPlugin(packageName) && semver.prerelease(cliVersion)) {
await pm.add(`${packageName}@^${cliVersion}`)
} else {
await pm.add(packageName)
}
pm.add(packageName)

log(`${chalk.green('✔')} 插件安装成功: ${chalk.cyan(packageName)}`)
log()

const generatorPath = resolveModule(`${packageName}/generator`, context)
if (generatorPath) {
invoke(pluginName, options, context)
} else {
log(`插件 ${packageName} 没有 generator`)
}
// todo 后面可以添加一些钩子
}

module.exports = (...args) => add(...args).catch((err) => {
Expand Down
20 changes: 1 addition & 19 deletions packages/shared-utils/lib/pluginResolution.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,7 @@ exports.resolvePluginId = (id) => {
if (pkbOfficialPlugins.includes(id)) {
return `@pkb/plugin-${id}`
}

if (id.charAt(0) === '@') {
const scopeMatch = id.match(scopeRE)
if (scopeMatch) {
const scope = scopeMatch[0]
const shortId = id.replace(scopeRE, '')
let ii = ''
if (/^(@pkb)/.test(id)) {
ii = `${scope}${
(scope === '@pkb/' ? '' : 'pk-')
}cli-plugin-${shortId}`
} else {
ii = id
}
return ii
}
}

return `pk-cli-plugin-${id}`
return null
}

exports.matchesPluginId = (input, full) => {
Expand Down
22 changes: 0 additions & 22 deletions packages/vite-box/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,6 @@ function App() {
count is: {count}
</button>
</p>
<p>
Edit <code>App.tsx</code> and save to test HMR updates.
</p>
<p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
{' | '}
<a
className="App-link"
href="https://vitejs.dev/guide/features.html"
target="_blank"
rel="noopener noreferrer"
>
Vite Docs5
</a>
</p>
</header>
</div>
)
Expand Down
9 changes: 1 addition & 8 deletions webpack-box.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,12 @@ module.exports = function (config) {
filenameHashing: true,
eslint: {
lintOnSave: true, // 开启运行时检测
extensions: ['js', 'jsx', 'vue'] // 默认 ['js', 'jsx']
},
tslint: {
lintOnSave: true, // 开启运行时检测
useThreads: true
extensions: ['js', 'jsx', 'vue', 'ts', 'tsx'] // 默认 ['js', 'jsx']
},
stylelint: {
lintOnSave: true // 开启运行时检测
// extensions: ['vue', 'htm', 'html', 'css', 'sss', 'less', 'scss']
},
// dll: {
// venders: ['react']
// },
chainWebpack(config) {}
}
}

0 comments on commit ee2ce9c

Please sign in to comment.