forked from sunstar-engineering/sunstar-engineering
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add framework for using external libs and add jslinq (#63)
* Add framework for using external libs and add jslinq. --------- Co-authored-by: Satya Deep Maheshwari <[email protected]>
- Loading branch information
Showing
12 changed files
with
296 additions
and
2 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,2 +1,3 @@ | ||
helix-importer-ui | ||
blocks/embed/lite-yt-embed.js | ||
ext-libs/** |
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,7 @@ | ||
[ | ||
{ | ||
"name": "jslinq", | ||
"source": "node_modules/jslinq/build", | ||
"target": "ext-libs/jslinq" | ||
} | ||
] |
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,27 @@ | ||
#!/usr/bin/env bash | ||
|
||
for var in GITHUB_SERVER_URL GITHUB_REPOSITORY GITHUB_RUN_ID GITHUB_STEP_SUMMARY GITHUB_ENV DOMAIN_MAIN DOMAIN_BRANCH; do | ||
if [ -z "${!var}" ]; then | ||
echo "WARN: $var is not set. Link to artifacts will not be added." | ||
fi | ||
done | ||
|
||
|
||
npm run compare ./.ext-libs-mapping.json; | ||
|
||
if grep -q "Difference" difference_results.md; then | ||
echo "Diffs found" | ||
export SUMMARY="$(cat difference_results.md)" | ||
|
||
echo "$SUMMARY" >> "$GITHUB_STEP_SUMMARY" | ||
|
||
# using multi-line-vars from https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#example-of-a-multiline-string | ||
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) | ||
echo "SUMMARY<<$EOF" >> "$GITHUB_ENV" | ||
echo "$SUMMARY" >> "$GITHUB_ENV" | ||
echo "$EOF" >> "$GITHUB_ENV" | ||
else | ||
echo "No diffs found" | ||
cat difference_results.md >> "$GITHUB_STEP_SUMMARY" | ||
echo "SUMMARY=" >> "$GITHUB_ENV" | ||
fi |
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,35 @@ | ||
name: Compare Folders | ||
|
||
on: | ||
pull_request: | ||
types: [ opened, synchronize ] | ||
|
||
jobs: | ||
compare-folders: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: . | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18 | ||
|
||
- name: Install dependencies | ||
run: npm ci | ||
|
||
- name: Compare folders | ||
id: run-compare | ||
run: | | ||
./.github/folder-compare/run-and-create-github-summary.bash | ||
cat difference_results.md | ||
- name: Comment on Pull Request | ||
if: env.SUMMARY != '' | ||
uses: peter-evans/create-or-update-comment@v3 | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
issue-number: ${{ github.event.number }} | ||
body: ${{ env.SUMMARY }} | ||
|
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,72 @@ | ||
/* eslint-disable no-console */ | ||
const fs = require('fs'); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
const path = require('path'); | ||
const process = require('process'); | ||
|
||
function isDifferent(folder1, folder2) { | ||
let different = false; | ||
const entries1 = fs.readdirSync(folder1); | ||
const entries2 = fs.readdirSync(folder2); | ||
|
||
// Check if the number of entries is different | ||
if (entries1.length !== entries2.length) { | ||
return true; | ||
} | ||
|
||
// Check if the names of entries are different | ||
const sortedEntries1 = entries1.sort(); | ||
const sortedEntries2 = entries2.sort(); | ||
for (let i = 0; i < sortedEntries1.length; i += 1) { | ||
if (sortedEntries1[i] !== sortedEntries2[i]) { | ||
return true; | ||
} | ||
} | ||
|
||
for (let i = 0; i < sortedEntries1.length; i += 1) { | ||
const filePath1 = path.join(folder1, sortedEntries1[i]); | ||
const filePath2 = path.join(folder2, sortedEntries1[i]); | ||
|
||
if (fs.statSync(filePath1).isFile() && fs.statSync(filePath2).isFile()) { | ||
const content1 = fs.readFileSync(filePath1, 'utf8'); | ||
const content2 = fs.readFileSync(filePath2, 'utf8'); | ||
|
||
if (content1 !== content2) { | ||
different = true; | ||
} | ||
} else if (fs.statSync(filePath1).isDirectory() && fs.statSync(filePath2).isDirectory()) { | ||
different = isDifferent(filePath1, filePath2); | ||
} else { | ||
different = true; | ||
} | ||
if (different) { break; } | ||
} | ||
return different; | ||
} | ||
try { | ||
const mappingFilePath = process.argv[2]; | ||
if (!mappingFilePath) { | ||
console.error('Please provide the path to the config JSON file as a command line argument.'); | ||
process.exit(1); | ||
} | ||
const mappings = JSON.parse(fs.readFileSync(mappingFilePath, 'utf8')); | ||
const comparisonResults = []; | ||
|
||
mappings.forEach((mapping) => { | ||
const result = isDifferent(mapping.source, mapping.target); | ||
if (result) { | ||
comparisonResults.push(`### :small_orange_diamond: Difference detected between \`${mapping.source}\` and \`${mapping.target}\` | ||
\n#### Execute this to fix the difference: \n \`npm run copy ${mapping.source} ext-libs ${mapping.target.split('/').pop()}\`\n`); | ||
} | ||
}); | ||
|
||
if (comparisonResults.length > 0) { | ||
fs.writeFileSync('difference_results.md', comparisonResults.join('\n')); | ||
console.log('Comparison results have been written to difference_results.md'); | ||
} else { | ||
fs.writeFileSync('difference_results.md', '### :tada: No external libs differences detected :tada:'); | ||
console.log('No differences detected'); | ||
} | ||
} catch (error) { | ||
fs.writeFileSync('difference_results.md', 'Error reading or processing the JSON file'); | ||
console.error('Error reading or processing the JSON file:', error.message); | ||
} |
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,35 @@ | ||
/* eslint-disable no-console */ | ||
const fs = require('fs-extra'); | ||
const path = require('path'); | ||
|
||
// Get source and target directory paths from command line arguments | ||
const sourceDir = process.argv[2]; | ||
const targetDir = process.argv[3]; | ||
const copiedFolderName = process.argv[4] || path.basename(sourceDir); | ||
|
||
if (!sourceDir || !targetDir) { | ||
console.error('Usage: npm run copy <source-directory> <target-directory> [copied-folder-name]'); | ||
process.exit(1); | ||
} | ||
|
||
// Ensure that the target directory exists | ||
fs.ensureDirSync(targetDir); | ||
|
||
// Construct the path to the target directory including the specified copied folder name | ||
const targetPath = require('path').join(targetDir, copiedFolderName); | ||
|
||
// Check if the target folder already exists | ||
if (fs.existsSync(targetPath)) { | ||
// If it exists, remove it | ||
fs.removeSync(targetPath); | ||
console.log(`Removed existing folder '${targetPath}'.`); | ||
} | ||
|
||
// Perform the folder copy operation (recursively) | ||
try { | ||
fs.copySync(sourceDir, targetPath, { recursive: true }); | ||
console.log(`Folder '${sourceDir}' copied to '${targetPath}' successfully.`); | ||
} catch (error) { | ||
console.error('Error copying folder:', error); | ||
process.exit(1); | ||
} |
why not import ??