Skip to content

Commit

Permalink
custom templates
Browse files Browse the repository at this point in the history
  • Loading branch information
juliancwirko committed Aug 8, 2021
1 parent ddbf73d commit 84457ce
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### [0.7.0](https://github.com/juliancwirko/create-harold-app/releases/tag/v0.7.0) (2021-08-08)

- possibility to pass a custom template package when initializing the project

### [0.6.0](https://github.com/juliancwirko/create-harold-app/releases/tag/v0.6.0) (2021-07-11)

- new docs template as another option `-t docs`
Expand Down
32 changes: 29 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,36 @@ As an option, you can choose with which template it should init the project. Pos

If you want to init the project with `docs` template, pass additional option `-t docs`. For example: `npm init harold-app my-app -t docs` or with npm 7+ `npm init harold-app my-app -- -t docs`. The same for `bare` template.

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

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

### Custom templates

You can prepare your template and reuse it on every new project initialization. You can do this by passing a path to your zip package. It can be a remote, hosted file or one from a local file system.

Examples:

```
npm init harold-app my-app -t https://github.com/juliancwirko/harold-template-scaffold/archive/refs/heads/main.zip
```

with npm 7+
```
npm init harold-app my-app -- -t https://github.com/juliancwirko/harold-template-scaffold/archive/refs/heads/main.zip
```

Or it can be also local file:

```
npm init harold-app my-app -t ./main.zip
```

with npm 7+
```
npm init harold-app my-app -- -t ./main.zip
```

Read more about it in the docs here: [Custom templates](https://www.haroldjs.com/docs/custom-templates.html).

### Starting the app

From the 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`.
Expand All @@ -69,7 +95,7 @@ You can configure the directory for md files (by default `posts`) and the direct

You can also configure the name for output directory using `outputDirName` and if you want to host your site in subdirectory you would also need to add `hostDirName`.

Example of `.haroldrc` (placed in the root of your harold app):
Example of `.haroldrc` (placed in the root of the app or in the src directory):

```
{
Expand Down
9 changes: 6 additions & 3 deletions bin/create-harold-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ if (options.template && Object.keys(TEMPLATES).includes(options.template)) {
if (isUrl(templateArchiveFilePath)) {
// Extract required files to proper directories
// This should be an archive link from a repository
// We need to strip one level of directories in the archive
// Assumption: you have root directory with files in the archive, by default in repository package
// so, we need to strip one level of directories in the archive
download(
templateArchiveFilePath,
process.cwd() + '/' + projectName + '/src',
Expand All @@ -114,10 +115,12 @@ if (isUrl(templateArchiveFilePath)) {
});
} else {
// This should be an archive file from local path
// Assumed that we don't have files on one root level directory
// Assumption: you have root directory with files in the archive
// so, we need to strip one level of directories in the archive
decompress(
templateArchiveFilePath,
process.cwd() + '/' + projectName + '/src'
process.cwd() + '/' + projectName + '/src',
{ strip: 1 }
)
.then(projectInit)
.catch((err) => {
Expand Down
2 changes: 1 addition & 1 deletion bin/packagejson.template
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"start": "harold-scripts start"
},
"devDependencies": {
"harold-scripts": "^0.6.0"
"harold-scripts": "^0.7.0"
}
}
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-harold-app",
"version": "0.6.0",
"version": "0.7.0",
"description": "Static blog/site generator",
"author": "Julian Ćwirko (julian.io)",
"license": "MIT",
Expand Down

0 comments on commit 84457ce

Please sign in to comment.