-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: verify templates is the same in lib and src before each push (#596
) * test: verify templates is the same in lib and src before each push * chore: add comment for caution
- Loading branch information
1 parent
ff4444a
commit 0bcd077
Showing
3 changed files
with
74 additions
and
1 deletion.
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,4 +1,4 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
yarn build && yarn test | ||
yarn build && yarn test && node scripts/verify-for-bundling.js |
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,67 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
// Function to get all files in a directory recursively | ||
function getAllFiles(dirPath, arrayOfFiles = []) { | ||
const files = fs.readdirSync(dirPath); | ||
|
||
files.forEach((file) => { | ||
if (fs.statSync(path.join(dirPath, file)).isDirectory()) { | ||
arrayOfFiles = getAllFiles(path.join(dirPath, file), arrayOfFiles); | ||
} else { | ||
arrayOfFiles.push(path.join(dirPath, file)); | ||
} | ||
}); | ||
|
||
return arrayOfFiles; | ||
} | ||
|
||
// Function to compare the contents of two files | ||
function compareFiles(file1, file2) { | ||
const file1Contents = fs.readFileSync(file1, 'utf8'); | ||
const file2Contents = fs.readFileSync(file2, 'utf8'); | ||
return file1Contents === file2Contents; | ||
} | ||
|
||
let result = true; | ||
|
||
// Function to compare files and folders between two directories | ||
function compareDirectories(dir1, dir2) { | ||
const dir1Files = getAllFiles(dir1).map((file) => file.replace(dir1, '')); | ||
const dir2Files = getAllFiles(dir2).map((file) => file.replace(dir2, '')); | ||
|
||
const allFiles = new Set([...dir1Files, ...dir2Files]); | ||
|
||
allFiles.forEach((file) => { | ||
const filePath1 = path.join(dir1, file); | ||
const filePath2 = path.join(dir2, file); | ||
|
||
if (fs.existsSync(filePath1) && fs.existsSync(filePath2)) { | ||
if ( | ||
fs.statSync(filePath1).isDirectory() && | ||
fs.statSync(filePath2).isDirectory() | ||
) { | ||
// Both are directories, compare their contents recursively | ||
compareDirectories(filePath1, filePath2); | ||
} else if (!compareFiles(filePath1, filePath2)) { | ||
console.log(`Difference found in file: ${file}`); | ||
} | ||
} else { | ||
console.log( | ||
`File or directory exists only in one of the directories: ${file}` | ||
); | ||
result = false; | ||
} | ||
}); | ||
|
||
console.log('Comparison completed.'); | ||
} | ||
|
||
// Replace these with the actual paths to your directories | ||
const dir1 = path.resolve('lib/templates'); | ||
const dir2 = path.resolve('src/templates'); | ||
|
||
compareDirectories(dir1, dir2); | ||
if (!result) { | ||
process.exit(1); | ||
} |
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 |
---|---|---|
|
@@ -193,6 +193,12 @@ export abstract class BaseGenerator< | |
* @param partialPath the relative path from the templates folder to templates root folder. | ||
*/ | ||
public sourceRootWithPartialPath(partialPath: string): void { | ||
/** | ||
* CAUTION: | ||
* PLEASE make sure the relative path from this function to /templates does NOT change! | ||
* The core VSCode extension bundles /templates separately, so the change of the relative path will make bundling fail! | ||
* Reach out to [email protected] if unsure. | ||
*/ | ||
this.builtInTemplatesRootPath = path.join( | ||
__dirname, | ||
'..', | ||
|