-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c4d21fa
commit cf11bf5
Showing
4 changed files
with
149 additions
and
140 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 |
---|---|---|
@@ -0,0 +1,135 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
// Function to update package.json | ||
function updatePackageJson() { | ||
const packagePath = './package.json'; | ||
|
||
fs.readFile(packagePath, 'utf8', (err, data) => { | ||
if (err) { | ||
console.error(`Error reading package.json: ${err}`); | ||
return; | ||
} | ||
|
||
try { | ||
const packageJson = JSON.parse(data); | ||
|
||
// Update package name if necessary | ||
if (packageJson.name && packageJson.name === '@salesforce/core') { | ||
packageJson.name = '@salesforce/core-bundle'; | ||
} | ||
|
||
// Remove 'prepack' and 'prepare' scripts | ||
if (packageJson.scripts) { | ||
delete packageJson.scripts.prepack; | ||
delete packageJson.scripts.prepare; | ||
} | ||
|
||
// Remove 'exports' | ||
if (packageJson.exports) { | ||
delete packageJson.exports; | ||
} | ||
|
||
fs.writeFile(packagePath, JSON.stringify(packageJson, null, 2), 'utf8', (writeErr) => { | ||
if (writeErr) { | ||
console.error(`Error writing to package.json: ${writeErr}`); | ||
} else { | ||
console.log('package.json updated successfully.'); | ||
} | ||
}); | ||
} catch (parseErr) { | ||
console.error(`Error parsing JSON in package.json: ${parseErr}`); | ||
} | ||
}); | ||
} | ||
|
||
// Function to check the path to transformStream | ||
function checkTransformStreamPath() { | ||
const loggerPath = './src/logger/logger.ts'; | ||
const targetString = "target: path.join('..', '..', 'lib', 'logger', 'transformStream')"; | ||
const replacementString = "target: './transformStream'"; | ||
|
||
fs.readFile(loggerPath, 'utf8', (err, data) => { | ||
if (err) { | ||
console.error(`Error reading logger.ts: ${err}`); | ||
return; | ||
} | ||
|
||
// Check if the target string exists in the file | ||
if (!data.includes(targetString)) { | ||
console.error( | ||
`Error: The target string "${targetString}" was not found in logger.ts.\n Please make sure to bundle transformStream by referencing the new path or reach out to IDEx Foundations Team.` | ||
); | ||
return; | ||
} | ||
}); | ||
} | ||
|
||
// Function to update logger.ts | ||
function updateLoggerTs() { | ||
const loggerPath = './src/logger/logger.ts'; | ||
const targetString = "target: path.join('..', '..', 'lib', 'logger', 'transformStream')"; | ||
const replacementString = "target: './transformStream'"; | ||
|
||
fs.readFile(loggerPath, 'utf8', (err, data) => { | ||
if (err) { | ||
console.error(`Error reading logger.ts: ${err}`); | ||
return; | ||
} | ||
let updatedData = data.replace(targetString, replacementString); | ||
|
||
fs.writeFile(loggerPath, updatedData, 'utf8', (writeErr) => { | ||
if (writeErr) { | ||
console.error(`Error writing to logger.ts: ${writeErr}`); | ||
} else { | ||
console.log('Logger.ts updated successfully.'); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
function updateLoadMessagesParam() { | ||
const dirs = ['./src', './test']; | ||
function replaceTextInFile(filePath) { | ||
const data = fs.readFileSync(filePath, 'utf8'); | ||
const result = data.replace( | ||
/Messages\.loadMessages\('@salesforce\/core'/g, | ||
"Messages.loadMessages('@salesforce/core-bundle'" | ||
); | ||
fs.writeFileSync(filePath, result, 'utf8'); | ||
} | ||
function traverseDirectory(directory) { | ||
fs.readdirSync(directory).forEach((file) => { | ||
const fullPath = path.join(directory, file); | ||
if (fs.lstatSync(fullPath).isDirectory()) { | ||
traverseDirectory(fullPath); | ||
} else if (path.extname(fullPath) === '.ts') { | ||
replaceTextInFile(fullPath); | ||
} | ||
}); | ||
} | ||
dirs.forEach((dir) => { | ||
traverseDirectory(dir); | ||
}); | ||
} | ||
|
||
function addTestSetupToIndex() { | ||
const indexPath = './src/index.ts'; | ||
const testSetupExport = "export * from './testSetup';\n"; | ||
fs.readFile(indexPath, 'utf8', (err, data) => { | ||
fs.appendFile(indexPath, testSetupExport, 'utf8', (err) => { | ||
if (err) { | ||
console.error(`Error appending to file: ${err}`); | ||
} else { | ||
console.log('Content successfully added to the file.'); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
// Run the update functions | ||
exports.updatePackageJson = updatePackageJson; | ||
exports.checkTransformStreamPath = checkTransformStreamPath; | ||
exports.updateLoggerTs = updateLoggerTs; | ||
exports.updateLoadMessagesParam = updateLoadMessagesParam; | ||
exports.addTestSetupToIndex = addTestSetupToIndex; |
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,136 +1,13 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const { | ||
updatePackageJson, | ||
checkTransformStreamPath, | ||
updateLoggerTs, | ||
updateLoadMessagesParam, | ||
addTestSetupToIndex, | ||
} = require('./bundlingUtils'); | ||
|
||
// Function to update package.json | ||
function updatePackageJson() { | ||
const packagePath = './package.json'; | ||
|
||
fs.readFile(packagePath, 'utf8', (err, data) => { | ||
if (err) { | ||
console.error(`Error reading package.json: ${err}`); | ||
return; | ||
} | ||
|
||
try { | ||
const packageJson = JSON.parse(data); | ||
|
||
// Update package name if necessary | ||
if (packageJson.name && packageJson.name === '@salesforce/core') { | ||
packageJson.name = '@salesforce/core-bundle'; | ||
} | ||
|
||
// Remove 'prepack' and 'prepare' scripts | ||
if (packageJson.scripts) { | ||
delete packageJson.scripts.prepack; | ||
delete packageJson.scripts.prepare; | ||
} | ||
|
||
// Remove 'exports' | ||
if (packageJson.exports) { | ||
delete packageJson.exports; | ||
} | ||
|
||
fs.writeFile(packagePath, JSON.stringify(packageJson, null, 2), 'utf8', (writeErr) => { | ||
if (writeErr) { | ||
console.error(`Error writing to package.json: ${writeErr}`); | ||
} else { | ||
console.log('package.json updated successfully.'); | ||
} | ||
}); | ||
} catch (parseErr) { | ||
console.error(`Error parsing JSON in package.json: ${parseErr}`); | ||
} | ||
}); | ||
} | ||
|
||
// Function to check the path to transformStream | ||
function checkTransformStreamPath() { | ||
const loggerPath = './src/logger/logger.ts'; | ||
const targetString = "target: path.join('..', '..', 'lib', 'logger', 'transformStream')"; | ||
const replacementString = "target: './transformStream'"; | ||
|
||
fs.readFile(loggerPath, 'utf8', (err, data) => { | ||
if (err) { | ||
console.error(`Error reading logger.ts: ${err}`); | ||
return; | ||
} | ||
|
||
// Check if the target string exists in the file | ||
if (!data.includes(targetString)) { | ||
console.error( | ||
`Error: The target string "${targetString}" was not found in logger.ts.\n Please make sure to bundle transformStream by referencing the new path or reach out to IDEx Foundations Team.` | ||
); | ||
return; | ||
} | ||
}); | ||
} | ||
|
||
// Function to update logger.ts | ||
function updateLoggerTs() { | ||
const loggerPath = './src/logger/logger.ts'; | ||
const targetString = "target: path.join('..', '..', 'lib', 'logger', 'transformStream')"; | ||
const replacementString = "target: './transformStream'"; | ||
|
||
fs.readFile(loggerPath, 'utf8', (err, data) => { | ||
if (err) { | ||
console.error(`Error reading logger.ts: ${err}`); | ||
return; | ||
} | ||
let updatedData = data.replace(targetString, replacementString); | ||
|
||
fs.writeFile(loggerPath, updatedData, 'utf8', (writeErr) => { | ||
if (writeErr) { | ||
console.error(`Error writing to logger.ts: ${writeErr}`); | ||
} else { | ||
console.log('Logger.ts updated successfully.'); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
function updateLoadMessagesParam() { | ||
const dirs = ['./src', './test']; | ||
function replaceTextInFile(filePath) { | ||
const data = fs.readFileSync(filePath, 'utf8'); | ||
const result = data.replace( | ||
/Messages\.loadMessages\('@salesforce\/core'/g, | ||
"Messages.loadMessages('@salesforce/core-bundle'" | ||
); | ||
fs.writeFileSync(filePath, result, 'utf8'); | ||
} | ||
function traverseDirectory(directory) { | ||
fs.readdirSync(directory).forEach((file) => { | ||
const fullPath = path.join(directory, file); | ||
if (fs.lstatSync(fullPath).isDirectory()) { | ||
traverseDirectory(fullPath); | ||
} else if (path.extname(fullPath) === '.ts') { | ||
replaceTextInFile(fullPath); | ||
} | ||
}); | ||
} | ||
dirs.forEach((dir) => { | ||
traverseDirectory(dir); | ||
}); | ||
} | ||
|
||
function addTestSetupToIndex() { | ||
const indexPath = './src/index.ts'; | ||
const testSetupExport = "export * from './testSetup';\n"; | ||
fs.readFile(indexPath, 'utf8', (err, data) => { | ||
fs.appendFile(indexPath, testSetupExport, 'utf8', (err) => { | ||
if (err) { | ||
console.error(`Error appending to file: ${err}`); | ||
} else { | ||
console.log('Content successfully added to the file.'); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
// Run the update functions | ||
updatePackageJson(); | ||
checkTransformStreamPath(); | ||
updateLoggerTs(); | ||
updateLoadMessagesParam(); | ||
addTestSetupToIndex(); | ||
exports.checkTransformStreamPath = checkTransformStreamPath; |
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