Skip to content

Commit

Permalink
feat: add resume cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunqing committed May 11, 2022
1 parent c4c26dc commit c81113d
Show file tree
Hide file tree
Showing 14 changed files with 659 additions and 738 deletions.
7 changes: 7 additions & 0 deletions examples/resume-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# TEST

- 123
- 456
>
- 678
- 8910
18 changes: 18 additions & 0 deletions examples/resume-example/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link
rel="icon"
type="image/svg+xml"
href="/src/favicon.svg"
/>
<meta
name="viewport"
content="width=device-width, initial-scale=1.0"
/>
</head>
<body>
<div id="root"></div>
</body>
</html>
12 changes: 12 additions & 0 deletions examples/resume-example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "resume-example",
"private": true,
"dependencies": {
"@resumejs/core": "workspace:*",
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
"scripts": {
"dev": "resume"
}
}
4 changes: 1 addition & 3 deletions packages/core/build.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ export default defineBuildConfig({
entries: ['src/index.ts'],
declaration: true,
clean: true,
rollup: {
emitCJS: true,
},
rollup: {},
})
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<div id="root"></div>
<script
type="module"
src="/src/main.tsx"
src="./public/src/main.tsx"
></script>
</body>
</html>
24 changes: 14 additions & 10 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
{
"name": "playground",
"name": "@resumejs/core",
"version": "0.0.0",
"private": true,
"scripts": {
"build": "unbuild",
"dev": "unbuild --stub"
},
"devDependencies": {
"@vitejs/plugin-react": "^1.0.7",
"vite": "^2.9.0",
"unbuild": "^0.7.4",
"@types/react": "^17.0.33",
"@types/react-dom": "^17.0.10",
"@unocss/preset-wind": "^0.33.2",
"unocss": "^0.33.2"
"bin": {
"resume": "./dist/index.ts.mjs"
},
"dependencies": {
"@resumejs/components": "workspace:*",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"@resumejs/components": "workspace:*"
"@types/minimist": "^1.2.2",
"@types/react": "^17.0.33",
"@types/react-dom": "^17.0.10",
"@unocss/preset-wind": "^0.33.2",
"@vitejs/plugin-react": "^1.0.7",
"kolorist": "^1.5.1",
"minimist": "^1.2.6",
"unbuild": "^0.7.4",
"unocss": "^0.33.2",
"vite": "^2.9.0"
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import ReactDOM from 'react-dom'
import Show from './Show'
import Show from 'F:\\dengqing\\resume\\packages\\core\\public\\Show.tsx'
import 'uno.css'
import '@resumejs/components/style'

Expand Down
62 changes: 45 additions & 17 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,53 @@
import path from 'path'
import { createServer } from 'vite'
import path, { isAbsolute } from 'path'
import type { InlineConfig } from 'vite'
import { build, createServer } from 'vite'
import react from '@vitejs/plugin-react'
import unocssVite from 'unocss/vite'
import presetWind from '@unocss/preset-wind'
import minimist from 'minimist'
import { loadResume } from './plugins/loadResume'
import { entry } from './plugins/entry'

const cwd = process.cwd()

createServer({
root: path.resolve(__dirname, '../public'),
logLevel: 'info',
// configFile: path.join(cwd, 'vite.config.js'),
plugins: [
unocssVite({
presets: [presetWind()],
}),
react(),
loadResume(cwd),
],
}).then((res) => {
res.listen(3001).then(() => {
res.printUrls()
interface ArgvOptions extends minimist.ParsedArgs {
template?: string
config?: string
}

const { _, config } = minimist(process.argv.slice(2), {
string: '-',
}) as ArgvOptions

const getViteConfig = () => {
const configFile = config
? isAbsolute(config)
? config
: path.join(cwd, config)
: undefined

const _config: InlineConfig = {
logLevel: 'info',
configFile,
plugins: [
entry(__dirname),
unocssVite({
presets: [presetWind()],
}),
react(),
loadResume(),
],
}

return _config
}

if (_.includes('build')) {
build(getViteConfig())
} else {
createServer(getViteConfig()).then((res) => {
res.listen(3000).then(() => {
res.printUrls()
})
})
})
}
24 changes: 24 additions & 0 deletions packages/core/src/plugins/entry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import path from 'path'
import type { Plugin } from 'vite'

export const entry = (cwd: string): Plugin => {
console.log(path.resolve(cwd, '../public/main.tsx'))
return {
name: 'resume:entry',
enforce: 'pre',
transformIndexHtml: {
enforce: 'pre',
transform() {
return [
{
tag: 'script',
attrs: {
type: 'module',
src: `/${path.resolve(cwd, '../public/main.tsx')}`,
},
},
]
},
},
}
}
19 changes: 13 additions & 6 deletions packages/core/src/plugins/loadResume.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
import path from 'path'
import type { Plugin } from 'vite'
import type { Plugin, ResolvedConfig } from 'vite'

export const loadResume = (cwd: string): Plugin => {
export const loadResume = (): Plugin => {
const virtualModuleId = 'virtual:resume'
let config: ResolvedConfig
return {
name: 'load-resume',

resolveId(id) {
configResolved(_config) {
config = _config
},
async resolveId(id) {
// const react = await this.resolve('react')
// console.log(
// '🚀 ~ file: loadResume.ts ~ line 14 ~ resolveId ~ react',
// react
// )
if (id === virtualModuleId) {
return `\0${id}`
}
},
load(id) {
if (id === `\0${virtualModuleId}`) {
const resumePath = path.resolve(cwd, 'RESUME.md')
const resumePath = path.resolve(config.root, 'README.md')
return `
export { default as default } from ${JSON.stringify(
`${resumePath}?raw`
)}
`
}

return null
},
}
Expand Down
3 changes: 2 additions & 1 deletion packages/core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
},
"include": [
"src",
"publick"
"client.d.ts",
"public"
]
}
Loading

0 comments on commit c81113d

Please sign in to comment.