-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Merge branch 'main' of https://github.com/affinidi/reference-app…
…-affinidi-vault into paramesh
- Loading branch information
Showing
67 changed files
with
3,128 additions
and
330 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
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,13 @@ | ||
{ | ||
"overrides": [ | ||
{ | ||
"files": ["generate.mjs", "confirm.mjs"], | ||
"options": { | ||
"printWidth": 120, | ||
"semi": false, | ||
"singleQuote": true, | ||
"trailingComma": "all" | ||
} | ||
} | ||
] | ||
} |
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,16 @@ | ||
import inquirer from 'inquirer' | ||
|
||
const { confirmed } = await inquirer.prompt([ | ||
{ | ||
default: true, | ||
name: 'confirmed', | ||
message: 'This will overwrite any changes made to the samples directory. Are you sure?', | ||
type: 'confirm', | ||
}, | ||
]) | ||
|
||
if (confirmed) { | ||
process.exit(0) | ||
} else { | ||
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 |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import fs from 'fs/promises' | ||
import { dirname, join, basename } from 'path' | ||
import url from 'url' | ||
import mkdirp from 'mkdirp' | ||
import rimraf from 'rimraf' | ||
import { generateAppInformation } from '../generateAppInformation.mjs' | ||
|
||
const filesToIgnore = ['.next', '.env', 'generator-config.json', '.gitkeep', 'keys', 'appInformation.json'] | ||
const pathsToOverwrite = [] | ||
|
||
const __dirname = dirname(url.fileURLToPath(import.meta.url)) | ||
|
||
async function generate() { | ||
await generateAppInformation() | ||
const rootPath = join(__dirname, '../..') | ||
const samplesPath = join(rootPath, 'samples') | ||
const generatorPath = join(rootPath, 'generator') | ||
const fastapiPath = join(generatorPath, 'fastapi') | ||
const overridesPath = join(fastapiPath, 'overrides') | ||
const templatePath = join(fastapiPath, 'template') | ||
|
||
const overrides = (await fs.readdir(overridesPath, { withFileTypes: true })) | ||
.filter((i) => i.isDirectory()) | ||
.map((i) => i.name) | ||
.sort() | ||
|
||
console.log(`Detected samples: ${overrides.join(', ')}`) | ||
|
||
for (const [i, sample] of overrides.entries()) { | ||
console.log(`\nGenerating "${sample}" sample`) | ||
|
||
const overridePath = join(overridesPath, sample) | ||
const samplePath = join(samplesPath, sample) | ||
|
||
let generatorConfig = {} | ||
try { | ||
generatorConfig = JSON.parse( | ||
await fs.readFile(join(overridePath, 'generator-config.json'), { | ||
encoding: 'utf-8', | ||
}), | ||
) | ||
} catch (error) { | ||
if (error.code !== 'ENOENT') { | ||
throw error | ||
} | ||
} | ||
|
||
console.log('Copying the template') | ||
const pathsToDelete = (await fs.readdir(samplePath).catch(() => [])) | ||
.filter((file) => !filesToIgnore.includes(file)) | ||
.map((file) => join(samplePath, file)) | ||
await deletePath(pathsToDelete) | ||
await merge(templatePath, samplePath, { | ||
filter: (path) => !filesToIgnore.includes(basename(path)), | ||
}) | ||
|
||
for (const path of pathsToOverwrite) { | ||
if (await exists(join(overridePath, ...path))) { | ||
console.log(`Deleting "${path.join('/')}" path from the template`) | ||
await deletePath(join(samplePath, ...path)) | ||
} | ||
} | ||
|
||
console.log(`Applying overrides`) | ||
await merge(overridePath, samplePath, { | ||
filter: (path) => !filesToIgnore.includes(basename(path)), | ||
}) | ||
|
||
const envPath = join(samplePath, '.env') | ||
if (!(await exists(envPath))) { | ||
await fs.cp(join(samplePath, '.env.example'), envPath) | ||
} | ||
} | ||
} | ||
|
||
async function merge(from, to, options) { | ||
await mkdirp(join(to, '..')) | ||
|
||
try { | ||
await fs.cp(from, to, { recursive: true, ...options }) | ||
} catch (error) { | ||
if (error.code === 'ENOENT') { | ||
console.warn(`Warning: Source doesn't exist: ${from}`) | ||
} else { | ||
throw error | ||
} | ||
} | ||
} | ||
|
||
async function deletePath(path) { | ||
await rimraf(path) | ||
} | ||
|
||
async function exists(path) { | ||
try { | ||
await fs.access(path) | ||
return true | ||
} catch { | ||
return false | ||
} | ||
} | ||
|
||
generate() | ||
.catch((error) => { | ||
console.error(error) | ||
process.exit(1) | ||
}) | ||
.then(() => { | ||
console.log('\nDone!') | ||
process.exit(0) | ||
}) |
Empty file.
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,4 @@ | ||
PROVIDER_CLIENT_ID="" | ||
PROVIDER_CLIENT_SECRET="" | ||
PROVIDER_ISSUER="" | ||
FASTAPI_SECRET="this-is-very-secret-dont-tell-anyone" |
Oops, something went wrong.