-
-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1723 from flexn-io/feat/override_plugins_on_install
Feat/override plugins on install
- Loading branch information
Showing
9 changed files
with
166 additions
and
75 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
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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
const path = require('path'); | ||
const { | ||
createRnvContext, | ||
loadWorkspacesConfigSync, | ||
loadDefaultConfigTemplates, | ||
updateRenativeConfigs, | ||
overrideTemplatePlugins, | ||
createRnvApi, | ||
getConfigProp, | ||
doResolve, | ||
logError, | ||
RnvFileName, | ||
fsExistsSync, | ||
fsReadFileSync, | ||
removeDirSync, | ||
revertOverrideToOriginal, | ||
} = require('@rnv/core'); | ||
|
||
const Logger = require('@rnv/cli/lib/logger'); | ||
const RNV_HOME_DIR = path.join(__dirname, '..'); | ||
|
||
(async () => { | ||
try { | ||
createRnvApi({ | ||
logger: Logger, | ||
getConfigProp, | ||
doResolve, | ||
}); | ||
createRnvContext({ RNV_HOME_DIR }); | ||
|
||
loadWorkspacesConfigSync(); | ||
await loadDefaultConfigTemplates(); | ||
await updateRenativeConfigs(); | ||
await resetOverrides(); | ||
|
||
await overrideTemplatePlugins(); | ||
} catch (error) { | ||
logError(error); | ||
} | ||
})(); | ||
|
||
const resetOverrides = async () => { | ||
const overrideDir = path.join(process.cwd(), '.rnv', 'overrides'); | ||
|
||
const appliedOverrideFilePath = path.join(overrideDir, RnvFileName.appliedOverride); | ||
|
||
if (fsExistsSync(appliedOverrideFilePath)) { | ||
const appliedOverrides = JSON.parse(fsReadFileSync(appliedOverrideFilePath).toString()); | ||
|
||
Object.keys(appliedOverrides).forEach((moduleName) => { | ||
const appliedVersion = appliedOverrides[moduleName].version; | ||
const packageJsonPath = path.join(process.cwd(), 'node_modules', moduleName, RnvFileName.package); | ||
|
||
if (fsExistsSync(packageJsonPath)) { | ||
const packageContent = JSON.parse(fsReadFileSync(packageJsonPath).toString()); | ||
const currentVersion = packageContent.version; | ||
|
||
if (currentVersion === appliedVersion) { | ||
const packageOverrides = appliedOverrides[moduleName]; | ||
Object.keys(packageOverrides).forEach((filePath) => { | ||
if (filePath !== 'version') { | ||
const backupPath = path.join(overrideDir, moduleName, filePath); | ||
const destinationPath = path.join(process.cwd(), 'node_modules', moduleName, filePath); | ||
|
||
revertOverrideToOriginal(destinationPath, backupPath); | ||
} | ||
}); | ||
} | ||
} | ||
}); | ||
removeDirSync(overrideDir); | ||
return true; | ||
} | ||
return false; | ||
}; |