-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added CLI command to migrate to using
openedx
scope (#2984)
* feat: added migration command to new openedx-paragon npm package * chore: add default path to the cli --------- Co-authored-by: Viktor Rusakov <[email protected]>
- Loading branch information
1 parent
51d864a
commit 6927788
Showing
2 changed files
with
74 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const chalk = require('chalk'); | ||
|
||
const isValidFileExtension = (filename) => /(.jsx|.js|.tsx|.ts|.md|.rst|.scss)$/.test(filename.toLowerCase()); | ||
|
||
/** | ||
* Processes the content of a file by replacing occurrences of '@edx/paragon' with '@openedx/paragon'. | ||
* | ||
* @param {string} filePath - The path to the file to process. | ||
*/ | ||
function processFileContent(filePath) { | ||
const fileName = path.basename(filePath); | ||
|
||
if (!isValidFileExtension(fileName)) { | ||
return; | ||
} | ||
|
||
const fileContent = fs.readFileSync(filePath, 'utf-8'); | ||
const updatedContent = fileContent.replace(/@edx\/paragon/g, '@openedx/paragon'); | ||
|
||
if (fileContent !== updatedContent) { | ||
fs.writeFileSync(filePath, updatedContent, 'utf-8'); | ||
console.log(`Updated file: ${filePath}`); // eslint-disable-line no-console | ||
} | ||
} | ||
|
||
/** | ||
* Performs a migration from "@edx/paragon" to "@openedx/paragon" NPM package name. | ||
*/ | ||
function migrateToOpenEdxScopeCommand() { | ||
const projectPath = process.argv[3] || path.resolve(__dirname, '../../../../'); | ||
const stack = [projectPath]; | ||
|
||
while (stack.length > 0) { | ||
const currentDir = stack.pop(); | ||
const files = fs.readdirSync(currentDir); | ||
|
||
files.forEach(file => { | ||
const filePath = path.join(currentDir, file); | ||
const fileStats = fs.statSync(filePath); | ||
|
||
if (fileStats.isDirectory()) { | ||
if (file === 'node_modules') { | ||
return; | ||
} | ||
|
||
if (file.startsWith('.') && file !== '.' && file !== '..') { | ||
return; | ||
} | ||
|
||
stack.push(filePath); | ||
} else { | ||
processFileContent(filePath); | ||
} | ||
}); | ||
} | ||
|
||
console.error(`${chalk.green.bold('Paragon migration to Openedx scope completed successfully.')}`); // eslint-disable-line no-console | ||
} | ||
|
||
module.exports = migrateToOpenEdxScopeCommand; |