Skip to content

Commit 65751e5

Browse files
committed
fix: export isDevEnv as static method
1 parent b17618d commit 65751e5

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed

build.mjs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,55 @@
1-
import esbuild from 'esbuild'
2-
import copyPluginPkg from '@sprout2000/esbuild-copy-plugin'
3-
import { lessLoader } from 'esbuild-plugin-less'
4-
import * as process from 'node:process'
5-
import * as console from 'node:console'
1+
import esbuild from "esbuild"
2+
import copyPluginPkg from "@sprout2000/esbuild-copy-plugin"
3+
import { lessLoader } from "esbuild-plugin-less"
4+
import * as process from "node:process"
5+
import * as console from "node:console"
66

77
const { copyPlugin } = copyPluginPkg
8-
const isProduction = !process.argv.includes('--development')
9-
const OUT_DIR = 'dist'
8+
const isProduction = !process.argv.includes("--development")
9+
const OUT_DIR = "dist"
1010

1111
const defaultOptions = {
12-
format: 'cjs',
13-
resolveExtensions: ['.ts', '.js', '.mjs', '.tsx'],
12+
format: "cjs",
13+
resolveExtensions: [".ts", ".js", ".mjs", ".tsx"],
1414
bundle: true,
1515
sourcemap: !isProduction,
1616
minify: isProduction,
17-
platform: 'node',
17+
platform: "node",
1818
outdir: OUT_DIR,
1919
}
2020

2121
async function buildExtension() {
2222
const options = {
2323
...defaultOptions,
24-
entryPoints: ['./src/extension.ts'],
25-
external: ['vscode', '@mapbox/node-pre-gyp', 'sequelize'],
24+
entryPoints: ["./src/extension.ts"],
25+
external: ["vscode", "@mapbox/node-pre-gyp", "sequelize"],
2626
define: {
27-
// eslint-disable-next-line @typescript-eslint/naming-convention
2827
CNBLOGS_CLIENTID: JSON.stringify(process.env.CLIENTID),
29-
// eslint-disable-next-line @typescript-eslint/naming-convention
3028
CNBLOGS_CLIENTSECRET: JSON.stringify(process.env.CLIENTSECRET),
3129
},
3230
plugins: [
3331
copyPlugin({
34-
src: 'src/assets',
32+
src: "src/assets",
3533
dest: `${OUT_DIR}/assets`,
3634
errorOnExist: false,
3735
}),
3836
copyPlugin({
39-
src: 'node_modules/@mapbox/node-pre-gyp',
37+
src: "node_modules/@mapbox/node-pre-gyp",
4038
dest: `${OUT_DIR}/node_modules/@mapbox/node-pre-gyp`,
4139
errorOnExist: false,
4240
}),
4341
copyPlugin({
44-
src: 'node_modules/sequelize',
42+
src: "node_modules/sequelize",
4543
dest: `${OUT_DIR}/node_modules/sequelize`,
4644
errorOnExist: false,
4745
}),
4846
copyPlugin({
49-
src: 'node_modules/@fluentui/font-icons-mdl2/fonts/',
47+
src: "node_modules/@fluentui/font-icons-mdl2/fonts/",
5048
dest: `${OUT_DIR}/assets/fonts`,
5149
errorOnExist: false,
5250
}),
5351
copyPlugin({
54-
src: 'src/wasm/rs_bg.wasm',
52+
src: "src/wasm/rs_bg.wasm",
5553
dest: `${OUT_DIR}/rs_bg.wasm`,
5654
errorOnExist: false,
5755
}),
@@ -62,13 +60,13 @@ async function buildExtension() {
6260
}
6361

6462
async function buildUI(...apps) {
65-
const srcPath = './ui/'
63+
const srcPath = "./ui/"
6664
const outPath = `${OUT_DIR}/assets/ui/`
6765
for (const app of apps) {
6866
const options = {
6967
...defaultOptions,
7068
define: {
71-
'process.env.NODE_ENV': JSON.stringify('production'),
69+
"process.env.NODE_ENV": JSON.stringify("production"),
7270
},
7371
entryPoints: [`${srcPath}${app}/index.tsx`],
7472
outdir: `${outPath}${app}`,
@@ -86,7 +84,9 @@ async function buildUI(...apps) {
8684
}
8785
}
8886

89-
await Promise.all([buildExtension(), buildUI('ing', 'post-cfg')]).catch(ex => {
90-
console.error(ex)
91-
process.exit(1)
92-
})
87+
await Promise.all([buildExtension(), buildUI("ing", "post-cfg")]).catch(
88+
(ex) => {
89+
console.error(ex)
90+
process.exit(1)
91+
},
92+
)

src/ctx/ext-const.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
declare const CNBLOGS_CLIENTID: string
22
declare const CNBLOGS_CLIENTSECRET: string
33

4-
const isDevEnv = () => process.env.NODE_ENV === 'Development'
5-
64
export class ExtConst {
75
static EXT_NAME = 'vscode-cnb'
86
static EXT_PUBLISHER = 'cnblogs'
@@ -19,6 +17,8 @@ export class ExtConst {
1917
}
2018

2119
static OAUTH_SCOPES = ['openid', 'profile', 'CnBlogsApi', 'CnblogsAdminApi']
20+
21+
static isDevEnv = () => process.env.NODE_ENV === 'Development'
2222
}
2323

2424
export function extName(tail: any) {

src/service/blog-export/blog-export-post.store.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import { ExportPostModel } from '@/model/blog-export/export-post'
33
import { DataTypes, Op, Sequelize } from 'sequelize'
44
import { Disposable } from 'vscode'
55
import sqlite3 from 'sqlite3'
6-
import { isDevEnv } from '@/ctx/ext-const'
6+
import { ExtConst } from '@/ctx/ext-const'
77

88
export class ExportPostStore implements Disposable {
99
private _sequelize = new Sequelize({
1010
dialect: 'sqlite',
1111
storage: this.downloadedExport.filePath,
1212
dialectModule: sqlite3,
13-
logging: (...msg) => (isDevEnv() ? console.log(msg) : undefined),
13+
logging: (...msg) => (ExtConst.isDevEnv() ? console.log(msg) : undefined),
1414
})
1515

1616
private _table = ExportPostModel

0 commit comments

Comments
 (0)