Skip to content

Commit

Permalink
Merge pull request #20 from nunocoracao/11-author
Browse files Browse the repository at this point in the history
✨ added features to config author and basic site information
  • Loading branch information
nunocoracao authored Jan 15, 2024
2 parents e3d7049 + 1f2a507 commit b9cfed6
Show file tree
Hide file tree
Showing 6 changed files with 229 additions and 33 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ CLI to initialize and configure a [Blowfish](https://blowfish.page) project. Ins
- Configure an existing Hugo project to use Blowfish
- Run a local server with Blowfish
- Generate the static site with Hugo
- Configure site's main information - title, description, etc
- Configure site's author - name, bio, links, etc

## Installation
Install globally using:
Expand Down Expand Up @@ -51,4 +53,6 @@ Commands:
install Installs Blowfish on an existing Hugo project (assumes current directory).
run Run a local server with Blowfish in the current directory. Requires Hugo to be installed and Blowfish configured in current directory.
generate Generates site assets in public folder in the current directory. Requires Hugo to be installed and Blowfish configured in current directory.
configMeta Configure site's main information - title, description, etc
configAuthor Configure site's author - name, bio, links, etc
```
12 changes: 12 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,17 @@ program.command('generate')
flow.generateSite(true);
});

program.command('configMeta')
.description('Configure site\'s main information - title, description, etc')
.action((str, options) => {
flow.configureMeta(true);
});

program.command('configAuthor')
.description('Configure site\'s author - name, bio, links, etc')
.action((str, options) => {
flow.configureAuthor(true);
});


program.parse();
12 changes: 9 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "blowfish-tools",
"version": "0.8.2",
"version": "0.8.3",
"description": "CLI to initialize and configure a Blowfish project.",
"main": "cli.js",
"bin": {
Expand Down Expand Up @@ -33,6 +33,7 @@
"command-exists": "^1.2.9",
"commander": "^11.1.0",
"enquirer": "^2.4.1",
"ora": "^8.0.1"
"ora": "^8.0.1",
"toml-patch": "^0.2.3"
}
}
203 changes: 176 additions & 27 deletions src/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import ora from 'ora';
import pkg from 'enquirer';
const { prompt } = pkg;
import toml from 'toml-patch';

import eyecandy from "./eyecandy.js";
import utils from './utils.js';

Expand All @@ -17,7 +19,7 @@ export default class flow {
}
}

static async showMain() {
static async showMain(message) {

var blowfishIsInstalled = await flow.detectBlowfish();

Expand All @@ -26,12 +28,16 @@ export default class flow {
var choices = [];

for (var i in options) {
if (!options[i].hasOwnProperty('blowfishIsInstalled') )
if (!options[i].hasOwnProperty('blowfishIsInstalled'))
choices.push(options[i].text);
else if (options[i].blowfishIsInstalled && blowfishIsInstalled)
choices.push(options[i].text);
else if (!options[i].blowfishIsInstalled && !blowfishIsInstalled)
choices.push(options[i].text);
choices.push(options[i].text);
}

if (message) {
console.log(message);
}

const response = await prompt({
Expand All @@ -51,27 +57,6 @@ export default class flow {
}
}

static async showPost(message) {
console.log(message)
const response = await prompt({
type: 'AutoComplete',
name: 'option',
message: 'Do you need help with anything else?',
limit: 10,
initial: 0,
choices: [
'Take me to the main menu',
'Exit'
]
});

if (response.option === 'Exit') {
eyecandy.showBye();
} else if (response.option === 'Take me to the main menu') {
flow.showMain();
}
}

static async configureNew(directory, exitAfterRun) {
const spinner = ora('Checking for dependencies').start();
await flow.checkHugo(spinner);
Expand Down Expand Up @@ -130,14 +115,14 @@ export default class flow {
if (exitAfterRun)
process.exit(0);
else
flow.showPost('Blowfish configured in ' + response.directory + '. cd into it and run "hugo server" to start your website.', { dir: response.directory });
flow.showMain('Blowfish configured in ' + response.directory + '. cd into it and run "hugo server" to start your website.', { dir: response.directory });

}

static async configureExisting(exitAfterRun) {

var blowfishIsInstalled = await flow.detectBlowfish();
if(blowfishIsInstalled) {
if (blowfishIsInstalled) {
console.log('Blowfish is already installed in this folder.');
process.exit(0);
}
Expand All @@ -162,7 +147,7 @@ export default class flow {
if (exitAfterRun)
process.exit(0);
else
flow.showPost('Blowfish installed. Run "hugo server" to start your website.', { dir: response.directory });
flow.showMain('Blowfish installed. Run "hugo server" to start your website.', { dir: response.directory });
}

static async runServer() {
Expand Down Expand Up @@ -212,6 +197,160 @@ export default class flow {
});
}

static async configureMeta(exitAfterRun) {
var blowfishIsInstalled = await flow.detectBlowfish();
if (!blowfishIsInstalled) {
console.log('Blowfish is not yet installed.');
process.exit(0);
}

const fileToConfigure = './config/_default/languages.en.toml';

if (!utils.fileExists(fileToConfigure)) {
console.log('File ' + fileToConfigure + ' does not exist.');
process.exit(0);
}

var data = toml.parse(utils.openFile(fileToConfigure).toString());

const response = await prompt([
{
type: 'input',
name: 'title',
default: data.title ? data.title : 'a title',
message: 'What is the title of your site?'
},
{
type: 'input',
name: 'description',
default: data.description ? data.description : 'a description',
message: 'What is the description of your site?'
},
{
type: 'input',
name: 'logo',
default: data.params && data.params.logo ? data.params.logo : 'logo.png',
message: 'Do you have a logo for your website? - please place the file in the assets folder and type the filename here.'
}
]);

data.title = response.title;
if (!data.params)
data.params = {};

data.params.description = response.description;
data.params.logo = response.logo;

utils.saveFileSync(fileToConfigure, toml.stringify(data));

if (exitAfterRun)
process.exit(0);
else
flow.showMain('Configurations applied. Run server to check changes.');
}

static async configureAuthor(exitAfterRun) {

var blowfishIsInstalled = await flow.detectBlowfish();
if (!blowfishIsInstalled) {
console.log('Blowfish is not yet installed.');
process.exit(0);
}

const fileToConfigure = './config/_default/languages.en.toml';

if (!utils.fileExists(fileToConfigure)) {
console.log('File ' + fileToConfigure + ' does not exist.');
process.exit(0);
}

var data = toml.parse(utils.openFile(fileToConfigure).toString());

const response = await prompt([
{
type: 'input',
name: 'name',
default: data.author && data.author.name ? data.author.name : 'a name',
message: 'What is your name?'
},
{
type: 'input',
name: 'image',
default: data.author && data.author.image ? data.author.image : 'profile.png',
message: 'Do you have a profile for your website? - please place the file in the assets folder and type the filename here.'
},
{
type: 'input',
name: 'headline',
default: data.author && data.author.headline ? data.author.headline : 'a headline',
message: 'What is your headline - displayed below name in main page?'
},
{
type: 'input',
name: 'bio',
default: data.author && data.author.bio ? data.author.bio : 'a bio',
message: 'What is your bio - displayed in author pages?'
},
{
type: 'multiselect',
name: 'value',
message: 'Which links to you want to configure for your profile?\nSelect using spacebar and press enter when done.',
choices: [
{ name: 'email' },
{ name: 'link' },
{ name: 'bluesky' },
{ name: 'discord' },
{ name: 'github' },
{ name: 'instagram' },
{ name: 'keybase' },
{ name: 'linkedin' },
{ name: 'mastodon' },
{ name: 'medium' },
{ name: 'reddit' },
{ name: 'telegram' },
{ name: 'tiktok' },
{ name: 'twitter' },
{ name: 'x-twitter' },
{ name: 'whatsapp' },
{ name: 'youtube' }
]
}
]);


var linksQuestions = [];
for (var i in response.value) {
linksQuestions.push({
type: 'input',
name: response.value[i],
message: 'What URL do you want to configure for ' + response.value[i] + '?'
});
}

const responseLinks = await prompt(linksQuestions);

if (!data.author)
data.author = {};
data.author.name = response.name;
data.author.image = response.image;
data.author.headline = response.headline;
data.author.bio = response.bio;
data.author.links = [];

for (const [key, value] of Object.entries(responseLinks)) {
var obj = {}
obj[key] = value;
data.author.links.push(obj);
}

utils.saveFileSync(fileToConfigure, toml.stringify(data));

if (exitAfterRun)
process.exit(0);
else
flow.showMain('Configurations applied. Run server to check changes.');
}

}


Expand All @@ -226,6 +365,16 @@ var options = [
blowfishIsInstalled: false,
action: flow.configureExisting
},
{
text: 'Configure site\'s main information - title, description, etc',
blowfishIsInstalled: true,
action: flow.configureMeta
},
{
text: 'Configure site\'s author - name, bio, links, etc',
blowfishIsInstalled: true,
action: flow.configureAuthor
},
{
text: 'Run a local server with Blowfish',
blowfishIsInstalled: true,
Expand Down
Loading

0 comments on commit b9cfed6

Please sign in to comment.