-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fix] server web dynamic api url (#2780)
* fix: server web dynamic api using server setting value * fix: apply dynamic api on desktop server web * fix: dialog restart server on save setting * fix: server web application menu * fix: replace config setting on windows os * style: clean code
- Loading branch information
Showing
12 changed files
with
209 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './create-window' | ||
export * from './create-window'; | ||
export * from './replace-config'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import fg from 'fast-glob'; | ||
import os from 'os'; | ||
|
||
type EnvOptions = { | ||
before: { | ||
NEXT_PUBLIC_GAUZY_API_SERVER_URL?: string | ||
}, | ||
after: { | ||
NEXT_PUBLIC_GAUZY_API_SERVER_URL?: string | ||
} | ||
} | ||
|
||
const scanAllFiles = async (files: string[], oldConfig: string, newConfig: string) => { | ||
files.forEach((file) => { | ||
if (path.extname(file) === '.js') { | ||
try { | ||
const data = fs.readFileSync(file, 'utf-8'); | ||
const result = data.replace(new RegExp(oldConfig, 'g'), newConfig); | ||
fs.writeFileSync(file, result, 'utf8'); | ||
} catch (error) { | ||
console.log('error replace', error); | ||
} | ||
} | ||
}); | ||
} | ||
export const replaceConfig = async (folderPath: string, envOptions: EnvOptions) => { | ||
try { | ||
console.log('all files path', folderPath); | ||
if (os.platform() === 'win32') { | ||
folderPath = folderPath.replace(/\\/g, '/'); | ||
} | ||
console.log('final path', folderPath); | ||
const NEXT_PUBLIC_GAUZY_API_SERVER_URL_BEFORE = `"NEXT_PUBLIC_GAUZY_API_SERVER_URL","${envOptions.before.NEXT_PUBLIC_GAUZY_API_SERVER_URL}"`; | ||
const NEXT_PUBLIC_GAUZY_API_SERVER_URL_AFTER = `"NEXT_PUBLIC_GAUZY_API_SERVER_URL","${envOptions.after.NEXT_PUBLIC_GAUZY_API_SERVER_URL}"`; | ||
const NEXT_PUBLIC_GAUZY_API_SERVER_URL_DEFAULT = `"NEXT_PUBLIC_GAUZY_API_SERVER_URL","https://api.ever.team"`; | ||
const files = await fg(`${folderPath}/**/*`, { onlyFiles: true }); | ||
await scanAllFiles(files, NEXT_PUBLIC_GAUZY_API_SERVER_URL_BEFORE, NEXT_PUBLIC_GAUZY_API_SERVER_URL_AFTER); | ||
await scanAllFiles(files, NEXT_PUBLIC_GAUZY_API_SERVER_URL_DEFAULT, NEXT_PUBLIC_GAUZY_API_SERVER_URL_AFTER); | ||
} catch (error) { | ||
console.log('error on replacing file', error); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.