Make it pretty
This commit is contained in:
parent
0f48dc8132
commit
9efe41090e
1 changed files with 19 additions and 15 deletions
34
index.ts
34
index.ts
|
@ -14,8 +14,6 @@ interface Account {
|
||||||
link: string;
|
link: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const BUILD_DIR = join(__dirname, 'build');
|
const BUILD_DIR = join(__dirname, 'build');
|
||||||
const SRC_DIR = join(__dirname, 'src');
|
const SRC_DIR = join(__dirname, 'src');
|
||||||
const PROGRESS_BAR_FORMAT = '[:bar] :rate/ps :percent :current/:total';
|
const PROGRESS_BAR_FORMAT = '[:bar] :rate/ps :percent :current/:total';
|
||||||
|
@ -30,16 +28,19 @@ const BUNDLER_OPTIONS = {
|
||||||
};
|
};
|
||||||
|
|
||||||
function readAccounts(): ReadonlyArray<Account> {
|
function readAccounts(): ReadonlyArray<Account> {
|
||||||
const rawAccounts: Object = jsyaml.safeLoad(readFileSync(join(__dirname, 'accounts.yml')).toString());
|
const rawAccounts: Object = jsyaml.safeLoad(
|
||||||
return Object.values(mapObject(rawAccounts, (val, key) => {
|
readFileSync(join(__dirname, 'accounts.yml')).toString()
|
||||||
return {
|
);
|
||||||
...val,
|
return Object.values(
|
||||||
name: key
|
mapObject(rawAccounts, (val, key) => {
|
||||||
};
|
return {
|
||||||
}));
|
...val,
|
||||||
|
name: key,
|
||||||
|
};
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function statusOutput(message: string) {
|
function statusOutput(message: string) {
|
||||||
console.log('> ' + message + '...');
|
console.log('> ' + message + '...');
|
||||||
}
|
}
|
||||||
|
@ -61,7 +62,7 @@ function writeTemplate(
|
||||||
(async function() {
|
(async function() {
|
||||||
rimraf.sync(BUILD_DIR);
|
rimraf.sync(BUILD_DIR);
|
||||||
|
|
||||||
statusOutput("Reading accounts")
|
statusOutput('Reading accounts');
|
||||||
const accounts = readAccounts();
|
const accounts = readAccounts();
|
||||||
|
|
||||||
statusOutput('Creating template');
|
statusOutput('Creating template');
|
||||||
|
@ -69,7 +70,10 @@ function writeTemplate(
|
||||||
await bundler.bundle();
|
await bundler.bundle();
|
||||||
|
|
||||||
statusOutput('Compiling HTML template');
|
statusOutput('Compiling HTML template');
|
||||||
Handlebars.registerPartial('accounts', readFileSync(join(SRC_DIR, 'accounts.html')).toString());
|
Handlebars.registerPartial(
|
||||||
|
'accounts',
|
||||||
|
readFileSync(join(SRC_DIR, 'accounts.html')).toString()
|
||||||
|
);
|
||||||
const template = Handlebars.compile(
|
const template = Handlebars.compile(
|
||||||
readFileSync(join(BUILD_DIR, 'template.html')).toString()
|
readFileSync(join(BUILD_DIR, 'template.html')).toString()
|
||||||
);
|
);
|
||||||
|
@ -81,7 +85,7 @@ function writeTemplate(
|
||||||
});
|
});
|
||||||
|
|
||||||
const baseContext = {
|
const baseContext = {
|
||||||
accounts
|
accounts,
|
||||||
};
|
};
|
||||||
|
|
||||||
statusOutput('Generating pages');
|
statusOutput('Generating pages');
|
||||||
|
@ -102,7 +106,7 @@ function writeTemplate(
|
||||||
}
|
}
|
||||||
bar.tick();
|
bar.tick();
|
||||||
});
|
});
|
||||||
writeTemplate(template, '', {...baseContext, value: ''});
|
writeTemplate(template, '', { ...baseContext, value: '' });
|
||||||
const filesOutput = glob.sync(join(BUILD_DIR, "**/index.html")).length;
|
const filesOutput = glob.sync(join(BUILD_DIR, '**/index.html')).length;
|
||||||
console.log(`Generated ${filesOutput} files.`);
|
console.log(`Generated ${filesOutput} files.`);
|
||||||
})();
|
})();
|
||||||
|
|
Reference in a new issue