Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: Windows setup on DeepSpeech dep removal
- Loading branch information
Showing
2 changed files
with
22 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,32 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
const os = require('os') | ||
const { execSync } = require('child_process') | ||
|
||
/** | ||
* Trigger preinstall hook to remove DeepSpeech on Windows | ||
*/ | ||
|
||
console.info('\x1b[36m➡ %s\x1b[0m', 'Running Leon\'s installation...') | ||
|
||
if (os.type().indexOf('Windows') !== -1) { | ||
const packageJsonPath = path.join(__dirname, '../../package.json') | ||
const packageJson = require(packageJsonPath) | ||
|
||
console.warn('\x1b[33m❗ %s\x1b[0m', 'The Leon\'s voice offline mode is not available on Windows') | ||
console.info('\x1b[36m➡ %s\x1b[0m', 'Backing up package.json...') | ||
fs.copyFileSync('package.json', 'package.json.backup') | ||
console.log('\x1b[32m✔ %s\x1b[0m', 'package.json has been backed up') | ||
console.info('\x1b[36m➡ %s\x1b[0m', 'Removing DeepSpeech dependency... Please wait, this might take several minutes...') | ||
execSync('npm uninstall --save deepspeech') | ||
console.log('\x1b[32m✔ %s\x1b[0m', 'DeepSpeech dependency has been removed.') | ||
} | ||
|
||
console.info('\x1b[36m➡ %s\x1b[0m', 'Running Leon\'s installation...') | ||
try { | ||
if (packageJson?.dependencies.deepspeech) { | ||
console.info('\x1b[36m➡ %s\x1b[0m', 'Removing DeepSpeech dependency...') | ||
|
||
delete packageJson.dependencies.deepspeech | ||
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2)) | ||
|
||
console.log('\x1b[32m✔ %s\x1b[0m', 'DeepSpeech dependency has been removed.') | ||
} | ||
} catch (e) { | ||
console.error('\x1b[31m✖ %s\x1b[0m', 'Failed to remove DeepSpeech dependency') | ||
} | ||
} |
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