mirror of
https://github.com/dilllxd/gitfolio.git
synced 2024-08-14 22:28:09 +00:00
Fix some mistakes and use xo
This commit is contained in:
parent
b7a21d8bd7
commit
957ada3ea7
14 changed files with 4316 additions and 560 deletions
|
@ -1,18 +0,0 @@
|
||||||
{
|
|
||||||
"env": {
|
|
||||||
"browser": true,
|
|
||||||
"es6": true,
|
|
||||||
"node": true
|
|
||||||
},
|
|
||||||
"extends": "eslint:recommended",
|
|
||||||
"globals": {
|
|
||||||
"Atomics": "readonly",
|
|
||||||
"SharedArrayBuffer": "readonly"
|
|
||||||
},
|
|
||||||
"parserOptions": {
|
|
||||||
"ecmaVersion": 2018,
|
|
||||||
"sourceType": "module"
|
|
||||||
},
|
|
||||||
"rules": {
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,4 +1,5 @@
|
||||||
{
|
{
|
||||||
|
"singleQuote": false,
|
||||||
"overrides": [
|
"overrides": [
|
||||||
{
|
{
|
||||||
"files": ["*.html", "*.ejs"],
|
"files": ["*.html", "*.ejs"],
|
||||||
|
|
|
@ -2,3 +2,4 @@
|
||||||
[![Dependency Status](https://img.shields.io/david/k4ustu3h/gitfolio?style=for-the-badge)](https://david-dm.org/k4ustu3h/gitfolio)
|
[![Dependency Status](https://img.shields.io/david/k4ustu3h/gitfolio?style=for-the-badge)](https://david-dm.org/k4ustu3h/gitfolio)
|
||||||
[![devDependencies Status](https://img.shields.io/david/dev/k4ustu3h/gitfolio?style=for-the-badge)](https://david-dm.org/k4ustu3h/gitfolio?type=dev)
|
[![devDependencies Status](https://img.shields.io/david/dev/k4ustu3h/gitfolio?style=for-the-badge)](https://david-dm.org/k4ustu3h/gitfolio?type=dev)
|
||||||
[![Code Style: Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=for-the-badge)](https://github.com/prettier/prettier)
|
[![Code Style: Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=for-the-badge)](https://github.com/prettier/prettier)
|
||||||
|
[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg?style=for-the-badge)](https://github.com/xojs/xo)
|
||||||
|
|
77
api.js
77
api.js
|
@ -10,45 +10,46 @@ const got = require("got");
|
||||||
* @param {'desc' | 'asc'} [opts.order]
|
* @param {'desc' | 'asc'} [opts.order]
|
||||||
*/
|
*/
|
||||||
async function getRepos(username, opts = {}) {
|
async function getRepos(username, opts = {}) {
|
||||||
let tempRepos;
|
let tempRepos;
|
||||||
let page = 1;
|
let page = 1;
|
||||||
let repos = [];
|
let repos = [];
|
||||||
|
|
||||||
const sort = opts.sort;
|
const {sort} = opts;
|
||||||
const order = opts.order || (sort === "full_name" ? "asc" : "desc");
|
const order = opts.order || (sort === "full_name" ? "asc" : "desc");
|
||||||
const types = opts.types || [];
|
const types = opts.types || [];
|
||||||
let type = "all";
|
let type = "all";
|
||||||
|
|
||||||
if (
|
if (
|
||||||
types.includes("all") ||
|
types.includes("all") ||
|
||||||
(types.includes("owner") && types.includes("member"))
|
(types.includes("owner") && types.includes("member"))
|
||||||
) {
|
) {
|
||||||
type = "all";
|
type = "all";
|
||||||
} else if (types.includes("member")) {
|
} else if (types.includes("member")) {
|
||||||
type = "member";
|
type = "member";
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
let requestUrl = `https://api.github.com/users/${username}/repos?per_page=100&page=${page++}&type=${type}`;
|
let requestUrl = `https://api.github.com/users/${username}/repos?per_page=100&page=${page++}&type=${type}`;
|
||||||
if (sort && sort !== "star") {
|
if (sort && sort !== "star") {
|
||||||
requestUrl += `&sort=${sort}&direction=${order}`;
|
requestUrl += `&sort=${sort}&direction=${order}`;
|
||||||
}
|
}
|
||||||
tempRepos = await got(requestUrl);
|
|
||||||
tempRepos = JSON.parse(tempRepos.body);
|
|
||||||
repos = repos.concat(tempRepos);
|
|
||||||
} while (tempRepos.length == 100);
|
|
||||||
|
|
||||||
if (sort == "star") {
|
tempRepos = await got(requestUrl);
|
||||||
repos = repos.sort(function(a, b) {
|
tempRepos = JSON.parse(tempRepos.body);
|
||||||
if (order == "desc") {
|
repos = repos.concat(tempRepos);
|
||||||
return b.stargazers_count - a.stargazers_count;
|
} while (tempRepos.length === 100);
|
||||||
} else {
|
|
||||||
return a.stargazers_count - b.stargazers_count;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return repos;
|
if (sort === "star") {
|
||||||
|
repos = repos.sort((a, b) => {
|
||||||
|
if (order === "desc") {
|
||||||
|
return b.stargazers_count - a.stargazers_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
return a.stargazers_count - b.stargazers_count;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return repos;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -56,11 +57,11 @@ async function getRepos(username, opts = {}) {
|
||||||
* @param {string} username
|
* @param {string} username
|
||||||
*/
|
*/
|
||||||
async function getUser(username) {
|
async function getUser(username) {
|
||||||
const res = await got(`https://api.github.com/users/${username}`);
|
const res = await got(`https://api.github.com/users/${username}`);
|
||||||
return JSON.parse(res.body);
|
return JSON.parse(res.body);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getRepos,
|
getRepos,
|
||||||
getUser
|
getUser
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,42 +1,42 @@
|
||||||
importScripts(
|
importScripts(
|
||||||
"https://storage.googleapis.com/workbox-cdn/releases/3.6.1/workbox-sw.js"
|
"https://storage.googleapis.com/workbox-cdn/releases/3.6.1/workbox-sw.js"
|
||||||
);
|
);
|
||||||
|
|
||||||
if (workbox) {
|
if (workbox) {
|
||||||
workbox.setConfig({
|
workbox.setConfig({
|
||||||
debug: false
|
debug: false
|
||||||
});
|
});
|
||||||
|
|
||||||
var defaultStrategy = workbox.strategies.networkFirst({
|
const defaultStrategy = workbox.strategies.networkFirst({
|
||||||
cacheName: "fallback",
|
cacheName: "fallback",
|
||||||
plugins: [
|
plugins: [
|
||||||
new workbox.expiration.Plugin({
|
new workbox.expiration.Plugin({
|
||||||
maxEntries: 128,
|
maxEntries: 128,
|
||||||
maxAgeSeconds: 7 * 24 * 60 * 60, // 1 week
|
maxAgeSeconds: 7 * 24 * 60 * 60, // 1 week
|
||||||
purgeOnQuotaError: true // Opt-in to automatic cleanup
|
purgeOnQuotaError: true // Opt-in to automatic cleanup
|
||||||
}),
|
}),
|
||||||
new workbox.cacheableResponse.Plugin({
|
new workbox.cacheableResponse.Plugin({
|
||||||
statuses: [0, 200] // for opague requests
|
statuses: [0, 200] // For opague requests
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
workbox.routing.setDefaultHandler(args => {
|
workbox.routing.setDefaultHandler(args => {
|
||||||
if (args.event.request.method === "GET") {
|
if (args.event.request.method === "GET") {
|
||||||
return defaultStrategy.handle(args); // use default strategy
|
return defaultStrategy.handle(args); // Use default strategy
|
||||||
} else {
|
}
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
workbox.routing.registerRoute(
|
return null;
|
||||||
new RegExp(/.*\.(?:js|css)/g),
|
});
|
||||||
workbox.strategies.networkFirst()
|
|
||||||
);
|
|
||||||
|
|
||||||
workbox.routing.registerRoute(
|
workbox.routing.registerRoute(
|
||||||
new RegExp(/.*\.(?:png|jpg|jpeg|svg|gif|webp)/g),
|
new RegExp(/.*\.(?:js|css)/g),
|
||||||
workbox.strategies.cacheFirst()
|
workbox.strategies.networkFirst()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
workbox.routing.registerRoute(
|
||||||
|
new RegExp(/.*\.(?:png|jpg|jpeg|svg|gif|webp)/g),
|
||||||
|
workbox.strategies.cacheFirst()
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
console.log(`No workbox on this browser 😬`);
|
console.log("No workbox on this browser 😬");
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,56 +5,63 @@ const program = require("commander");
|
||||||
|
|
||||||
process.env.OUT_DIR = process.env.OUT_DIR || process.cwd();
|
process.env.OUT_DIR = process.env.OUT_DIR || process.cwd();
|
||||||
|
|
||||||
const { buildCommand } = require("../build");
|
const {buildCommand} = require("../build");
|
||||||
const { updateCommand } = require("../update");
|
const {updateCommand} = require("../update");
|
||||||
const { uiCommand } = require("../ui");
|
const {uiCommand} = require("../ui");
|
||||||
const { runCommand } = require("../run");
|
const {runCommand} = require("../run");
|
||||||
const { version } = require("../package.json");
|
const {version} = require("../package.json");
|
||||||
|
|
||||||
function collect(val, memo) {
|
function collect(val, memo) {
|
||||||
memo.push(val);
|
memo.push(val);
|
||||||
return memo;
|
return memo;
|
||||||
}
|
}
|
||||||
|
|
||||||
program
|
program
|
||||||
.command("build <username>")
|
.command("build <username>")
|
||||||
.description(
|
.description(
|
||||||
"Build site with your GitHub username. This will be used to customize your site"
|
"Build site with your GitHub username. This will be used to customize your site"
|
||||||
)
|
)
|
||||||
.option("-t, --theme [theme]", "specify a theme to use", "light")
|
.option("-t, --theme [theme]", "specify a theme to use", "light")
|
||||||
.option("-b, --background [background]", "set the background image")
|
.option("-b, --background [background]", "set the background image")
|
||||||
.option("-f, --fork", "includes forks with repos")
|
.option("-f, --fork", "includes forks with repos")
|
||||||
.option("-s, --sort [sort]", "set default sort for repository", "created")
|
.option("-s, --sort [sort]", "set default sort for repository", "created")
|
||||||
.option("-o, --order [order]", "set default order on sort", "asc")
|
.option("-o, --order [order]", "set default order on sort", "asc")
|
||||||
.option("-c, --codepen [username]", "specify codepen username")
|
.option("-c, --codepen [username]", "specify codepen username")
|
||||||
.option("-d, --dev [username]", "specify dev username")
|
.option("-d, --dev [username]", "specify dev username")
|
||||||
.option("-D, --dribbble [username]", "specify dribbble username")
|
.option("-D, --dribbble [username]", "specify dribbble username")
|
||||||
.option("-e, --email [username]", "specify email")
|
.option("-e, --email [username]", "specify email")
|
||||||
.option("-i, --instagram [username]", "specify instagram username")
|
.option("-i, --instagram [username]", "specify instagram username")
|
||||||
.option("-r, --reddit [username]", "specify reddit username")
|
.option("-r, --reddit [username]", "specify reddit username")
|
||||||
.option("-T, --telegram [username]", "specify telegram username")
|
.option("-T, --telegram [username]", "specify telegram username")
|
||||||
.option("-w, --twitter [username]", "specify twitter username")
|
.option("-w, --twitter [username]", "specify twitter username")
|
||||||
.action(buildCommand);
|
.action(buildCommand);
|
||||||
|
|
||||||
program
|
program
|
||||||
.command("update")
|
.command("update")
|
||||||
.description("Update user and repository data")
|
.description("Update user and repository data")
|
||||||
.action(updateCommand);
|
.action(updateCommand);
|
||||||
|
|
||||||
program
|
program
|
||||||
.command("run")
|
.command("ui")
|
||||||
.description("Run build files")
|
.description("Create and Manage gitfolio with ease")
|
||||||
.option("-p, --port [port]", "provide a port for localhost, default is 3000")
|
.action(uiCommand);
|
||||||
.action(runCommand);
|
|
||||||
|
program
|
||||||
|
.command("run")
|
||||||
|
.description("Run build files")
|
||||||
|
.option("-p, --port [port]", "provide a port for localhost, default is 3000")
|
||||||
|
.action(runCommand);
|
||||||
|
|
||||||
program.on("command:*", () => {
|
program.on("command:*", () => {
|
||||||
console.log("Unknown Command: " + program.args.join(" "));
|
console.log("Unknown Command: " + program.args.join(" "));
|
||||||
program.help();
|
program.help();
|
||||||
});
|
});
|
||||||
|
|
||||||
program
|
program
|
||||||
.version(version, "-v --version")
|
.version(version, "-v --version")
|
||||||
.usage("<command> [options]")
|
.usage("<command> [options]")
|
||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
|
|
||||||
if (program.args.length === 0) program.help();
|
if (program.args.length === 0) {
|
||||||
|
program.help();
|
||||||
|
}
|
||||||
|
|
129
build.js
129
build.js
|
@ -6,8 +6,8 @@ const hbs = require("handlebars");
|
||||||
/* Creates promise-returning async functions
|
/* Creates promise-returning async functions
|
||||||
from callback-passed async functions */
|
from callback-passed async functions */
|
||||||
const fs = bluebird.promisifyAll(require("fs"));
|
const fs = bluebird.promisifyAll(require("fs"));
|
||||||
const { updateHTML } = require("./populate");
|
const {updateHTML} = require("./populate");
|
||||||
const { getConfig, outDir } = require("./utils");
|
const {getConfig, outDir} = require("./utils");
|
||||||
|
|
||||||
const assetDir = path.resolve(`${__dirname}/assets/`);
|
const assetDir = path.resolve(`${__dirname}/assets/`);
|
||||||
const config = path.join(outDir, "config.json");
|
const config = path.join(outDir, "config.json");
|
||||||
|
@ -19,80 +19,83 @@ const config = path.join(outDir, "config.json");
|
||||||
* arguments.
|
* arguments.
|
||||||
*/
|
*/
|
||||||
async function populateCSS({
|
async function populateCSS({
|
||||||
theme = "light",
|
theme = "light",
|
||||||
background = "https://source.unsplash.com/1280x720/?wallpaper"
|
background = "https://source.unsplash.com/1280x720/?wallpaper"
|
||||||
} = {}) {
|
} = {}) {
|
||||||
/* Get the theme the user requests. Defaults to 'light' */
|
/* Get the theme the user requests. Defaults to 'light' */
|
||||||
theme = `${theme}.css`;
|
theme = `${theme}.css`;
|
||||||
let template = path.resolve(assetDir, "index.css");
|
const template = path.resolve(assetDir, "index.css");
|
||||||
let stylesheet = path.join(outDir, "index.css");
|
const stylesheet = path.join(outDir, "index.css");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await fs.accessAsync(outDir, fs.constants.F_OK);
|
await fs.accessAsync(outDir, fs.constants.F_OK);
|
||||||
} catch (err) {
|
} catch (error) {
|
||||||
await fs.mkdirAsync(outDir);
|
await fs.mkdirAsync(outDir);
|
||||||
}
|
}
|
||||||
/* Copy over the template CSS stylesheet */
|
|
||||||
await fs.copyFileAsync(template, stylesheet);
|
|
||||||
|
|
||||||
/* Get an array of every available theme */
|
/* Copy over the template CSS stylesheet */
|
||||||
let themes = await fs.readdirAsync(path.join(assetDir, "themes"));
|
await fs.copyFileAsync(template, stylesheet);
|
||||||
|
|
||||||
if (!themes.includes(theme)) {
|
/* Get an array of every available theme */
|
||||||
console.error('Error: Requested theme not found. Defaulting to "light".');
|
const themes = await fs.readdirAsync(path.join(assetDir, "themes"));
|
||||||
theme = "light";
|
|
||||||
}
|
|
||||||
/* Read in the theme stylesheet */
|
|
||||||
let themeSource = await fs.readFileSync(path.join(assetDir, "themes", theme));
|
|
||||||
themeSource = themeSource.toString("utf-8");
|
|
||||||
let themeTemplate = hbs.compile(themeSource);
|
|
||||||
let styles = themeTemplate({
|
|
||||||
background: `${background}`
|
|
||||||
});
|
|
||||||
/* Add the user-specified styles to the new stylesheet */
|
|
||||||
await fs.appendFileAsync(stylesheet, styles);
|
|
||||||
|
|
||||||
/* Update the config file with the user's theme choice */
|
if (!themes.includes(theme)) {
|
||||||
const data = await getConfig();
|
console.error('Error: Requested theme not found. Defaulting to "light".');
|
||||||
data[0].theme = theme;
|
theme = "light";
|
||||||
await fs.writeFileAsync(config, JSON.stringify(data, null, " "));
|
}
|
||||||
|
|
||||||
|
/* Read in the theme stylesheet */
|
||||||
|
let themeSource = await fs.readFileSync(path.join(assetDir, "themes", theme));
|
||||||
|
themeSource = themeSource.toString("utf-8");
|
||||||
|
const themeTemplate = hbs.compile(themeSource);
|
||||||
|
const styles = themeTemplate({
|
||||||
|
background: `${background}`
|
||||||
|
});
|
||||||
|
/* Add the user-specified styles to the new stylesheet */
|
||||||
|
await fs.appendFileAsync(stylesheet, styles);
|
||||||
|
|
||||||
|
/* Update the config file with the user's theme choice */
|
||||||
|
const data = await getConfig();
|
||||||
|
data[0].theme = theme;
|
||||||
|
await fs.writeFileAsync(config, JSON.stringify(data, null, " "));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function populateConfig(opts) {
|
async function populateConfig(opts) {
|
||||||
const data = await getConfig();
|
const data = await getConfig();
|
||||||
Object.assign(data[0], opts);
|
Object.assign(data[0], opts);
|
||||||
await fs.writeFileAsync(config, JSON.stringify(data, null, " "));
|
await fs.writeFileAsync(config, JSON.stringify(data, null, " "));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function buildCommand(username, program) {
|
async function buildCommand(username, program) {
|
||||||
await populateCSS(program);
|
await populateCSS(program);
|
||||||
let types;
|
let types;
|
||||||
if (!program.include || !program.include.length) {
|
if (!program.include || !program.include.length) {
|
||||||
types = ["all"];
|
types = ["all"];
|
||||||
} else {
|
} else {
|
||||||
types = program.include;
|
types = program.include;
|
||||||
}
|
}
|
||||||
const opts = {
|
|
||||||
sort: program.sort,
|
|
||||||
order: program.order,
|
|
||||||
includeFork: program.fork ? true : false,
|
|
||||||
types,
|
|
||||||
codepen: program.codepen,
|
|
||||||
dev: program.dev,
|
|
||||||
dribbble: program.dribbble,
|
|
||||||
email: program.email,
|
|
||||||
instagram: program.instagram,
|
|
||||||
reddit: program.reddit,
|
|
||||||
telegram: program.telegram,
|
|
||||||
twitter: program.twitter
|
|
||||||
};
|
|
||||||
|
|
||||||
await populateConfig(opts);
|
const opts = {
|
||||||
updateHTML(("%s", username), opts);
|
sort: program.sort,
|
||||||
|
order: program.order,
|
||||||
|
includeFork: Boolean(program.fork),
|
||||||
|
types,
|
||||||
|
codepen: program.codepen,
|
||||||
|
dev: program.dev,
|
||||||
|
dribbble: program.dribbble,
|
||||||
|
email: program.email,
|
||||||
|
instagram: program.instagram,
|
||||||
|
reddit: program.reddit,
|
||||||
|
telegram: program.telegram,
|
||||||
|
twitter: program.twitter
|
||||||
|
};
|
||||||
|
|
||||||
|
await populateConfig(opts);
|
||||||
|
updateHTML(("%s", username), opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
buildCommand,
|
buildCommand,
|
||||||
populateCSS,
|
populateCSS,
|
||||||
populateConfig
|
populateConfig
|
||||||
};
|
};
|
||||||
|
|
3791
package-lock.json
generated
3791
package-lock.json
generated
File diff suppressed because it is too large
Load diff
146
package.json
146
package.json
|
@ -1,98 +1,52 @@
|
||||||
{
|
{
|
||||||
|
"name": "gitfolio",
|
||||||
"name": "gitfolio",
|
"version": "0.1.5",
|
||||||
|
"description": "a portfolio website for everyone to showcase their work",
|
||||||
"version": "0.1.5",
|
"main": "build.js",
|
||||||
|
"bin": "bin/gitfolio.js",
|
||||||
"description": "a portfolio website for everyone to showcase their work",
|
"scripts": {
|
||||||
|
"cli": "OUT_DIR='./dist' node bin/gitfolio.js",
|
||||||
"main": "build.js",
|
"clean": "rm -rf ./dist/*",
|
||||||
|
"prettier": "prettier --write \"./**/*.{js,jsx,json,html,css,md}\"",
|
||||||
"bin": "bin/gitfolio.js",
|
"test": "xo && OUT_DIR='./dist' node bin/gitfolio.js build k4ustu3h --fork --theme dark --sort updated --twitter k4ustu3h_ --dribbble k4ustu3h --email k4ustu3h@gmail.com --codepen k4ustu3h --dev k4ustu3h --instagram k4ustu3h --telegram k4ustu3h --reddit kaustubhladiya"
|
||||||
|
},
|
||||||
"scripts": {
|
"xo": {
|
||||||
|
"prettier": true
|
||||||
"cli": "OUT_DIR='./dist' node bin/gitfolio.js",
|
},
|
||||||
|
"author": {
|
||||||
"clean": "rm -rf ./dist/*",
|
"name": "@imfunniee and community",
|
||||||
|
"email": "imfunny@wybemf.com",
|
||||||
"prettier": "prettier --write \"./**/*.{js,jsx,json,html,css,md}\"",
|
"url": "https://imfunniee.github.io"
|
||||||
|
},
|
||||||
"test": "OUT_DIR='./dist' node bin/gitfolio.js build k4ustu3h --fork --theme dark --sort updated --twitter k4ustu3h_ --dribbble k4ustu3h --email k4ustu3h@gmail.com --codepen k4ustu3h --dev k4ustu3h --instagram k4ustu3h --telegram k4ustu3h --reddit kaustubhladiya"
|
"bugs": "https://github.com/imfunniee/gitfolio/issues",
|
||||||
|
"homepage": "https://github.com/imfunniee/gitfolio",
|
||||||
},
|
"keywords": [
|
||||||
|
"personal-website",
|
||||||
"author": {
|
"github",
|
||||||
|
"portfolio",
|
||||||
"name": "@imfunniee and community",
|
"portfolio website",
|
||||||
|
"gitfolio",
|
||||||
"email": "imfunny@wybemf.com",
|
"git"
|
||||||
|
],
|
||||||
"url": "https://imfunniee.github.io"
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
},
|
"url": "https://github.com/imfunniee/gitfolio"
|
||||||
|
},
|
||||||
"bugs": "https://github.com/imfunniee/gitfolio/issues",
|
"license": "GPL-3.0",
|
||||||
|
"dependencies": {
|
||||||
"homepage": "https://github.com/imfunniee/gitfolio",
|
"bluebird": "^3.5.4",
|
||||||
|
"body-parser": "^1.19.0",
|
||||||
"keywords": [
|
"commander": "^2.20.0",
|
||||||
|
"ejs": "^2.6.2",
|
||||||
"personal-website",
|
"express": "^4.17.0",
|
||||||
|
"github-emoji": "^1.1.1",
|
||||||
"github",
|
"got": "^9.6.0",
|
||||||
|
"handlebars": "^4.1.2",
|
||||||
"portfolio",
|
"jsdom": "^15.1.0",
|
||||||
|
"ncp": "^2.0.0"
|
||||||
"portfolio website",
|
},
|
||||||
|
"devDependencies": {
|
||||||
"gitfolio",
|
"prettier": "1.19.1",
|
||||||
|
"xo": "^0.25.3"
|
||||||
"git"
|
}
|
||||||
|
|
||||||
],
|
|
||||||
|
|
||||||
"repository": {
|
|
||||||
|
|
||||||
"type": "git",
|
|
||||||
|
|
||||||
"url": "https://github.com/imfunniee/gitfolio"
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
"license": "GPL-3.0",
|
|
||||||
|
|
||||||
"dependencies": {
|
|
||||||
|
|
||||||
"bluebird": "^3.7.2",
|
|
||||||
|
|
||||||
"body-parser": "^1.19.0",
|
|
||||||
|
|
||||||
"commander": "4.0.1",
|
|
||||||
|
|
||||||
"ejs": "3.0.1",
|
|
||||||
|
|
||||||
"express": "^4.17.1",
|
|
||||||
|
|
||||||
"github-emoji": "^1.1.1",
|
|
||||||
|
|
||||||
"got": "10.0.4",
|
|
||||||
|
|
||||||
"handlebars": "^4.5.3",
|
|
||||||
|
|
||||||
"jsdom": "^15.2.1",
|
|
||||||
|
|
||||||
"ncp": "^2.0.0"
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
"devDependencies": {
|
|
||||||
|
|
||||||
"eslint": "^6.7.2",
|
|
||||||
|
|
||||||
"prettier": "1.19.1"
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
316
populate.js
316
populate.js
|
@ -1,106 +1,112 @@
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const emoji = require("github-emoji");
|
const emoji = require("github-emoji");
|
||||||
const jsdom = require("jsdom").JSDOM,
|
const jsdom = require("jsdom").JSDOM;
|
||||||
options = {
|
const options = {
|
||||||
resources: "usable"
|
resources: "usable"
|
||||||
};
|
};
|
||||||
const { getConfig, outDir } = require("./utils");
|
const {getConfig, outDir} = require("./utils");
|
||||||
const { getRepos, getUser } = require("./api");
|
const {getRepos, getUser} = require("./api");
|
||||||
|
|
||||||
function convertToEmoji(text) {
|
function convertToEmoji(text) {
|
||||||
if (text == null) return;
|
if (text === null) {
|
||||||
text = text.toString();
|
return;
|
||||||
var pattern = /(?<=:\s*).*?(?=\s*:)/gs;
|
}
|
||||||
if (text.match(pattern) != null) {
|
|
||||||
var str = text.match(pattern);
|
text = text.toString();
|
||||||
str = str.filter(function(arr) {
|
const pattern = /(?<=:\s*).*?(?=\s*:)/gs;
|
||||||
return /\S/.test(arr);
|
if (text.match(pattern) !== null) {
|
||||||
});
|
let str = text.match(pattern);
|
||||||
for (i = 0; i < str.length; i++) {
|
str = str.filter(arr => {
|
||||||
if (emoji.URLS[str[i]] != undefined) {
|
return /\S/.test(arr);
|
||||||
text = text.replace(
|
});
|
||||||
`:${str[i]}:`,
|
for (i = 0; i < str.length; i++) {
|
||||||
`<img src="${emoji.URLS[str[i]]}" class="emoji">`
|
if (emoji.URLS[str[i]] !== undefined) {
|
||||||
);
|
text = text.replace(
|
||||||
}
|
`:${str[i]}:`,
|
||||||
}
|
`<img src="${emoji.URLS[str[i]]}" class="emoji">`
|
||||||
return text;
|
);
|
||||||
} else {
|
}
|
||||||
return text;
|
}
|
||||||
}
|
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.updateHTML = (username, opts) => {
|
module.exports.updateHTML = (username, opts) => {
|
||||||
const {
|
const {
|
||||||
includeFork,
|
includeFork,
|
||||||
codepen,
|
codepen,
|
||||||
dev,
|
dev,
|
||||||
dribbble,
|
dribbble,
|
||||||
email,
|
email,
|
||||||
instagram,
|
instagram,
|
||||||
reddit,
|
reddit,
|
||||||
telegram,
|
telegram,
|
||||||
twitter
|
twitter
|
||||||
} = opts;
|
} = opts;
|
||||||
//add data to assets/index.html
|
// add data to assets/index.html
|
||||||
jsdom
|
jsdom
|
||||||
.fromFile(`${__dirname}/assets/index.html`, options)
|
.fromFile(`${__dirname}/assets/index.html`, options)
|
||||||
.then(function(dom) {
|
.then(dom => {
|
||||||
let window = dom.window,
|
const {window} = dom;
|
||||||
document = window.document;
|
const {document} = window;
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
console.log("Building HTML/CSS...");
|
console.log("Building HTML/CSS...");
|
||||||
const repos = await getRepos(username, opts);
|
const repos = await getRepos(username, opts);
|
||||||
|
|
||||||
for (var i = 0; i < repos.length; i++) {
|
for (const element of repos) {
|
||||||
let element;
|
let element;
|
||||||
if (repos[i].fork == false) {
|
if (element.fork === false) {
|
||||||
element = document.getElementById("work_section");
|
element = document.querySelector("#work_section");
|
||||||
} else if (includeFork == true) {
|
} else if (includeFork === true) {
|
||||||
document.getElementById("forks").style.display = "block";
|
document.querySelector("#forks").style.display = "block";
|
||||||
element = document.getElementById("forks_section");
|
element = document.querySelector("#forks_section");
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
element.innerHTML += `
|
|
||||||
<a href="${repos[i].html_url}" target="_blank">
|
element.innerHTML += `
|
||||||
|
<a href="${element.html_url}" target="_blank">
|
||||||
<section>
|
<section>
|
||||||
<div class="section_title">${repos[i].name}</div>
|
<div class="section_title">${element.name}</div>
|
||||||
<div class="about_section">
|
<div class="about_section">
|
||||||
<span style="display:${
|
<span style="display:${
|
||||||
repos[i].description == undefined
|
element.description === undefined
|
||||||
? "none"
|
? "none"
|
||||||
: "block"
|
: "block"
|
||||||
};">${convertToEmoji(repos[i].description)}</span>
|
};">${convertToEmoji(element.description)}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="bottom_section">
|
<div class="bottom_section">
|
||||||
<span style="display:${
|
<span style="display:${
|
||||||
repos[i].language == null
|
element.language === null
|
||||||
? "none"
|
? "none"
|
||||||
: "inline-block"
|
: "inline-block"
|
||||||
};"><i class="mdi mdi-code-tags"></i> ${
|
};"><i class="mdi mdi-code-tags"></i> ${
|
||||||
repos[i].language
|
element.language
|
||||||
}</span>
|
}</span>
|
||||||
<span><i class="mdi mdi-star"></i> ${
|
<span><i class="mdi mdi-star"></i> ${
|
||||||
repos[i].stargazers_count
|
element.stargazers_count
|
||||||
}</span>
|
}</span>
|
||||||
<span><i class="mdi mdi-source-branch"></i> ${
|
<span><i class="mdi mdi-source-branch"></i> ${
|
||||||
repos[i].forks_count
|
element.forks_count
|
||||||
}</span>
|
}</span>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</a>`;
|
</a>`;
|
||||||
}
|
}
|
||||||
const user = await getUser(username);
|
|
||||||
document.title = user.login;
|
|
||||||
var icon = document.createElement("link");
|
|
||||||
icon.setAttribute("rel", "icon");
|
|
||||||
icon.setAttribute("href", user.avatar_url);
|
|
||||||
icon.setAttribute("type", "image/png");
|
|
||||||
|
|
||||||
document.getElementsByTagName("head")[0].appendChild(icon);
|
const user = await getUser(username);
|
||||||
document.getElementsByTagName("head")[0].innerHTML += `
|
document.title = user.login;
|
||||||
|
const icon = document.createElement("link");
|
||||||
|
icon.setAttribute("rel", "icon");
|
||||||
|
icon.setAttribute("href", user.avatar_url);
|
||||||
|
icon.setAttribute("type", "image/png");
|
||||||
|
|
||||||
|
document.querySelectorAll("head")[0].append(icon);
|
||||||
|
document.querySelectorAll("head")[0].innerHTML += `
|
||||||
<meta name="description" content="${user.bio}" />
|
<meta name="description" content="${user.bio}" />
|
||||||
<meta property="og:image" content="${user.avatar_url}" />
|
<meta property="og:image" content="${user.avatar_url}" />
|
||||||
<meta property="og:type" content="profile" />
|
<meta property="og:type" content="profile" />
|
||||||
|
@ -112,89 +118,95 @@ module.exports.updateHTML = (username, opts) => {
|
||||||
<meta name="twitter:card" content="summary" />
|
<meta name="twitter:card" content="summary" />
|
||||||
<meta name="twitter:title" content="${user.login}" />
|
<meta name="twitter:title" content="${user.login}" />
|
||||||
<meta name="twitter:description" content="${user.bio}" />`;
|
<meta name="twitter:description" content="${user.bio}" />`;
|
||||||
document.getElementById(
|
document.querySelector(
|
||||||
"username"
|
"#username"
|
||||||
).innerHTML = `<span id="text" style="display:${
|
).innerHTML = `<span id="text" style="display:${
|
||||||
user.name == null || !user.name ? "none" : "block"
|
user.name === null || !user.name ? "none" : "block"
|
||||||
};"></span><div class='console-underscore' id='console'>_</div><br><a href="${
|
};"></span><div class='console-underscore' id='console'>_</div><br><a href="${
|
||||||
user.html_url
|
user.html_url
|
||||||
}">@${user.login}</a>`;
|
}">@${user.login}</a>`;
|
||||||
//document.getElementById("github_link").href = `https://github.com/${user.login}`;
|
// document.getElementById("github_link").href = `https://github.com/${user.login}`;
|
||||||
document.getElementById("userbio").innerHTML = convertToEmoji(
|
document.querySelector("#userbio").innerHTML = convertToEmoji(
|
||||||
user.bio
|
user.bio
|
||||||
);
|
);
|
||||||
document.getElementById("userbio").style.display =
|
document.querySelector("#userbio").style.display =
|
||||||
user.bio == null || !user.bio ? "none" : "block";
|
user.bio == null || !user.bio ? "none" : "block";
|
||||||
document.getElementById("about").innerHTML = `
|
document.querySelector("#about").innerHTML = `
|
||||||
<span style="display:${
|
<span style="display:${
|
||||||
user.company == null || !user.company ? "none" : "block"
|
user.company == null || !user.company ? "none" : "block"
|
||||||
};"><i class="mdi-face"></i> ${user.company}</span>
|
};"><i class="mdi-face"></i> ${user.company}</span>
|
||||||
<span style="display:${
|
<span style="display:${
|
||||||
user.email == null || !user.email ? "none" : "block"
|
user.email == null || !user.email ? "none" : "block"
|
||||||
};"><i class="mdi mdi-email"></i> ${user.email}</span>
|
};"><i class="mdi mdi-email"></i> ${user.email}</span>
|
||||||
<span style="display:${
|
<span style="display:${
|
||||||
user.location == null || !user.location ? "none" : "block"
|
user.location == null || !user.location ? "none" : "block"
|
||||||
};"><i class="mdi mdi-map-marker"></i> ${
|
};"><i class="mdi mdi-map-marker"></i> ${
|
||||||
user.location
|
user.location
|
||||||
}</span>
|
}</span>
|
||||||
<span style="display:${
|
<span style="display:${
|
||||||
user.hireable == false || !user.hireable ? "none" : "block"
|
user.hireable == false || !user.hireable ? "none" : "block"
|
||||||
};"><i class="mdi mdi-account-tie"></i> Available for hire</span>
|
};"><i class="mdi mdi-account-tie"></i> Available for hire</span>
|
||||||
<div class="socials">
|
<div class="socials">
|
||||||
<span style="display:${
|
<span style="display:${
|
||||||
codepen == null ? "none !important" : "block"
|
codepen == null ? "none !important" : "block"
|
||||||
};"><a href="https://codepen.io/${codepen}" target="_blank" class="socials"><i class="mdi mdi-codepen"></i></a></span>
|
};"><a href="https://codepen.io/${codepen}" target="_blank" class="socials"><i class="mdi mdi-codepen"></i></a></span>
|
||||||
<span style="display:${
|
<span style="display:${
|
||||||
dev == null ? "none !important" : "block"
|
dev == null ? "none !important" : "block"
|
||||||
};"><a href="https://dev.to/${dev}" target="_blank" class="socials"><i class="mdi mdi-dev-to"></i></a></span>
|
};"><a href="https://dev.to/${dev}" target="_blank" class="socials"><i class="mdi mdi-dev-to"></i></a></span>
|
||||||
<span style="display:${
|
<span style="display:${
|
||||||
dribbble == null ? "none !important" : "block"
|
dribbble == null ? "none !important" : "block"
|
||||||
};"><a href="https://www.dribbble.com/${dribbble}" target="_blank" class="socials"><i class="mdi mdi-dribbble"></i></a></span>
|
};"><a href="https://www.dribbble.com/${dribbble}" target="_blank" class="socials"><i class="mdi mdi-dribbble"></i></a></span>
|
||||||
<span style="display:${
|
<span style="display:${
|
||||||
email == null ? "none !important" : "block"
|
email == null ? "none !important" : "block"
|
||||||
};"><a href="mailto:${email}" target="_blank" class="socials"><i class="mdi mdi-email"></i></a></span>
|
};"><a href="mailto:${email}" target="_blank" class="socials"><i class="mdi mdi-email"></i></a></span>
|
||||||
<span style="display:${
|
<span style="display:${
|
||||||
instagram == null ? "none !important" : "block"
|
instagram == null ? "none !important" : "block"
|
||||||
};"><a href="https://www.instagram.com/${instagram}" target="_blank" class="socials"><i class="mdi mdi-instagram"></i></a></span>
|
};"><a href="https://www.instagram.com/${instagram}" target="_blank" class="socials"><i class="mdi mdi-instagram"></i></a></span>
|
||||||
<span style="display:${
|
<span style="display:${
|
||||||
reddit == null ? "none !important" : "block"
|
reddit == null ? "none !important" : "block"
|
||||||
};"><a href="https://www.reddit.com/u/${reddit}" target="_blank" class="socials"><i class="mdi mdi-reddit"></i></a></span>
|
};"><a href="https://www.reddit.com/u/${reddit}" target="_blank" class="socials"><i class="mdi mdi-reddit"></i></a></span>
|
||||||
<span style="display:${
|
<span style="display:${
|
||||||
telegram == null ? "none !important" : "block"
|
telegram == null ? "none !important" : "block"
|
||||||
};"><a href="https://t.me/${telegram}" target="_blank" class="socials"><i class="mdi mdi-telegram"></i></a></span>
|
};"><a href="https://t.me/${telegram}" target="_blank" class="socials"><i class="mdi mdi-telegram"></i></a></span>
|
||||||
<span style="display:${
|
<span style="display:${
|
||||||
twitter == null ? "none !important" : "block"
|
twitter == null ? "none !important" : "block"
|
||||||
};"><a href="https://www.twitter.com/${twitter}" target="_blank" class="socials"><i class="mdi mdi-twitter"></i></a></span>
|
};"><a href="https://www.twitter.com/${twitter}" target="_blank" class="socials"><i class="mdi mdi-twitter"></i></a></span>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
//add data to config.json
|
// add data to config.json
|
||||||
const data = await getConfig();
|
const data = await getConfig();
|
||||||
data[0].username = user.login;
|
data[0].username = user.login;
|
||||||
data[0].name = user.name;
|
data[0].name = user.name;
|
||||||
data[0].userimg = user.avatar_url;
|
data[0].userimg = user.avatar_url;
|
||||||
|
|
||||||
await fs.writeFile(
|
await fs.writeFile(
|
||||||
`${outDir}/config.json`,
|
`${outDir}/config.json`,
|
||||||
JSON.stringify(data, null, " "),
|
JSON.stringify(data, null, " "),
|
||||||
function(err) {
|
err => {
|
||||||
if (err) throw err;
|
if (err) {
|
||||||
console.log("Config file updated.");
|
throw err;
|
||||||
}
|
}
|
||||||
);
|
|
||||||
await fs.writeFile(
|
console.log("Config file updated.");
|
||||||
`${outDir}/index.html`,
|
}
|
||||||
"<!DOCTYPE html>" + window.document.documentElement.outerHTML,
|
);
|
||||||
function(error) {
|
await fs.writeFile(
|
||||||
if (error) throw error;
|
`${outDir}/index.html`,
|
||||||
console.log(`Build Complete, Files can be Found @ ${outDir}\n`);
|
"<!DOCTYPE html>" + window.document.documentElement.outerHTML,
|
||||||
}
|
error => {
|
||||||
);
|
if (error) {
|
||||||
} catch (error) {
|
throw error;
|
||||||
console.log(error);
|
}
|
||||||
}
|
|
||||||
})();
|
console.log(`Build Complete, Files can be Found @ ${outDir}\n`);
|
||||||
})
|
}
|
||||||
.catch(function(error) {
|
);
|
||||||
console.log(error);
|
} catch (error) {
|
||||||
});
|
console.log(error);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.log(error);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
20
run.js
20
run.js
|
@ -1,22 +1,22 @@
|
||||||
const express = require("express");
|
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
|
const express = require("express");
|
||||||
const outDir = path.resolve("./dist/" || process.env.OUT_DIR);
|
const outDir = path.resolve("./dist/" || process.env.OUT_DIR);
|
||||||
const app = express();
|
const app = express();
|
||||||
app.use(express.static(`${outDir}`));
|
app.use(express.static(`${outDir}`));
|
||||||
|
|
||||||
function runCommand(program) {
|
function runCommand(program) {
|
||||||
let port = program.port ? program.port : 3000;
|
const port = program.port ? program.port : 3000;
|
||||||
|
|
||||||
app.get("/", function(req, res) {
|
app.get("/", (req, res) => {
|
||||||
res.sendFile("/index.html");
|
res.sendFile("/index.html");
|
||||||
});
|
});
|
||||||
|
|
||||||
app.listen(port);
|
app.listen(port);
|
||||||
console.log(
|
console.log(
|
||||||
`\nGitfolio running on port ${port}, Navigate to http://localhost:${port} in your browser\n`
|
`\nGitfolio running on port ${port}, Navigate to http://localhost:${port} in your browser\n`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
runCommand
|
runCommand
|
||||||
};
|
};
|
||||||
|
|
152
ui.js
152
ui.js
|
@ -1,99 +1,101 @@
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const express = require("express");
|
const express = require("express");
|
||||||
const { updateHTML } = require("./populate");
|
const jsdom = require("jsdom").JSDOM;
|
||||||
const { populateCSS, populateConfig } = require("./build");
|
const options = {
|
||||||
const { updateCommand } = require("./update");
|
resources: "usable"
|
||||||
|
};
|
||||||
|
const {updateHTML} = require("./populate");
|
||||||
|
const {populateCSS, populateConfig} = require("./build");
|
||||||
|
const {updateCommand} = require("./update");
|
||||||
const app = express();
|
const app = express();
|
||||||
app.set("view engine", "ejs");
|
app.set("view engine", "ejs");
|
||||||
app.use(express.static(__dirname + "/views"));
|
app.use(express.static(__dirname + "/views"));
|
||||||
app.set("views", __dirname + "/views");
|
app.set("views", __dirname + "/views");
|
||||||
app.use(
|
app.use(
|
||||||
express.json({
|
express.json({
|
||||||
limit: "50mb"
|
limit: "50mb"
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
app.use(
|
app.use(
|
||||||
express.urlencoded({
|
express.urlencoded({
|
||||||
limit: "50mb",
|
limit: "50mb",
|
||||||
extended: true
|
extended: true
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
const port = 3000;
|
const port = 3000;
|
||||||
|
|
||||||
const jsdom = require("jsdom").JSDOM,
|
|
||||||
options = {
|
|
||||||
resources: "usable"
|
|
||||||
};
|
|
||||||
global.DOMParser = new jsdom().window.DOMParser;
|
global.DOMParser = new jsdom().window.DOMParser;
|
||||||
|
|
||||||
function uiCommand() {
|
function uiCommand() {
|
||||||
app.get("/", function(req, res) {
|
app.get("/", (req, res) => {
|
||||||
res.render("index.ejs");
|
res.render("index.ejs");
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/update", function(req, res) {
|
app.get("/update", (req, res) => {
|
||||||
if (!fs.existsSync(`${outDir}/config.json`)) {
|
if (!fs.existsSync(`${outDir}/config.json`)) {
|
||||||
return res.send(
|
return res.send(
|
||||||
'You need to run build command before using update<br><a href="/">Go Back</a>'
|
'You need to run build command before using update<br><a href="/">Go Back</a>'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
updateCommand();
|
|
||||||
res.redirect("/");
|
|
||||||
});
|
|
||||||
|
|
||||||
app.post("/build", function(req, res) {
|
updateCommand();
|
||||||
let username = req.body.username;
|
res.redirect("/");
|
||||||
if (!username) {
|
});
|
||||||
return res.send("username can't be empty");
|
|
||||||
}
|
|
||||||
let sort = req.body.sort ? req.body.sort : "created";
|
|
||||||
let order = req.body.order ? req.body.order : "asc";
|
|
||||||
let includeFork = req.body.fork == "true" ? true : false;
|
|
||||||
let types = ["owner"];
|
|
||||||
let codepen = req.body.codepen ? req.body.codepen : null;
|
|
||||||
let dev = req.body.dev ? req.body.dev : null;
|
|
||||||
let dribbble = req.body.dribbble ? req.body.dribbble : null;
|
|
||||||
let email = req.body.email ? req.body.email : null;
|
|
||||||
let instagram = req.body.instagram ? req.body.instagram : null;
|
|
||||||
let reddit = req.body.reddit ? req.body.reddit : null;
|
|
||||||
let telegram = req.body.telegram ? req.body.telegram : null;
|
|
||||||
let twitter = req.body.twitter ? req.body.twitter : null;
|
|
||||||
let background = req.body.background
|
|
||||||
? req.body.background
|
|
||||||
: "https://source.unsplash.com/1280x720/?wallpaper";
|
|
||||||
let theme = req.body.theme == "on" ? "dark" : "light";
|
|
||||||
const opts = {
|
|
||||||
sort: sort,
|
|
||||||
order: order,
|
|
||||||
includeFork: includeFork,
|
|
||||||
types,
|
|
||||||
codepen: codepen,
|
|
||||||
dev: dev,
|
|
||||||
dribbble: dribbble,
|
|
||||||
email: email,
|
|
||||||
instagram: instagram,
|
|
||||||
reddit: reddit,
|
|
||||||
telegram: telegram,
|
|
||||||
twitter: twitter
|
|
||||||
};
|
|
||||||
|
|
||||||
updateHTML(username, opts);
|
app.post("/build", (req, res) => {
|
||||||
populateCSS({
|
const {username} = req.body;
|
||||||
background: background,
|
if (!username) {
|
||||||
theme: theme
|
return res.send("username can't be empty");
|
||||||
});
|
}
|
||||||
populateConfig(opts);
|
|
||||||
res.redirect("/");
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log("\nStarting...");
|
const sort = req.body.sort ? req.body.sort : "created";
|
||||||
app.listen(port);
|
const order = req.body.order ? req.body.order : "asc";
|
||||||
console.log(
|
const includeFork = req.body.fork === "true";
|
||||||
`The GUI is running on port ${port}, Navigate to http://localhost:${port} in your browser\n`
|
const types = ["owner"];
|
||||||
);
|
const codepen = req.body.codepen ? req.body.codepen : null;
|
||||||
|
const dev = req.body.dev ? req.body.dev : null;
|
||||||
|
const dribbble = req.body.dribbble ? req.body.dribbble : null;
|
||||||
|
const email = req.body.email ? req.body.email : null;
|
||||||
|
const instagram = req.body.instagram ? req.body.instagram : null;
|
||||||
|
const reddit = req.body.reddit ? req.body.reddit : null;
|
||||||
|
const telegram = req.body.telegram ? req.body.telegram : null;
|
||||||
|
const twitter = req.body.twitter ? req.body.twitter : null;
|
||||||
|
const background = req.body.background
|
||||||
|
? req.body.background
|
||||||
|
: "https://source.unsplash.com/1280x720/?wallpaper";
|
||||||
|
const theme = req.body.theme === "on" ? "dark" : "light";
|
||||||
|
const opts = {
|
||||||
|
sort,
|
||||||
|
order,
|
||||||
|
includeFork,
|
||||||
|
types,
|
||||||
|
codepen,
|
||||||
|
dev,
|
||||||
|
dribbble,
|
||||||
|
email,
|
||||||
|
instagram,
|
||||||
|
reddit,
|
||||||
|
telegram,
|
||||||
|
twitter
|
||||||
|
};
|
||||||
|
|
||||||
|
updateHTML(username, opts);
|
||||||
|
populateCSS({
|
||||||
|
background,
|
||||||
|
theme
|
||||||
|
});
|
||||||
|
populateConfig(opts);
|
||||||
|
res.redirect("/");
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("\nStarting...");
|
||||||
|
app.listen(port);
|
||||||
|
console.log(
|
||||||
|
`The GUI is running on port ${port}, Navigate to http://localhost:${port} in your browser\n`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
uiCommand
|
uiCommand
|
||||||
};
|
};
|
||||||
|
|
53
update.js
53
update.js
|
@ -1,32 +1,33 @@
|
||||||
const { getConfig } = require("./utils");
|
const {getConfig} = require("./utils");
|
||||||
const { updateHTML } = require("./populate");
|
const {updateHTML} = require("./populate");
|
||||||
|
|
||||||
async function updateCommand() {
|
async function updateCommand() {
|
||||||
const data = await getConfig();
|
const data = await getConfig();
|
||||||
var username = data[0].username;
|
const {username} = data[0];
|
||||||
if (username == null) {
|
if (username === null) {
|
||||||
console.log(
|
console.log(
|
||||||
"username not found in config.json, please run build command before using update"
|
"username not found in config.json, please run build command before using update"
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const opts = {
|
|
||||||
sort: data[0].sort,
|
const opts = {
|
||||||
order: data[0].order,
|
sort: data[0].sort,
|
||||||
includeFork: data[0].includeFork,
|
order: data[0].order,
|
||||||
types: data[0].types,
|
includeFork: data[0].includeFork,
|
||||||
codepen: data[0].codepen,
|
types: data[0].types,
|
||||||
dev: data[0].dev,
|
codepen: data[0].codepen,
|
||||||
dribbble: data[0].dribbble,
|
dev: data[0].dev,
|
||||||
email: data[0].email,
|
dribbble: data[0].dribbble,
|
||||||
instagram: data[0].instagram,
|
email: data[0].email,
|
||||||
reddit: data[0].reddit,
|
instagram: data[0].instagram,
|
||||||
telegram: data[0].telegram,
|
reddit: data[0].reddit,
|
||||||
twitter: data[0].twitter
|
telegram: data[0].telegram,
|
||||||
};
|
twitter: data[0].twitter
|
||||||
updateHTML(username, opts);
|
};
|
||||||
|
updateHTML(username, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
updateCommand
|
updateCommand
|
||||||
};
|
};
|
||||||
|
|
23
utils.js
23
utils.js
|
@ -12,21 +12,22 @@ const defaultConfigPath = path.resolve(`${__dirname}/default/config.json`);
|
||||||
* if not present returns default file contents
|
* if not present returns default file contents
|
||||||
*/
|
*/
|
||||||
async function getFileWithDefaults(file, defaultFile) {
|
async function getFileWithDefaults(file, defaultFile) {
|
||||||
try {
|
try {
|
||||||
await fs.accessAsync(file, fs.constants.F_OK);
|
await fs.accessAsync(file, fs.constants.F_OK);
|
||||||
} catch (err) {
|
} catch (error) {
|
||||||
const defaultData = await fs.readFileAsync(defaultFile);
|
const defaultData = await fs.readFileAsync(defaultFile);
|
||||||
return JSON.parse(defaultData);
|
return JSON.parse(defaultData);
|
||||||
}
|
}
|
||||||
const data = await fs.readFileAsync(file);
|
|
||||||
return JSON.parse(data);
|
const data = await fs.readFileAsync(file);
|
||||||
|
return JSON.parse(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getConfig() {
|
async function getConfig() {
|
||||||
return getFileWithDefaults(configPath, defaultConfigPath);
|
return getFileWithDefaults(configPath, defaultConfigPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
outDir,
|
outDir,
|
||||||
getConfig
|
getConfig
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue