Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
juliancwirko committed Apr 25, 2021
0 parents commit 480066a
Show file tree
Hide file tree
Showing 58 changed files with 3,338 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
insert_final_newline = true
indent_style = space
indent_size = 2
charset = utf-8
24 changes: 24 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"extends": [
"plugin:prettier/recommended",
"eslint:recommended"
],
"env": {
"node": true
},
"parserOptions": {
"ecmaVersion": 2018
},
"rules": {
"no-var": "error",
"prefer-const": "error",
"no-use-before-define": "error",
"no-mixed-spaces-and-tabs": "error",
"no-nested-ternary": "error",
"no-unused-vars": "error",
"prettier/prettier": ["error", {
"endOfLine": "auto"
}]
}
}

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
11 changes: 11 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"arrowParens": "always",
"trailingComma": "es5",
"jsxBracketSameLine": false,
"jsxSingleQuote": true,
"endOfLine": "auto"
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Julian Ćwirko

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
71 changes: 71 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
## create-harold-app

Static site and blog generator based on Handlebars and Markdown.

## Why another one?

Because I wanted to have a simple static site generator to build and host on Netlify. I know there are many of them. I built one to have better control over it.

What is important, I equipped it with two themes that you can use and modify for your needs. I prepared the theme system for custom ones in the future. This is also added value. We don’t need to start every site/blog repeatedly from the ground.

## When to use it

- wehen you want to build static website/blog with simple search functionality (default theme)
- when you want to build small (maybe medium) site or blog
- when you don't want to use any big and complicated solution
- when you know how to use Handlebars template system

## When not to use it

- when you want to build something big (not tested with very big projects, tested with over 120 markdown files, works quite fast)
- when you don't want to use Scss (you can still write standard css in .scss files)
- when you want to rely on something which has its own community

### Creating an app

##### npx
```
npx create-harold-app my-app
```
(npx is a package runner tool that comes with npm 5.2+ and higher, see instructions for older npm versions)

##### npm
```
npm init harold-app my-app
```
npm init <initializer> is available in npm 6+

##### Yarn
```
yarn create harold-app my-app
```
yarn create <starter-kit-package> is available in Yarn 0.25+

It will create a directory called my-app inside the current folder.
Inside that directory, it will generate the initial project structure and install the transitive dependencies.

As an option you can choose with which template it should init the project. Possible choices:
- default
- bare

If you want to init the project with `bare` template pass additional option `-t bare`. For example: `npm init harold-app my-app -t bare`

In the future there will be a possibility to pass custom templates.

Write `create-harold-app --help` in terminal to get the list of options.

### Starting the app

From newly created app's directory (in our case `my-app`). Run `npm start`. It will serve the app under `localhost:3000`. To change the port just add `PORT` env, like: `PORT=3002 npm start`.

### Documentation

WIP. Available soon.

### License

MIT

### Contact

julian.io
80 changes: 80 additions & 0 deletions bin/create-harold-app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env node

const spawn = require('cross-spawn');
const { program } = require('commander');
const sanitizeName = require('sanitize-filename');
const path = require('path');
const fse = require('fs-extra');
const fs = require('fs');

const TEMPLATES = ['bare', 'default'];

const packageJson = require('../package.json');

const args = process.argv;
const projectName = args ? args[2] : undefined;

program
.option('-t, --template <type>', 'template type (bare, default)')
.option('-v, --version', 'Create Harold App version');
program.parse(process.argv);

const options = program.opts();

// Show version number
if (options.version) {
console.log(packageJson.version);
return;
}

if (projectName && projectName.indexOf('-') !== 0) {
// Create project directory
spawn.sync('mkdir', [sanitizeName(projectName)], { stdio: 'inherit' });

let templateName = 'default';

// Choose template if user passes an option
if (options.template && TEMPLATES.includes(options.template)) {
templateName = options.template;
}

// Copy required files to proper directories
fse
.copy(
path.join(__dirname, '../templates/' + templateName),
process.cwd() + '/' + projectName + '/src'
)
.then(() => {
// Write proper package.json file for the project
fs.readFile(
__dirname + '/' + 'packagejson.template',
'utf8',
function (err, data) {
if (err) {
return console.log(err);
}

const result = data.replace(/{{projectName}}/g, projectName);

fs.writeFile(
process.cwd() + '/' + projectName + '/' + 'package.json',
result,
'utf8',
function (err) {
if (err) return console.log(err);

// Install packages in the newly created project
process.chdir(projectName);
spawn.sync('npm', ['install'], { stdio: 'inherit' });
process.chdir('..');
}
);
}
);
})
.catch((err) => {
if (err) console.log(err);
});
} else {
console.log('Please provide project name (directory)');
}
13 changes: 13 additions & 0 deletions bin/packagejson.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "{{projectName}}",
"version": "0.0.1",
"description": "{{projectName}}",
"main": "index.js",
"scripts": {
"build": "harold-scripts build",
"start": "harold-scripts start"
},
"devDependencies": {
"harold-scripts": "^0.1.0"
}
}
Loading

0 comments on commit 480066a

Please sign in to comment.