Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Nov 6, 2020
2 parents 8c0a197 + 287ca2f commit f4f019e
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 27 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/dist
/node_modules
/src/client/shared
/src/node/shared
*.log
.DS_Store
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@
},
"homepage": "https://github.com/vuejs/vitepress/tree/master/#readme",
"scripts": {
"dev": "run-p dev-client dev-client-copy dev-node dev-shared",
"dev": "yarn dev-shared && yarn dev-start",
"dev-start": "run-p dev-client dev-node dev-watch",
"dev-client": "tsc -w -p src/client",
"dev-client-copy": "node scripts/watchAndCopy",
"dev-node": "tsc -w -p src/node",
"dev-shared": "tsc -w -p src/shared",
"release": "bash scripts/release.sh",
"build": "rimraf -rf dist && tsc -p src/client && tsc -p src/node && tsc -p src/shared && node scripts/copy",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s"
"dev-shared": "node scripts/copyShared",
"dev-watch": "node scripts/watchAndCopy",
"build": "rimraf -rf dist && node scripts/copyShared && tsc -p src/client && tsc -p src/node && node scripts/copyClient",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
"release": "bash scripts/release.sh"
},
"engines": {
"node": ">=10.0.0"
Expand Down
File renamed without changes.
7 changes: 7 additions & 0 deletions scripts/copyShared.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const fs = require('fs-extra')
const glob = require('globby')

glob.sync('src/shared/**/*.ts').forEach((file) => {
fs.copy(file, file.replace(/^src\//, 'src/node/'))
fs.copy(file, file.replace(/^src\//, 'src/client/'))
})
28 changes: 23 additions & 5 deletions scripts/watchAndCopy.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
// copy and watch non-ts files in src/client
const fs = require('fs-extra')
const chokidar = require('chokidar')

function toDest(file) {
function toClientAndNode(method, file) {
if (method === 'copy') {
fs.copy(file, file.replace(/^src\//, 'src/node/'))
fs.copy(file, file.replace(/^src\//, 'src/client/'))
} else if (method === 'remove') {
fs.remove(file.replace(/^src\//, 'src/node/'))
fs.remove(file.replace(/^src\//, 'src/client/'))
}
}

function toDist(file) {
return file.replace(/^src\//, 'dist/')
}

// copy shared files to the client and node directory whenever they change.
chokidar
.watch('src/shared/**/*.ts')
.on('change', (file) => toClientAndNode('copy', file))
.on('add', (file) => toClientAndNode('copy', file))
.on('unlink', (file) => toClientAndNode('remove', file))

// copy non ts files, such as an html or css, to the dist directory whenever
// they change.
chokidar
.watch('src/client/**/!(*.ts|tsconfig.json)')
.on('change', (file) => fs.copy(file, toDest(file)))
.on('add', (file) => fs.copy(file, toDest(file)))
.on('unlink', (file) => fs.remove(toDest(file)))
.on('change', (file) => fs.copy(file, toDist(file)))
.on('add', (file) => fs.copy(file, toDist(file)))
.on('unlink', (file) => fs.remove(toDist(file)))
10 changes: 4 additions & 6 deletions src/client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,20 @@
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"baseUrl": ".",
"outDir": "../../dist",
"outDir": "../../dist/client",
"module": "esnext",
"lib": ["ESNext", "DOM"],
"types": ["vite"],
"paths": {
"/@app/*": ["app/*"],
"/@theme/*": ["theme-default/*"],
"/@shared/*": ["../shared/*"],
"/@shared/*": ["shared/*"],
"/@types/*": ["../../types/*"],
"vitepress": ["app/exports.ts"]
}
},
"include": [
".",
".",
"../../types/shared.d.ts",
],
"exclude": [
"../shared"
]
}
2 changes: 1 addition & 1 deletion src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import globby from 'globby'
import { createResolver, APP_PATH } from './resolver'
import { Resolver } from 'vite'
import { SiteData, HeadConfig, LocaleConfig } from '../../types/shared'
export { resolveSiteDataByRoute } from '../shared/config'
export { resolveSiteDataByRoute } from './shared/config'

const debug = require('debug')('vitepress:config')

Expand Down
13 changes: 10 additions & 3 deletions src/node/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "../../dist",
"baseUrl": ".",
"outDir": "../../dist/node",
"module": "commonjs",
"lib": ["ESNext", "DOM"],
"sourceMap": true
"sourceMap": true,
"paths": {
"/@types/*": ["../../types/*"]
}
},
"include": [".", "../shared", "../../types/shared.d.ts"]
"include": [
".",
"../../types/shared.d.ts"
]
}
2 changes: 1 addition & 1 deletion src/shared/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SiteData } from '../../types/shared'
import { SiteData } from '/@types/shared'

const inBrowser = typeof window !== 'undefined'

Expand Down
10 changes: 5 additions & 5 deletions src/shared/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"baseUrl": ".",
"outDir": "../../dist/client/shared",
"module": "esnext",
"lib": ["ESNext", "DOM"],
"paths": {
"/@types/*": ["../../types/*"]
}
},
"include": [
".",
"../../types/shared.d.ts",
".",
"../../types/shared.d.ts"
]
}

0 comments on commit f4f019e

Please sign in to comment.