Skip to content

Commit

Permalink
UJ: Merged from template.
Browse files Browse the repository at this point in the history
  • Loading branch information
ianwieds committed Jun 18, 2024
2 parents a72425b + 9bb18db commit 0b5ecbe
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 37 deletions.
98 changes: 65 additions & 33 deletions _websrc/gulp_tasks/master/_prefill.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const _configYml = require('js-yaml').load(jetpack.read('_config.yml'));
const del = require('del');
const tools = new (require('../../libraries/tools.js'));
const Global = require('../../libraries/global.js');
const fetch = require('node-fetch');
const fetch = require('wonderful-fetch');
const JSON5 = require('json5');

gulp.task('_prefill', () => {
return new Promise(async (resolve, reject) => {
Expand Down Expand Up @@ -188,55 +189,86 @@ gulp.task('_prefill', () => {
// })

// Get firebase-auth
const urlBase = 'https://ultimate-jekyll.firebaseapp.com'
const firebaseAuthFiles = [
'handler.html',
'handler.js',
'experiments.js',
'iframe.html',
'iframe.js',
{
remote: '__/auth/handler',
},
{
remote: '__/auth/handler.js',
},
{
remote: '__/auth/experiments.js',
},
{
remote: '__/auth/iframe',
},
{
remote: '__/auth/iframe.js',
},
{
remote: '__/firebase/init.json',
custom: 'init',
}
]
const firebaseAuthPrefix = '__/auth';
const firebaseAuthPromises = [];
const firebaseAuthDir = './special/master/scripts/firebase-auth';
const firebaseConfig = eval(`(${_configYml.settings['manager-configuration']})`).libraries.firebase_app.config;

// Clear files
jetpack.remove(firebaseAuthDir);

// Create directory if not on server
if (!tools.isServer) {
await createFile(`${firebaseAuthDir}/.gitignore`, gitignore_ph);
}

for (var i = 0; i < firebaseAuthFiles.length; i++) {
const file = firebaseAuthFiles[i];
const fileNoHTML = file.replace('.html', '');
const remoteFile = `https://ultimate-jekyll.firebaseapp.com/${firebaseAuthPrefix}/${fileNoHTML}`;

// console.log(`Fetching ${remoteFile}`);

firebaseAuthPromises.push(
fetch(remoteFile)
.then(async (res) => {
if (res.ok) {
jetpack.write(`${firebaseAuthDir}/${file}`,
'---\n'
+ `permalink: /${firebaseAuthPrefix}/${fileNoHTML}\n`
+ '---\n'
+ '\n'
+ await res.text()
)
} else {
throw new Error(`Failed to get ${file}`)
}
})
// .catch(e => {
// console.error(e);
// })
)
// Fetch files
for (let i = 0; i < firebaseAuthFiles.length; i++) {
const item = firebaseAuthFiles[i];
const remoteUrl = `${urlBase}/${item.remote}`;
const remote = item.remote;
const name = remoteUrl.split('/').pop();
const dir = `${firebaseAuthDir}/${name}`;
const custom = item.custom || false;

function _write(content) {
jetpack.write(dir,
'---\n'
+ `permalink: /${remote}\n`
+ '---\n'
+ '\n'
+ content
)
}

if (custom === 'init') {
// Write custom content to init.json
_write(JSON.stringify(firebaseConfig, null, 2));
} else {
// Push promise
firebaseAuthPromises.push(
fetch(remoteUrl)
.then(async (res) => {
// Check if response is ok
if (!res.ok) {
throw new Error(`Failed to get ${remoteUrl}`)
}

// Write file
_write(await res.text());
})
)
}
}

// Wait for all promises to resolve
await Promise.all(firebaseAuthPromises);

// Set prefill status
Global.set('prefillStatus', 'done');

// Resolve
return resolve();
} catch (e) {
return reject(e)
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
"sharp": "0.23.1 (sometime before 2021ish): Hard lock because later versions had issues. Possibly solved in higher node versions"
},
"devDependencies": {
"@babel/core": "^7.24.6",
"@babel/preset-env": "^7.24.6",
"@babel/core": "^7.24.7",
"@babel/preset-env": "^7.24.7",
"autoprefixer": "9.8.8",
"browser-sync": "2.23.7",
"del": "6.1.1",
Expand Down Expand Up @@ -88,10 +88,10 @@
"through2": "4.0.2",
"ultimate-jekyll-poster": "1.0.1",
"vinyl-named": "1.1.0",
"web-manager": "3.2.49",
"web-manager": "3.2.50",
"webpack": "5.89.0",
"webpack-stream": "6.1.2",
"wonderful-fetch": "^1.1.9",
"wonderful-fetch": "^1.1.11",
"yargs": "16.2.0",
"zzzzzzzzzz": "9.9.9"
}
Expand Down

0 comments on commit 0b5ecbe

Please sign in to comment.