-
Notifications
You must be signed in to change notification settings - Fork 24
Thank you page addition #104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pratyushtiwary
wants to merge
9
commits into
techrail:main
Choose a base branch
from
pratyushtiwary:thankYouPageAddition
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
674eafe
Added thank you page
pratyushtiwary a1252a4
Fixed a grammatical mistake
pratyushtiwary c824ced
Added page header to thank you page
pratyushtiwary ff64029
Merge branch 'main' into thankYouPageAddition
pratyushtiwary dca1f06
Update routes.js
pratyushtiwary 3bf09cf
Renamed file
pratyushtiwary a6069eb
Merge branch 'thankYouPageAddition' of https://github.com/pratyushtiw…
pratyushtiwary f8ba690
Dependencies list is now generated only at build time
pratyushtiwary d85bb6a
Merge branch 'main' into thankYouPageAddition
pratyushtiwary File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,161 @@ | ||
| import fs from "fs"; | ||
| import path from "path"; | ||
| import registryURL from "registry-url"; | ||
| import { fileURLToPath } from "url"; | ||
|
|
||
| const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
| const src = path.join(__dirname, "src"), | ||
| pages = path.join(src, "pages"), | ||
| components = path.join(src, "components"), | ||
| stores = path.join(src, "stores"), | ||
| router = path.join(src, "router"), | ||
| utils = path.join(components, "utils"), | ||
| packageJson = path.join(__dirname, "package.json"), | ||
| thankYouPageDir = path.join(pages, "ThankYou"), | ||
| npmRegistryURL = registryURL(); | ||
|
|
||
| const NPMPackageLink = `https://www.npmjs.com/package/`; | ||
|
|
||
| let modules = []; | ||
|
|
||
| /* | ||
| Single module looks like this | ||
| module = { | ||
| "name": string, | ||
| "link": string, | ||
| "description": string, | ||
| "homepage": string | ||
| } | ||
|
|
||
| link here is the npm link to the package | ||
| */ | ||
|
|
||
| async function getPackageDetails(name) { | ||
| try { | ||
| const data = await (await fetch(npmRegistryURL + name)).json(); | ||
|
|
||
| return { | ||
| success: { | ||
| description: data.description, | ||
| homepage: data.homepage, | ||
| }, | ||
| error: false, | ||
| }; | ||
| } catch (e) { | ||
| return { | ||
| success: false, | ||
| error: e, | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| function extractModules(content) { | ||
| const lines = content.split(/\n/g); | ||
|
|
||
| let modules = []; | ||
|
|
||
| let j = 0; | ||
|
|
||
| while (lines[j]) { | ||
| if (lines[j].match("from") || lines[j].startsWith("import")) { | ||
| lines[j] = lines[j] | ||
| .split(/\s/) | ||
| .at(-2) | ||
| .replace(/\"|\'|;/g, ""); | ||
| if (!lines[j].match(/^\.[\/\\\.]*/g)) { | ||
| modules.push(lines[j]); | ||
| } | ||
| } | ||
| j++; | ||
| } | ||
| modules = new Set(modules); | ||
| modules = Array.from(modules); | ||
| return modules; | ||
| } | ||
|
|
||
| function getDirModules(dir) { | ||
| const files = fs.readdirSync(dir); | ||
| let tempModules = []; | ||
|
|
||
| for (let i = 0; i < files.length; i++) { | ||
| if (files[i].match(/\./)) { | ||
| const content = fs.readFileSync(path.join(dir, files[i]), "utf-8"); | ||
| tempModules = new Set([...tempModules, ...extractModules(content)]); | ||
|
|
||
| tempModules = Array.from(tempModules); | ||
| } | ||
| } | ||
| return tempModules; | ||
| } | ||
|
|
||
| function getSrcModules(src) { | ||
| const moduleFolders = fs.readdirSync(src); | ||
| let tempModules = []; | ||
| for (let i = 0; i < moduleFolders.length; i++) { | ||
| tempModules = new Set([ | ||
| ...tempModules, | ||
| ...getDirModules(path.join(src, moduleFolders[i])), | ||
| ]); | ||
|
|
||
| tempModules = Array.from(tempModules); | ||
| } | ||
| return tempModules; | ||
| } | ||
|
|
||
| async function generateDependenciesList() { | ||
| console.log(`Generating list of dependencies for thank you page... 👷♂️`); | ||
| modules = new Set( | ||
| [ | ||
| ...getSrcModules(pages), | ||
| ...getSrcModules(components), | ||
| ...getDirModules(router), | ||
| ...getDirModules(stores), | ||
| ...getDirModules(utils), | ||
| ...getDirModules(src), | ||
| ].map((e) => (e.startsWith("@") ? e : e.split(/[\/\\]/)[0])) | ||
| ); | ||
|
|
||
| modules = Array.from(modules); | ||
|
|
||
| // there are a lot of garbage generated | ||
| // let's clean that now by checking | ||
| // if the module found exists in the package.json file | ||
| const packageJsonContent = JSON.parse(fs.readFileSync(packageJson, "utf-8")); | ||
|
|
||
| const realDependencies = Object.keys(packageJsonContent.dependencies); | ||
|
|
||
| modules = modules.filter((e) => realDependencies.includes(e)); | ||
|
|
||
| for (let i = 0; i < modules.length; i++) { | ||
| let details = await getPackageDetails(modules[i]); | ||
| let final = { | ||
| name: modules[i], | ||
| link: NPMPackageLink + modules[i], | ||
| description: details.success?.description || undefined, | ||
| homepage: details.success?.homepage || undefined, | ||
| }; | ||
| modules[i] = final; | ||
| } | ||
|
|
||
| const dependenciesFile = `const dependencies = ${JSON.stringify( | ||
| modules, | ||
| null, | ||
| 4 | ||
| )}; \n\n export default dependencies;`; | ||
|
|
||
| fs.writeFileSync( | ||
| path.join(thankYouPageDir, "dependencies.js"), | ||
| dependenciesFile, | ||
| "utf-8" | ||
| ); | ||
|
|
||
| console.log(`List of dependencies successfully generated ✨`); | ||
| } | ||
|
|
||
| export default () => ({ | ||
| name: "dependencies-list-generator", | ||
| apply: "build", | ||
| async configResolved() { | ||
| await generateDependenciesList(); | ||
| }, | ||
| }); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is how this file is working:
srcand look for the import statements made,package.json,