Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9c130d4

Browse files
committed
refactor extension env vars
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent9328da7 commit9c130d4

File tree

9 files changed

+33
-36
lines changed

9 files changed

+33
-36
lines changed

‎src/actions/utils/loadWatchers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import*aschokidarfrom'chokidar'
22
import*asvscodefrom'vscode'
33
import{COMMANDS}from'../../editor/commands'
4-
importenvironmentfrom'../../environment'
4+
import{WORKSPACE_ROOT}from'../../environment'
55

66
// NOTE: vscode createFileWatcher doesn't seem to detect changes outside of vscode
77
// such as `npm install` of a package. Went with chokidar instead
@@ -26,7 +26,7 @@ const loadWatchers = (watchers: string[]) => {
2626
// see how glob patterns are used in VSCode (not like a regex)
2727
// https://code.visualstudio.com/api/references/vscode-api#GlobPattern
2828
constfsWatcher:chokidar.FSWatcher=chokidar.watch(watcher,{
29-
cwd:environment.WORKSPACE_ROOT,
29+
cwd:WORKSPACE_ROOT,
3030
interval:1000,
3131
})
3232

‎src/channel/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { openWorkspace, checkWorkspaceEmpty } from '../services/workspace'
1414
import{readFile}from'fs'
1515
import{join}from'path'
1616
import{promisify}from'util'
17-
importenvironmentfrom'../environment'
17+
import{WORKSPACE_ROOT}from'../environment'
1818

1919
constreadFileAsync=promisify(readFile)
2020

@@ -50,7 +50,7 @@ class Channel implements Channel {
5050
switch(actionType){
5151
case'EDITOR_STARTUP':
5252
// check if a workspace is open, otherwise nothing works
53-
constnoActiveWorksapce=!environment.WORKSPACE_ROOT.length
53+
constnoActiveWorksapce=!WORKSPACE_ROOT.length
5454
if(noActiveWorksapce){
5555
consterror:E.ErrorMessage={
5656
type:'NoWorkspaceFound',

‎src/environment.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,20 @@ require('dotenv').config({
44

55
import{getWorkspaceRoot}from'./services/workspace'
66

7-
interfaceEnvironment{
8-
VERSION:string
9-
NODE_ENV:string
10-
LOG:boolean
11-
API_URL:string
12-
SENTRY_DSN:string|null
13-
WORKSPACE_ROOT:string
14-
}
7+
// CodeRoad version
8+
exportconstVERSION:string=process.env.npm_package_version||'unknown'
159

16-
constenvironment:Environment={
17-
VERSION:process.env.VERSION||'unknown',
18-
NODE_ENV:process.env.NODE_ENV||'production',
19-
LOG:(process.env.REACT_APP_LOG||'').toLowerCase()==='true'&&process.env.NODE_ENV!=='production',
20-
API_URL:process.env.REACT_APP_GQL_URI||'',
21-
SENTRY_DSN:process.env.SENTRY_DSN||null,
22-
WORKSPACE_ROOT:getWorkspaceRoot(),
23-
}
10+
// Node env
11+
exporttypeEnv='test'|'local'|'development'|'production'
12+
//@ts-ignore
13+
exportconstNODE_ENV:Env=process.env.NODE_ENV||'production'
2414

25-
exportdefaultenvironment
15+
// toggle logging in development
16+
exportconstLOG:boolean=
17+
(process.env.REACT_APP_LOG||'').toLowerCase()==='true'&&process.env.NODE_ENV!=='production'
18+
19+
// error logging tool
20+
exportconstSENTRY_DSN:string|null=process.env.SENTRY_DSN||null
21+
22+
// uri path to the users project workspace
23+
exportconstWORKSPACE_ROOT:string=getWorkspaceRoot()

‎src/services/logger/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
importenviromentfrom'../../environment'
1+
import{LOG}from'../../environment'
22

33
constlogger=(message:string|string[])=>{
4-
if(!enviroment.LOG){
4+
if(!LOG){
55
return
66
}
77
if(Array.isArray(message)){

‎src/services/node/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ import { exec as cpExec } from 'child_process'
22
import*asfsfrom'fs'
33
import{join}from'path'
44
import{promisify}from'util'
5-
importenvironmentfrom'../../environment'
5+
import{WORKSPACE_ROOT}from'../../environment'
66

77
constasyncExec=promisify(cpExec)
88

99
exportconstexec=(cmd:string):Promise<{stdout:string;stderr:string}>|never=>{
1010
returnasyncExec(cmd,{
11-
cwd:environment.WORKSPACE_ROOT,
11+
cwd:WORKSPACE_ROOT,
1212
})
1313
}
1414

1515
exportconstexists=(...paths:string[]):boolean|never=>{
16-
returnfs.existsSync(join(environment.WORKSPACE_ROOT, ...paths))
16+
returnfs.existsSync(join(WORKSPACE_ROOT, ...paths))
1717
}

‎src/services/sentry/init.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import{init}from'@sentry/node'
2-
importenvironmentfrom'../../environment'
2+
import{SENTRY_DSN,NODE_ENV}from'../../environment'
33

4-
if(environment.SENTRY_DSN){
4+
if(SENTRY_DSN){
55
init({
6-
dsn:environment.SENTRY_DSN,
7-
environment:environment.NODE_ENV,
6+
dsn:SENTRY_DSN,
7+
environment:NODE_ENV,
88
})
99
}

‎src/services/sentry/onError.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import*assentryfrom'@sentry/node'
22
// import { Scope } from '@sentry/hub'
3-
importenvironmentfrom'../../environment'
3+
import{VERSION}from'../../environment'
44

55
constonError=(error:Error)=>{
66
// set user scope https://docs.sentry.io/enriching-error-data/scopes/?platform=node
77
sentry.withScope((scope:any)=>{
8-
scope.setTag('VERSION',environment.VERSION)
8+
scope.setTag('VERSION',VERSION)
99
// if (user) {
1010
// scope.setUser({
1111
// id: user.id,

‎src/services/workspace/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import*asvscodefrom'vscode'
22
import*asfsfrom'fs'
33
import{promisify}from'util'
4-
importenvironmentfrom'../../environment'
4+
import{WORKSPACE_ROOT}from'../../environment'
55

66
constreadDir=promisify(fs.readdir)
77

@@ -13,7 +13,7 @@ export const openWorkspace = () => {
1313
exportconstcheckWorkspaceEmpty=async()=>{
1414
letfiles
1515
try{
16-
files=awaitreadDir(environment.WORKSPACE_ROOT)
16+
files=awaitreadDir(WORKSPACE_ROOT)
1717
}catch(error){
1818
thrownewError('Failed to check workspace')
1919
}

‎src/webview/render.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { JSDOM } from 'jsdom'
22
import*aspathfrom'path'
33
import*asvscodefrom'vscode'
44
importonErrorfrom'../services/sentry/onError'
5-
importenvironmentfrom'../environment'
65

76
constgetNonce=():string=>{
87
lettext=''
@@ -73,7 +72,7 @@ async function render(panel: vscode.WebviewPanel, rootPath: string) {
7372
cspMeta.content=
7473
[
7574
`default-src 'self'`,
76-
`connect-src https: http:${environment.API_URL}`,
75+
`connect-src https: http:`,
7776
//@ts-ignore
7877
`font-src${panel.webview.cspSource} http: https: data:`,
7978
//@ts-ignore

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp