Skip to content

Commit

Permalink
v2.0.0: Refactor, New Features, etc. (#113)
Browse files Browse the repository at this point in the history
* Refactor CI workflow

* Update dev dependencies

* Add publishConfig to package.json

* Set current year in banner

* Specify lts/hydrogen as development version

* Set minimum supported Node.js version

* Use JSDoc syntax in banner comments

* Remove dist folder and gitignore it

* Regenerate lockfile

* Specify files to be in published tarball

* Point to src files in example and test

* Remove CONTRIBUTING.md

* Formatting and name changes and whatnot

* Add test against null textContent value

* Add support for null textContent

* Document support for null textContent

* Add more insertion non-Object tests

* S E M I C O L O N S

* Properly check insertions argument type

* Remove dist files

* Add and configure  concurrently and http-server

* Re-point example and spec at built dist files

* Use Array.isArray()

* Add another spec

* Add commit message prefixes to Dependabot config

* Add CHANGELOG.md

* Rebuild lockfile

* Refactor ESLint config file

* Add publish workflow

* Bump version and update CHANGELOG
  • Loading branch information
jgarber623 authored Sep 27, 2023
1 parent 2df6cf6 commit 68c6f49
Show file tree
Hide file tree
Showing 17 changed files with 1,193 additions and 526 deletions.
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ updates:
interval: "weekly"
assignees:
- "jgarber623"
commit-message:
prefix: "ci"
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "monthly"
assignees:
- "jgarber623"
commit-message:
prefix: "chore"
35 changes: 5 additions & 30 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
name: CI

on: [push, pull_request]
on:
pull_request:
workflow_call:
workflow_dispatch:

jobs:
analyze:
name: Analyze
permissions:
contents: read
security-events: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: github/codeql-action/init@v2
with:
languages: javascript
- uses: github/codeql-action/analyze@v2
lint:
name: Lint
runs-on: ubuntu-latest
Expand All @@ -26,25 +17,9 @@ jobs:
cache: npm
- run: npm ci
- run: npm run lint
build:
name: Build
needs: [analyze, lint]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version-file: ".nvmrc"
cache: npm
- run: npm ci
- run: npm run build
- name: Check for changed files
run: |
git status
git diff --quiet
test:
name: Test
needs: build
needs: lint
runs-on: macos-latest
strategy:
matrix:
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Publish

on:
release:
types: [published]

jobs:
ci:
name: CI
uses: ./.github/workflows/ci.yml
publish-to-npm:
name: Publish to npm
needs: ci
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version-file: ".nvmrc"
cache: npm
registry-url: https://registry.npmjs.org
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
publish-to-github-packages:
name: Publish to GitHub Packages
permissions:
contents: read
packages: write
needs: ci
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version-file: ".nvmrc"
cache: npm
registry-url: https://npm.pkg.github.com
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
/dist/
/node_modules/
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
lts/*
lts/hydrogen
33 changes: 33 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Changelog

## 2.0.0 (2023-09-27)

- 46460b8 chore: Add publish workflow
- 1085936 chore: Refactor ESLint config file
- 65f3092 chore: Rebuild lockfile
- 5e1092b docs: Add CHANGELOG.md
- a239fb8 chore: Add commit message prefixes to Dependabot config
- 625576c chore: Add another spec
- 849b1af feat: Use Array.isArray()
- 5a701e7 chore: Re-point example and spec at built dist files
- 8e39544 chore: Add and configure concurrently and http-server
- 230245e chore: Remove dist files
- 68d8081 fix: Properly check insertions argument type
- 3bd434d fix: S E M I C O L O N S
- 5fcd652 chore: Add more insertion non-Object tests
- 6d418c3 docs: Document support for null textContent
- fbbf654 feat: Add support for null textContent
- 426d9e3 chore: Add test against null textContent value
- 199f5e9 chore: Formatting and name changes and whatnot
- 76609b0 docs: Remove CONTRIBUTING.md
- 86d5de5 chore: Point to src files in example and test
- 8800f79 chore: Specify files to be in published tarball
- 7bcbbba chore: Regenerate lockfile
- e90dce4 chore: Remove dist folder and gitignore it
- c614555 docs: Use JSDoc syntax in banner comments
- 80db616 breaking: Set minimum supported Node.js version
- 51ef4a6 chore: Specify lts/hydrogen as development version
- f8a38d0 chore: Set current year in banner
- 3bb1f3b chore: Add publishConfig to package.json
- 1082b37 chore: Update dev dependencies
- 098a32d chore: Refactor CI workflow
55 changes: 0 additions & 55 deletions CONTRIBUTING.md

This file was deleted.

58 changes: 30 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

- Uses established Web standards (e.g. `<template>`, `document.querySelector`)
- Dependency-free
- ES2015/AMD/Node module support
- ESM/CommonJS/AMD module support

## Getting TemplateTemplate

You've got a couple options for adding TemplateTemplate to your project:

- [Download a tagged version](https://github.com/jgarber623/TemplateTemplate/tags) from GitHub and do it yourself _(old school)_.
- [Download a release](https://github.com/jgarber623/TemplateTemplate/releases) from GitHub and do it yourself _(old school)_.
- Install using [npm](https://www.npmjs.com/package/@jgarber/templatetemplate): `npm install @jgarber/templatetemplate --save`
- Install using [Yarn](https://yarnpkg.com/en/package/@jgarber/templatetemplate): `yarn add @jgarber/templatetemplate`

Expand Down Expand Up @@ -111,15 +111,19 @@ A more complex example, inserting a row into a `<table>` with different types of
tbody.appendChild(
TemplateTemplate('#row-template', {
'th': 'CashCash',
tr: [null, {
class: 'project',
id: 'project-cashcash'
}],
th: 'CashCash',
'th + td': anchor,
'.url': ['https://github.com/jgarber623/CashCash', {
'style': 'font-style: italic;'
style: 'font-style: italic;'
}],
'td:last-child': TemplateTemplate('#anchor-template', {
'a': ['JavaScript', {
'href': 'https://github.com/search?q=language%3AJavaScript',
'target': '_blank'
a: ['JavaScript', {
href: 'https://github.com/search?q=language%3AJavaScript',
target: '_blank'
}]
})
})
Expand All @@ -132,26 +136,33 @@ The example above demonstrates a handful of additional features that you may fin
```js
// The first argument to TemplateTemplate may also be a valid CSS selector.
TemplateTemplate('#row-template', {
'th': 'CashCash',
// When an array is passed as a value, TemplateTemplate will use the first
// index in the array as the `textContent` for the node. If this value is
// `null`, TemplateTemplate skips setting the node's `textContent`.
//
// The second index is a hash of key/value pairs which are added to the node
// as HTML attributes.
tr: [null, {
class: 'project',
id: 'project-cashcash'
}],

th: 'CashCash',

// TemplateTemplate will use `appendChild` when given an instance of
// a `DocumentFragment` or an `HTMLElement`.
// TemplateTemplate will use `appendChild` when given an instance of a
// `DocumentFragment` or an `HTMLElement`.
'th + td': anchor,

// When an array is passed as a value, TemplateTemplate will use the
// first index in the array as the `textContent` for the node. The
// second index is a hash of key/value pairs which are added to the
// node as HTML attributes.
'.url': ['https://github.com/jgarber623/CashCash', {
'style': 'font-weight: bold;'
style: 'font-weight: bold;'
}],

// TemplateTemplate may also be used to generate content from another
// `<template>` and reuse it on the fly!
'td:last-child': TemplateTemplate('#anchor-template', {
'a': ['JavaScript', {
'href': 'https://github.com/search?q=language%3AJavaScript',
'target': '_blank'
a: ['JavaScript', {
href: 'https://github.com/search?q=language%3AJavaScript',
target: '_blank'
}]
})
})
Expand All @@ -163,16 +174,7 @@ For a full-featured TemplateTemplate demonstration, check out [the included exam

## Browser Support

TemplateTemplate works in modern browsers. The library makes use of several new(ish) JavaScript features, including:

- Arrow function expressions ([MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions))
- Template literals ([MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals))
- `Document.querySelector()` ([MDN](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector))
- `Document.importNode()` ([MDN](https://developer.mozilla.org/en-US/docs/Web/API/Document/importNode))
- `Object.entries()` ([MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries))
- `Array.prototype.forEach()` ([MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach))

TemplateTemplate, in an effort to remain as lightweight and dependency-free as possible, leaves it up to you to choose whether or not to polyfill features for older browsers.
**TemplateTemplate works in modern browsers.** The library makes use of several new(ish) JavaScript features and, in an effort to remain as lightweight and dependency-free as possible, leaves it up to you to choose whether or not to polyfill features for older browsers.

## Acknowledgments

Expand Down
41 changes: 0 additions & 41 deletions dist/templatetemplate.js

This file was deleted.

12 changes: 0 additions & 12 deletions dist/templatetemplate.min.js

This file was deleted.

Loading

0 comments on commit 68c6f49

Please sign in to comment.