mirror of
https://github.com/veggiemonk/awesome-docker.git
synced 2025-04-26 10:43:35 +02:00
Merge build scripts
This commit is contained in:
parent
c57cc3d1bf
commit
ce8779ec61
5 changed files with 264 additions and 465 deletions
|
@ -10,10 +10,12 @@ const LOG = {
|
|||
if (process.env.DEBUG) console.log('💡 DEBUG: ', { ...args });
|
||||
},
|
||||
};
|
||||
const handleFailure = err => {
|
||||
LOG.error(err);
|
||||
process.exit(1);
|
||||
};
|
||||
|
||||
process.on('unhandledRejection', error => {
|
||||
LOG.error('unhandledRejection', error.message);
|
||||
});
|
||||
process.on('unhandledRejection', handleFailure);
|
||||
|
||||
if (!process.env.TOKEN) {
|
||||
LOG.error('no credentials found.');
|
||||
|
@ -26,12 +28,11 @@ const DELAY = parseInt(process.env.DELAY, 10) || 3000;
|
|||
const INTERVAL = parseInt(process.env.INTERVAL, 10) || 1;
|
||||
const INTERVAL_UNIT = process.env.INTERVAL_UNIT || 'days';
|
||||
|
||||
// --- FILENAME ---
|
||||
const README = 'README.md';
|
||||
// --- FILES ---
|
||||
const DATA_FOLDER = 'data';
|
||||
const GITHUB_METADATA_FILE = `${DATA_FOLDER}/${dayjs().format(
|
||||
'YYYY-MM-DDTHH.mm.ss',
|
||||
)}-fetched_repo_data.json`;
|
||||
const README = 'README.md';
|
||||
const DATE = dayjs().format('YYYY-MM-DDTHH.mm.ss');
|
||||
const GITHUB_METADATA_FILE = `${DATA_FOLDER}/${DATE}-fetched_repo_data.json`;
|
||||
const LATEST_FILENAME = `${DATA_FOLDER}/latest`;
|
||||
const GITHUB_REPOS = `${DATA_FOLDER}/list_repos.json`;
|
||||
|
||||
|
@ -46,12 +47,8 @@ const options = {
|
|||
},
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
const removeHost = x => x.slice('https://github.com/'.length, x.length);
|
||||
const barLine = console.draft('Starting batch...');
|
||||
const handleFailure = err => {
|
||||
LOG.error(err);
|
||||
process.exit(1);
|
||||
};
|
||||
|
||||
const delay = ms =>
|
||||
new Promise(resolve => {
|
||||
|
@ -59,7 +56,7 @@ const delay = ms =>
|
|||
});
|
||||
|
||||
const get = (pathURL, opt) => {
|
||||
LOG.debug(` Fetching ${pathURL}`);
|
||||
LOG.debug(`Fetching ${pathURL}`);
|
||||
return fetch(`${API}repos/${pathURL}`, {
|
||||
...options,
|
||||
...opt,
|
||||
|
@ -83,11 +80,13 @@ const extractAllRepos = markdown => {
|
|||
const ProgressBar = (i, batchSize, total) => {
|
||||
const progress = Math.round((i / total) * 100);
|
||||
const units = Math.round(progress / 2);
|
||||
const barLine = console.draft('Starting batch...');
|
||||
return barLine(
|
||||
`[${'='.repeat(units)}${' '.repeat(50 - units)}] ${progress}% - # ${i}`,
|
||||
);
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
async function batchFetchRepoMetadata(githubRepos) {
|
||||
const repos = githubRepos.map(removeHost);
|
||||
|
||||
|
@ -127,7 +126,6 @@ function shouldUpdate(lastUpdateTime) {
|
|||
async function main() {
|
||||
try {
|
||||
const lastUpdateTime = await fs.readFile(LATEST_FILENAME, 'utf8');
|
||||
|
||||
LOG.debug('Checking if updating is needed');
|
||||
if (!shouldUpdate(lastUpdateTime)) {
|
||||
LOG.debug('Last update was less than a day ago 😅. Exiting...');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue