Skip to content

Commit

Permalink
chore: 依赖更新,构建服务优化
Browse files Browse the repository at this point in the history
  • Loading branch information
crlang committed Jul 4, 2022
1 parent 01c9738 commit b9fed55
Show file tree
Hide file tree
Showing 26 changed files with 1,048 additions and 2,294 deletions.
4 changes: 1 addition & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ module.exports = defineConfig({
node: true,
es6: true,
},
globals: {
jest: 'readonly',
},
globals: { },
parser: 'vue-eslint-parser',
parserOptions: {
parser: '@typescript-eslint/parser',
Expand Down
39 changes: 20 additions & 19 deletions build/script/buildConf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,43 @@
*/
import { GLOB_CONFIG_FILE_NAME, OUTPUT_DIR } from '../constant'
import fs, { writeFileSync } from 'fs-extra'
import chalk from 'chalk'
import colors from 'picocolors'

import { getRootPath, getEnvConfig } from '../utils'
import { getEnvConfig, getRootPath } from '../utils'
import { getConfigFileName } from '../getConfigFileName'

import pkg from '../../package.json'

function createConfig(
{
configName,
config,
configFileName = GLOB_CONFIG_FILE_NAME,
}: { configName: string; config: any; configFileName?: string } = { configName: '', config: {} }
) {
interface CreateConfigParams {
configName: string;
config: any;
configFileName?: string;
}

function createConfig(params: CreateConfigParams) {
const { configName, config, configFileName } = params
try {
const windowConf = `window.${configName}`
// Ensure that the variable will not be modified
const configStr = `${windowConf}=${JSON.stringify(config)};
Object.freeze(${windowConf});
Object.defineProperty(window, "${configName}", {
configurable: false,
writable: false,
});
`.replace(/\s/g, '')
Object.freeze(${windowConf});
Object.defineProperty(window, "${configName}", {
configurable: false,
writable: false,
});
`.replace(/\s/g, '')
fs.mkdirp(getRootPath(OUTPUT_DIR))
writeFileSync(getRootPath(`${OUTPUT_DIR}/${configFileName}`), configStr)

console.info(chalk.cyan(`[${pkg.name}]`) + ` - configuration file is build successfully:`)
console.info(chalk.gray(OUTPUT_DIR + '/' + chalk.green(configFileName)) + '\n')
console.log(colors.cyan(`[${pkg.name}]`) + ` - configuration file is build successfully:`)
console.log(colors.gray(OUTPUT_DIR + '/' + colors.green(configFileName)) + '\n')
} catch (error) {
console.error(chalk.red('configuration file configuration file failed to package:\n' + error))
console.log(colors.red('configuration file configuration file failed to package:\n' + error))
}
}

export function runBuildConfig() {
const config = getEnvConfig()
const configFileName = getConfigFileName(config)
createConfig({ config, configName: configFileName })
createConfig({ config, configName: configFileName, configFileName: GLOB_CONFIG_FILE_NAME })
}
6 changes: 3 additions & 3 deletions build/script/postBuild.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// #!/usr/bin/env node

import { runBuildConfig } from './buildConf'
import chalk from 'chalk'
import colors from 'picocolors'

import pkg from '../../package.json'

Expand All @@ -14,9 +14,9 @@ export const runBuild = async () => {
runBuildConfig()
}

console.info(`${chalk.cyan(`[${pkg.name}]`)}` + ' - build successfully!')
console.log(`✨ ${colors.cyan(`[${pkg.name}]`)}` + ' - build successfully!')
} catch (error) {
console.error(chalk.red('vite build error:\n' + error))
console.log(colors.red('vite build error:\n' + error))
process.exit(1)
}
}
Expand Down
12 changes: 6 additions & 6 deletions build/vite/plugin/compress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
* Used to package and output gzip. Note that this does not work properly in Vite, the specific reason is still being investigated
* https://github.com/anncwb/vite-plugin-compression
*/
import type { Plugin } from 'vite'
import type { PluginOption } from 'vite'
import compressPlugin from 'vite-plugin-compression'

export function configCompressPlugin(
compress: 'gzip' | 'brotli' | 'none',
deleteOriginFile = false
): Plugin | Plugin[] {
deleteOriginFile = false,
): PluginOption | PluginOption[] {
const compressList = compress.split(',')

const plugins: Plugin[] = []
const plugins: PluginOption[] = []

if (compressList.includes('gzip')) {
plugins.push(
compressPlugin({
ext: '.gz',
deleteOriginFile,
})
}),
)
}

Expand All @@ -28,7 +28,7 @@ export function configCompressPlugin(
ext: '.br',
algorithm: 'brotliCompress',
deleteOriginFile,
})
}),
)
}
return plugins
Expand Down
6 changes: 3 additions & 3 deletions build/vite/plugin/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* Plugin to minimize and use ejs template syntax in index.html.
* https://github.com/anncwb/vite-plugin-html
*/
import type { Plugin } from 'vite'
import html from 'vite-plugin-html'
import type { PluginOption } from 'vite'
import { createHtmlPlugin } from 'vite-plugin-html'
import pkg from '../../../package.json'
import { GLOB_CONFIG_FILE_NAME } from '../../constant'

Expand All @@ -16,7 +16,7 @@ export function configHtmlPlugin(env: ViteEnv, isBuild: boolean) {
return `${path || '/'}${GLOB_CONFIG_FILE_NAME}?v=${pkg.version}-${new Date().getTime()}`
}

const htmlPlugin: Plugin[] = html({
const htmlPlugin: PluginOption[] = createHtmlPlugin({
minify: isBuild,
inject: {
// Inject data into ejs template
Expand Down
6 changes: 3 additions & 3 deletions build/vite/plugin/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ export function configMockPlugin(isBuild: boolean) {
localEnabled: !isBuild,
prodEnabled: isBuild,
injectCode: `
import { setupProdMockServer } from '../mock/_createProductionServer';
import { setupProdMockServer } from '../mock/_createProductionServer';
setupProdMockServer();
`,
setupProdMockServer();
`,
})
}
4 changes: 2 additions & 2 deletions build/vite/plugin/pwa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ export function configPwaConfig(env: ViteEnv) {
short_name: VITE_GLOB_APP_SHORT_NAME,
icons: [
{
src: './images/pwa-192x192.png',
src: './resource/img/pwa-192x192.png',
sizes: '192x192',
type: 'image/png',
},
{
src: './images/pwa-512x512.png',
src: './resource/img/pwa-512x512.png',
sizes: '512x512',
type: 'image/png',
},
Expand Down
4 changes: 2 additions & 2 deletions build/vite/plugin/svgSprite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* https://github.com/anncwb/vite-plugin-svg-icons
*/

import SvgIconsPlugin from 'vite-plugin-svg-icons'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import path from 'path'

export function configSvgIconsPlugin(isBuild: boolean) {
const svgIconsPlugin = SvgIconsPlugin({
const svgIconsPlugin = createSvgIconsPlugin({
iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
svgoOptions: isBuild,
// default
Expand Down
12 changes: 6 additions & 6 deletions build/vite/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
*/
import type { ProxyOptions } from 'vite'

type ProxyItem = [string, string]
type ProxyItem = [string, string];

type ProxyList = ProxyItem[]
type ProxyList = ProxyItem[];

type ProxyTargetList = Record<string, ProxyOptions & { rewrite: (path: string) => string }>
type ProxyTargetList = Record<string, ProxyOptions>;

const httpsRE = /^https:\/\//

/**
* Generate proxy
* @param list
*/
* Generate proxy
* @param list
*/
export function createProxy(list: ProxyList = []) {
const ret: ProxyTargetList = {}
for (const [prefix, target] of list) {
Expand Down
36 changes: 0 additions & 36 deletions jest.config.mjs

This file was deleted.

27 changes: 9 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@
"lint:prettier": "prettier --write \"src/**/*.{js,json,ts,vue,tsx,html,md}\"",
"lint:stylelint": "stylelint --fix \"**/*.{vue,postcss,css,scss}\" --cache-location node_modules/.cache/stylelint/",
"lint:lint-staged": "lint-staged -c ./.husky/lintstagedrc.js",
"test:unit": "jest",
"test:unit-coverage": "jest --coverage",
"test:gzip": "http-server dist --cors --gzip -c-1",
"test:br": "http-server dist --cors --brotli -c-1",
"test:gzip": "npx http-server dist --cors --gzip -c-1",
"test:br": "npx http-server dist --cors --brotli -c-1",
"reinstall": "rimraf yarn.lock && rimraf package.lock.json && rimraf node_modules && npm run bootstrap",
"prepare": "husky install"
},
Expand Down Expand Up @@ -58,9 +56,7 @@
"@iconify/json": "^1.1.453",
"@purge-icons/generated": "^0.7.0",
"@types/fs-extra": "^9.0.13",
"@types/inquirer": "^8.1.3",
"@types/intro.js": "^3.0.2",
"@types/jest": "^27.4.0",
"@types/lodash-es": "^4.17.5",
"@types/mockjs": "^1.0.4",
"@types/node": "^17.0.8",
Expand All @@ -85,16 +81,12 @@
"eslint-config-prettier": "^8.5.0",
"eslint-define-config": "^1.2.2",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jest": "^25.3.4",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-vue": "^8.2.0",
"esno": "^0.13.0",
"fs-extra": "^10.0.0",
"http-server": "^14.0.0",
"husky": "^7.0.4",
"inquirer": "^8.2.0",
"is-ci": "^3.0.1",
"jest": "^27.4.7",
"lint-staged": "^12.1.5",
"node-sass": "^7.0.1",
"npm-run-all": "^4.1.5",
Expand All @@ -113,20 +105,19 @@
"stylelint-config-standard-scss": "^3.0.0",
"stylelint-order": "^5.0.0",
"stylelint-scss": "^4.1.0",
"ts-jest": "^27.1.2",
"ts-node": "^10.4.0",
"typescript": "^4.5.4",
"vite": "^2.7.10",
"vite-plugin-compression": "^0.4.0",
"vite-plugin-html": "^2.1.2",
"vite-plugin-imagemin": "^0.5.1",
"vite-plugin-compression": "^0.5.1",
"vite-plugin-html": "^3.2.0",
"vite-plugin-imagemin": "^0.6.1",
"vite-plugin-mock": "^2.9.6",
"vite-plugin-optimize-persist": "^0.1.2",
"vite-plugin-package-config": "^0.1.1",
"vite-plugin-purge-icons": "^0.7.0",
"vite-plugin-pwa": "^0.11.12",
"vite-plugin-style-import": "^1.4.1",
"vite-plugin-svg-icons": "^1.1.0",
"vite-plugin-purge-icons": "^0.8.1",
"vite-plugin-pwa": "^0.12.2",
"vite-plugin-style-import": "^2.0.0",
"vite-plugin-svg-icons": "^2.0.1",
"vue-eslint-parser": "8.0.1",
"vue-tsc": "^0.30.2",
"workbox-build": "^6.4.2",
Expand Down
1 change: 0 additions & 1 deletion tests/__mocks__/fileMock.ts

This file was deleted.

1 change: 0 additions & 1 deletion tests/__mocks__/styleMock.ts

This file was deleted.

5 changes: 0 additions & 5 deletions tests/__mocks__/workerMock.ts

This file was deleted.

4 changes: 2 additions & 2 deletions tests/server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ It is used to start the test interface service, which can test the upload, webso

cd ./test/server

yarn
pnpm install

yarn start
pnpm run start

```
1 change: 1 addition & 0 deletions tests/server/controller/FileController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class FileController {

upload = async (ctx) => {
const files = ctx.request.files.file
console.log(files)

if (files.length === undefined) {
this.service.upload(ctx, files, false)
Expand Down
6 changes: 3 additions & 3 deletions tests/server/controller/UserController.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import UserService from '../service/UserService'

class UserController {
private service: UserService = new UserService();
private service: UserService = new UserService()

login = async (ctx) => {
ctx.body = await this.service.login()
};
}

getUserInfoById = async (ctx) => {
ctx.body = await this.service.getUserInfoById()
};
}
}

export default new UserController()
3 changes: 2 additions & 1 deletion tests/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ app.ws.use(
})
ctx.websocket.send(data)
}
console.log(message)
})
}),
)
Expand All @@ -58,5 +59,5 @@ app.use(router.allowedMethods())
app.use(koaStatic(path.join(__dirname)))

app.listen(PORT, () => {
console.info(`Application started successfully: http://localhost:${PORT}`)
console.log(`Application started successfully: http://localhost:${PORT}`)
})
Loading

0 comments on commit b9fed55

Please sign in to comment.