-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: continue Nouvelle initialisation de l'application #47
- Loading branch information
Showing
6 changed files
with
161 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { IpcMainEvent, IpcMainInvokeEvent } from 'electron' | ||
import { accessSync, constants } from 'node:fs' | ||
|
||
import { ConfigData } from '../../../class/ConfigData' | ||
import { getMainLog } from '../../main' | ||
import os from 'node:os' | ||
import path from 'node:path' | ||
|
||
export const initPluginCanInstall = ( | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
_event: IpcMainEvent | IpcMainInvokeEvent | ||
) => { | ||
const mainLog = getMainLog().scope( | ||
'main/initialization/initPluginGetLastVersion' | ||
) | ||
mainLog.debug( | ||
`Check latest version of lighthouse-plugin-ecoindex on registry.` | ||
) | ||
const toReturned = new ConfigData('plugin_installed') | ||
return new Promise<ConfigData>((resolve) => { | ||
try { | ||
const { homedir } = os.userInfo() | ||
// for testing `/Users/normaluser/Public` is not writable or readable | ||
// const npmPath = path.join( | ||
// os.platform() === 'win32' ? `C:\\` : `/`, | ||
// `Users`, | ||
// `normaluser`, | ||
// `Public` | ||
// ) | ||
const npmPath = path.join(homedir, '.npm') | ||
accessSync(npmPath, constants.R_OK && constants.W_OK) | ||
toReturned.result = true | ||
toReturned.message = `User can write` | ||
} catch (error) { | ||
toReturned.result = false | ||
toReturned.message = `User CAN'T write` | ||
} | ||
resolve(toReturned) | ||
}) | ||
} |
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,54 @@ | ||
import { IpcMainEvent, IpcMainInvokeEvent } from 'electron' | ||
|
||
import { ConfigData } from '../../../class/ConfigData' | ||
import { exec } from 'child_process' | ||
import { getMainLog } from '../../main' | ||
|
||
export const initPluginGetLastVersion = ( | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
_event: IpcMainEvent | IpcMainInvokeEvent, | ||
currentInstalledVersion: string | ||
) => { | ||
const mainLog = getMainLog().scope( | ||
'main/initialization/initPluginGetLastVersion' | ||
) | ||
mainLog.debug( | ||
`Check latest version of lighthouse-plugin-ecoindex on registry.` | ||
) | ||
/** | ||
* Dernière version sur le registry. | ||
*/ | ||
let latestVersion = '' | ||
const toReturned = new ConfigData('plugin_installed') | ||
return new Promise<ConfigData>((resolve) => { | ||
const cmd = `npm view lighthouse-plugin-ecoindex version` | ||
exec(cmd, (error, stdout, stderr) => { | ||
if (error) { | ||
mainLog.error(`exec error: ${error}`) | ||
toReturned.error = | ||
toReturned.message = `lighthouse-plugin-ecoindex can't check on registery` | ||
// resolve(toReturned) | ||
} | ||
if (stdout) { | ||
mainLog.debug(`latest version: ${stdout.trim()}`) | ||
// if (stderr) mainLog.error(`stderr: ${stderr}`) | ||
|
||
latestVersion = stdout.replace(`\n`, ``).trim() | ||
if ( | ||
currentInstalledVersion.trim() !== | ||
stdout.replace(`\n`, ``).trim() | ||
) { | ||
toReturned.result = latestVersion.trim() | ||
toReturned.message = `Update from version:${currentInstalledVersion.trim()} to latest version:${latestVersion.trim()} needed` | ||
mainLog.debug(toReturned.message) | ||
return resolve(toReturned) | ||
} else { | ||
toReturned.result = latestVersion.trim() | ||
toReturned.message = `lighthouse-plugin-ecoindex is up to date` | ||
mainLog.debug(toReturned.message) | ||
return resolve(toReturned) | ||
} | ||
} | ||
}) | ||
}) | ||
} |
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