Skip to content

Commit

Permalink
Add default ignore flags and support nested builds
Browse files Browse the repository at this point in the history
  • Loading branch information
bcomnes committed Sep 15, 2021
1 parent 0536cd0 commit 0f26da9
Show file tree
Hide file tree
Showing 15 changed files with 217 additions and 17 deletions.
11 changes: 10 additions & 1 deletion bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ const clopts = cliclopts([
help: 'path to build destination directory',
default: 'public'
},
{
name: 'ignore',
abbr: 'i',
help: 'comma separated gitignore style ignore string'
},
{
name: 'watch',
abbr: 'w',
Expand Down Expand Up @@ -73,7 +78,11 @@ async function run () {

// TODO validate input a little better

const siteup = new Siteup(src, dest, cwd)
const opts = {}

if (argv.ignore) opts.ignore = argv.ignore.split(',')

const siteup = new Siteup(src, dest, cwd, opts)

process.once('SIGINT', quit)
process.once('SIGTERM', quit)
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "",
"type": "module",
"scripts": {
"build": "siteup"
"build": "siteup --src src --dest public"
},
"keywords": [],
"author": "Bret Comnes <bcomnes@gmail.com> (https://bret.io/)",
Expand Down
100 changes: 100 additions & 0 deletions examples/nested-dest/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

## [v1.0.0](https://github.com/bcomnes/siteup-cli/compare/v0.0.13...v1.0.0)

### Commits

- Add implementation notes. [`90db6b9`](https://github.com/bcomnes/siteup-cli/commit/90db6b9646b1968fe59231f291bf63fbfea96059)
- Update README.md [`8351e25`](https://github.com/bcomnes/siteup-cli/commit/8351e25a4fcd168d955bc19cd825ac5e6ed20c5f)
- Update README.md [`bbb07b6`](https://github.com/bcomnes/siteup-cli/commit/bbb07b6c9f98139c4634481a72fc12c64bd4ff72)

## [v0.0.13](https://github.com/bcomnes/siteup-cli/compare/v0.0.12...v0.0.13) - 2021-09-09

### Commits

- Rename to @siteup/cli [`6088b4a`](https://github.com/bcomnes/siteup-cli/commit/6088b4a966e50d695897fc0a8b8d021ea57e9c4c)

## [v0.0.12](https://github.com/bcomnes/siteup-cli/compare/v0.0.11...v0.0.12) - 2021-09-06

### Commits

- Rename to xiteup [`2b3e89d`](https://github.com/bcomnes/siteup-cli/commit/2b3e89d36c7555d56ed1d3d5f2aafc616833812e)
- Fix tests [`5747438`](https://github.com/bcomnes/siteup-cli/commit/57474386ab6e0f152e40326cd8ab581982c689ec)

## [v0.0.11](https://github.com/bcomnes/siteup-cli/compare/v0.0.10...v0.0.11) - 2021-09-05

### Commits

- Fix relative css imports [`3f2c731`](https://github.com/bcomnes/siteup-cli/commit/3f2c7312a5b0e611313c9f9d01d07758ca230347)

## [v0.0.10](https://github.com/bcomnes/siteup-cli/compare/v0.0.9...v0.0.10) - 2021-09-05

### Commits

- Disable pretty links for loose MD. [`686b9e5`](https://github.com/bcomnes/siteup-cli/commit/686b9e5de2f01bcf7d01843a618870be892beec9)
- Render loose md pages [`659b672`](https://github.com/bcomnes/siteup-cli/commit/659b672b03cfd42b0c41d5d0a4cb14f8a3f05a29)
- Revert "Rename to site-up" [`8750674`](https://github.com/bcomnes/siteup-cli/commit/875067461d8ffef3d23d610905f22c4d0ad889fc)

## [v0.0.9](https://github.com/bcomnes/siteup-cli/compare/v0.0.8...v0.0.9) - 2021-09-05

### Commits

- Rename to site-up [`8933cf6`](https://github.com/bcomnes/siteup-cli/commit/8933cf62a70b891aca570d512806ba1f3cd71a7a)

## [v0.0.8](https://github.com/bcomnes/siteup-cli/compare/v0.0.7...v0.0.8) - 2021-09-03

### Commits

- add file watcher [`b21b3d4`](https://github.com/bcomnes/siteup-cli/commit/b21b3d42ae1ecb202f50a9324edb4c86fd022d3a)

## [v0.0.7](https://github.com/bcomnes/siteup-cli/compare/v0.0.6...v0.0.7) - 2021-09-02

### Commits

- Set up included files [`bdc8204`](https://github.com/bcomnes/siteup-cli/commit/bdc82044714ae93dd44b8c4f22d72b95614fedfb)

## [v0.0.6](https://github.com/bcomnes/siteup-cli/compare/v0.0.5...v0.0.6) - 2021-09-02

### Fixed

- Inject titles [`#7`](https://github.com/bcomnes/siteup/issues/7)

## [v0.0.5](https://github.com/bcomnes/siteup-cli/compare/v0.0.4...v0.0.5) - 2021-09-02

### Commits

- Depcrusier tweaks [`1d0605b`](https://github.com/bcomnes/siteup-cli/commit/1d0605b4b64aefc25d299b347839aa618c03381e)
- Add global.client.js and global.css to injected scripts and styles [`061459d`](https://github.com/bcomnes/siteup-cli/commit/061459da557749acf8ebfcbb4a1d9576f7ffd391)

## [v0.0.4](https://github.com/bcomnes/siteup-cli/compare/v0.0.3...v0.0.4) - 2021-08-30

### Commits

- Optional lookups [`592d072`](https://github.com/bcomnes/siteup-cli/commit/592d0726ba717dfdc09946a01ca0d0cac620507f)

## [v0.0.3](https://github.com/bcomnes/siteup-cli/compare/v0.0.2...v0.0.3) - 2021-08-29

### Commits

- Scope package for now [`0900a51`](https://github.com/bcomnes/siteup-cli/commit/0900a51b48d1b3cde5bd1f17ff90995138b4f4f6)

## [v0.0.2](https://github.com/bcomnes/siteup-cli/compare/v0.0.1...v0.0.2) - 2021-08-29

### Commits

- Fix gh-release typo [`2d939c4`](https://github.com/bcomnes/siteup-cli/commit/2d939c4e1008b5e5439d763fd83881c7be221b86)

## v0.0.1 - 2021-08-29

### Commits

- nest page-builders in build-pages [`c5a644a`](https://github.com/bcomnes/siteup-cli/commit/c5a644a28fc1a6297854deed65fc220656fd3e6a)
- Checking in [`9bf386b`](https://github.com/bcomnes/siteup-cli/commit/9bf386bce0f1a7885476b772a1b794ebd3216f7a)
- Fix tests [`c1fc836`](https://github.com/bcomnes/siteup-cli/commit/c1fc8362233bd144d3bfa61f7aa1bf78fa8ad2bd)
34 changes: 34 additions & 0 deletions examples/nested-dest/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Contributing

## Guidelines

- Patches, ideas and changes welcome.
- Fixes almost always welcome.
- Features sometimes welcome.
- Please open an issue to discuss the issue prior to spending lots of time on the problem.
- It may be rejected.
- If you don't want to wait around for the discussion to commence, and you really want to jump into the implementation work, be prepared for fork if the idea is respectfully declined.
- Try to stay within the style of the existing code.
- All tests must pass.
- Additional features or code paths must be tested.
- Aim for 100% coverage.
- Questions are welcome, however unless there is a official support contract established between the maintainers and the requester, support is not guaranteed.
- Contributors reserve the right to walk away from this project at any moment with or without notice.

## Releasing

Changelog, and releasing is automated with npm scripts and actions. To create a release:

- Navigate to the actions tab
- Select the `npm bump` action.
- Trigger an action, specifying the semantic version bump that is needed.
- Changelog, Github release and npm publish is hanlded by the action.
- An in depth review of this system is documented here: [bret.io/projects/package-automation](https://bret.io/projects/package-automation/)

If for some reason that isn't workoing or a local release is preferred, follow these steps:

- Ensure a clean working git workspace.
- Run `npm version {patch,minor,major}`.
- This wills update the version number and generate the changelog.
- Run `npm publish`.
- This will push your local git branch and tags to the default remote, perform a [gh-release](https://ghub.io/gh-release), and create an npm publication
13 changes: 13 additions & 0 deletions examples/nested-dest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Nested dest

One of the design goals of `siteup` was to allow you to point `siteup` at a generic
library repository, and render out all of the markdown inside of it, into a `dest` folder.

The issue with this is that `dest` folder essentially lives inside of the `src` folder,
so it was important to support sane ignore patterns by default so you don't fall into a recursive render
loop, or try to render out `node_modules` etc.

This example site points `siteup` at the root of the example `/`, and builds into `/public`, so its a good
example how hoe flexible siteup can be.

boop beep
4 changes: 4 additions & 0 deletions examples/nested-dest/global.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@import 'mine.css';
@import 'mine.css/dist/layout.css';

/* Just consuming some dependencies for the nested example */
4 changes: 4 additions & 0 deletions examples/nested-dest/global.vars.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default {
defaultStyle: false,
siteName: 'nested siteup example'
}
3 changes: 3 additions & 0 deletions examples/nested-dest/ignore/ignore-me.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Ignore me

This file should not be rendered.
17 changes: 17 additions & 0 deletions examples/nested-dest/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "default-layout",
"version": "0.0.0",
"description": "",
"type": "module",
"scripts": {
"build": "siteup --src . --dest public --ignore ignore"
},
"keywords": [],
"author": "Bret Comnes <bcomnes@gmail.com> (https://bret.io/)",
"license": "MIT",
"devDependencies": {
"@siteup/cli": "../../.",
"mine.css": "^4.6.1",
"uhtml-isomorphic": "^1.0.1"
}
}
25 changes: 20 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import process from 'node:process'
import { once } from 'events'
import assert from 'webassert'
import chokidar from 'chokidar'
import { basename, relative } from 'node:path'
import makeArray from 'make-array'
import ignore from 'ignore'

import { build } from './lib/builder.js'

Expand All @@ -10,6 +13,10 @@ export class Siteup {
assert(src, 'src is a required argument')
assert(dest, 'dest is a required argument')

const defaultIgnore = ['.*', 'node_modules', basename(dest)]

opts.ignore = defaultIgnore.concat(makeArray(opts.ignore))

this._src = src
this._dest = dest
this._cwd = cwd
Expand All @@ -25,15 +32,19 @@ export class Siteup {
}

build () {
return build(this._src, this._dest)
return build(this._src, this._dest, this.opts)
}

async watch () {
if (this.watching) throw new Error('Already watching.')
const results = await build(this._src, this._dest)
const results = await build(this._src, this._dest, this.opts)
console.log(this.opts.ignore)
const ig = ignore().add(this.opts.ignore)

const anymatch = name => ig.ignores(relname(this._src, name))

const watcher = chokidar.watch(this._src, {
ignored: /(^|[/\\])\../, // ignore dotfiles
ignored: anymatch,
persistent: true
})

Expand All @@ -43,11 +54,11 @@ export class Siteup {

watcher.on('add', path => {
console.log(`File ${path} has been added`)
build(this._src, this._dest)
build(this._src, this._dest, this.opts)
})
watcher.on('change', path => {
console.log(`File ${path} has been changed`)
build(this._src, this._dest)
build(this._src, this._dest, this.opts)
})
watcher.on('unlink', path => {
console.log(`File ${path} has been removed`)
Expand All @@ -64,3 +75,7 @@ export class Siteup {
this._watcher = null
}
}

function relname (root, name) {
return root === name ? basename(name) : relative(root, name)
}
4 changes: 2 additions & 2 deletions lib/build-static/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const copy = promisify(cpx.copy)
* @param {[type]} dest [description]
* @return {[type]} [description]
*/
export function buildStatic (src, dest) {
export function buildStatic (src, dest, opts = {}) {
const glob = `${src}/**/*.{png,svg,jpg,jpeg,pdf,mp4,mp3,json,gif}`
return copy(glob, dest)
return copy(glob, dest, { ignore: opts.ignore })
}
6 changes: 3 additions & 3 deletions lib/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { buildJs } from './build-js/index.js'
* @param {[type]} dest [description]
* @return {[type]} [description]
*/
export async function build (src, dest) {
const siteData = await identifyPages(src, pageBuilders)
export async function build (src, dest, opts = {}) {
const siteData = await identifyPages(src, pageBuilders, { ignore: opts.ignore })

// TODO: we need an improved reporting mechanism. Logging for now
for (const warning of siteData.warnings) {
Expand All @@ -24,7 +24,7 @@ export async function build (src, dest) {
await ensureDest(src, dest, siteData)

const results = await Promise.all([
buildStatic(src, dest),
buildStatic(src, dest, { ignore: opts.ignore }),
buildPages(src, dest, siteData),
buildCss(src, dest, siteData),
buildJs(src, dest, siteData)
Expand Down
2 changes: 1 addition & 1 deletion lib/defaults/default.root.layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function defaultRootLayout ({
<html>
<head>
<meta charset="utf-8">
<title>${siteName}${title ? ` | ${title}` : ''}</title>
<title>${title ? `${title}` : ''}${title && siteName ? ' | ' : ''}${siteName}</title>
<meta name="viewport" content="width=device-width, user-scalable=no" />
${scripts
? scripts.map(script => html`<script type='module' src="${script}"></script>`)
Expand Down
4 changes: 2 additions & 2 deletions lib/identify-pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ const __dirname = desm(import.meta.url)
* @param {string} src The string path of the src folder of the website to build.
* @return {object} The object containing page info
*/
export async function identifyPages (src, pageBuilders) {
export async function identifyPages (src, pageBuilders, opts = {}) {
assert(src, 'a src argument is required')
assert(pageBuilders, 'a pageBuilders argument is required')
const walker = asyncFolderWalker([src], {
statFilter: st => !st.isDirectory(),
ignore: opts.ignore,
shaper: ({
root,
filepath,
Expand Down Expand Up @@ -128,6 +129,5 @@ export async function identifyPages (src, pageBuilders) {
// allFiles: dirs
}


return results
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"esbuild": "^0.12.15",
"js-yaml": "^4.1.0",
"local-storage-proxy": "^3.0.3",
"make-array": "^1.0.5",
"markdown-it": "^12.2.0",
"markdown-it-abbr": "^1.0.4",
"markdown-it-deflist": "^2.1.0",
Expand All @@ -34,15 +35,15 @@
"markdown-it-mark": "^3.0.1",
"markdown-it-sub": "^1.0.0",
"markdown-it-sup": "^1.0.0",
"mine.css": "^4.6.1",
"minimist": "^1.2.5",
"postcss": "^8.3.6",
"postcss-import": "^14.0.2",
"postcss-nesting": "^8.0.1",
"postcss-url": "^10.1.3",
"pretty": "^2.0.0",
"uhtml-isomorphic": "^1.0.1",
"webassert": "^3.0.2",
"mine.css": "^4.6.1"
"webassert": "^3.0.2"
},
"devDependencies": {
"auto-changelog": "^2.0.0",
Expand Down

0 comments on commit 0f26da9

Please sign in to comment.