Skip to content

Commit

Permalink
added setup command
Browse files Browse the repository at this point in the history
  • Loading branch information
Daveed committed Sep 24, 2023
1 parent dbcb415 commit 01fcac0
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 15 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# NEXTVERSION

# 2.2.1
- Creating setup command to generate default _config.yml

# 2.2.0-a
- Fixing copy command that was corrupting images

Expand Down
38 changes: 38 additions & 0 deletions lib/bin/commands/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const logger = require('../../utils/logger');
const config = require('../../core/project.config');
const _setup = require('../../commands/setup');
const fs = require('fs');

/**
* Normally called as part of another command, but it can be used
* directly for debugging purposes.
* When given an output argument it will write the results and
* additional information to disk in a json file.
*
* Default include-paths are pages and posts.
* @param {string} argv.dest If present, write result to destination file
*/
const setup = (argv) => {
const { defaults } = config;

_setup.run({ config: defaults }, argv.overwrite).then((project) => {
// logger.log();

return project;
});
};

const options = {
overwrite: {
default: false,
description: `Overwrite existing files: not yet supported.`,
},
};

module.exports = {
command: `setup`,
aliases: [],
describe: `Attemps to create a _config.yml file and the necesary folders.`,
builder: options,
handler: setup,
};
20 changes: 20 additions & 0 deletions lib/commands/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const $q = require('q');
const logger = require('../utils/logger');
const config = require('../core/project.config');
const root = process.cwd();
const path = require('path');

// Actual collect file that the bin file calls after it processed the arguments or whatever
const run = (project) => {
const { writeYaml } = config;

// @TODO: create folders described in _config files to avoid errors during first run

writeYaml(project.config);
logger.log(project.config);
return $q.resolve();
};

module.exports = {
run,
};
52 changes: 38 additions & 14 deletions lib/core/project.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,48 @@ const loadConfigFromYamlFile = () => {
return config;
};

const writeConfigToYamlFile = (config, overwrite = false) => {
var root = process.cwd();
const configPath = path.normalize(`${root}/_config.yml`);

if (!fs.existsSync(configPath)) {
//require(`yargs`)
logger.warn(`${root}/_config.yml already exists`);
return {};
}

const configString = yaml.stringify(config);

fs.writeFile(path.normalize(`${root}/_config.yml`), configString, (err) => {
if (err) {
return logger.error(err);
}
logger.log('_config.yml was created!');
});
return {};
};

const defaults = {
include: ['pages'],
name: 'Slava',
tagline: 'A website generated with gloriaJs',
author: 'gloriajs',
dest: 'build',
copy: ['public'],
exclude: ['.draft.md'],
theme: ['layouts/tailwind'],
css: 'tailwind',
engine: 'default',
version: '2',
};

/**
* Call to read project configuration information from the defaults and the config files
*
* @returns {object} configuration settings for the project
*/
const get = () => {
const defaultConfig = {
include: ['pages'],
name: 'Slava',
tagline: 'A website generated with gloriaJs',
author: 'gloriajs',
dest: 'build',
copy: ['public'],
exclude: ['.draft.md'],
theme: ['layouts/tailwind'],
css: 'tailwind',
engine: 'default',
version: '2.0.4',
};

const defaultConfig = defaults;
const yamlConfig = loadConfigFromYamlFile();

/**
Expand All @@ -56,4 +78,6 @@ const get = () => {
module.exports = {
get: get,
getYaml: loadConfigFromYamlFile,
writeYaml: writeConfigToYamlFile,
defaults,
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gloriajs",
"version": "2.2.0-a",
"version": "2.2.1",
"description": "Gloria is a NodeJS simple static website generator.",
"main": "cli.js",
"bin": "cli.js",
Expand Down

0 comments on commit 01fcac0

Please sign in to comment.