Skip to content

Commit

Permalink
fix: add suffix to template files (#362)
Browse files Browse the repository at this point in the history
Add `.hbs` as a suffix to all Handlebars template files.
  • Loading branch information
rotu committed Nov 6, 2023
1 parent ebb48ec commit 3e1792c
Show file tree
Hide file tree
Showing 44 changed files with 92 additions and 98 deletions.
6 changes: 0 additions & 6 deletions .eslintrc.local.json

This file was deleted.

22 changes: 11 additions & 11 deletions README.md
Expand Up @@ -3,7 +3,7 @@
This module bundles the npm CLI team's basics for package development into a
single devDependency.

**CAUTION: THESE CHANGES WILL OVERWRITE ANY LOCAL FILES AND SETTINGS**
**CAUTION: THESE CHANGES WILL OVERWRITE LOCAL FILES AND SETTINGS**

### Configuration

Expand Down Expand Up @@ -60,29 +60,29 @@ any of the same settings in the root.
### Content

All the templated content for this repo lives in
[`lib/content/`](./lib/content/). The `index.js`[./lib/content/index.js] file
[`lib/content/`](./lib/content/). The [`index.js`](./lib/content/index.js) file
controls how and where this content is written.

Content files can be overwritten or merged with the existing target file.
Currently mergining is only supported for `package.json` files.
Merging is only supported for some types of files (ini, yaml, json, package.json)

Each content file goes through the following pipeline:

1. It is read from its source location
1. It is are templated using Handlebars with the variables from each packages's
config (with some derived values generated in [`config.js`](./lib/config.js)
1. It is parsed based on its file extension in
2. It is compiled using [Handlebars](https://handlebarsjs.com/) with the variables from each packages's
config (with some derived values generated in [`config.js`](./lib/config.js))
3. It is parsed based on its file extension in
[`parser.js`](./lib/util/parser.js)
1. Additional logic is applied by the parser
1. It is written to its target location
4. Additional logic is applied by the parser
5. It is written to its target location

### Usage

This package provides two bin scripts:

#### `template-oss-check`

This will check if any of the applied files different from the target content,
This will check if any of the applied files differ from the target content,
or if any of the other associated checks fail. The diffs of each file or check
will be reported with instructions on how to fix it.

Expand All @@ -92,15 +92,15 @@ This will write all source files to their target locations in the cwd. It will
do nothing if `package.json#templateOSS.version` is the same as the version
being run. This can be overridden by `--force`.

This is the script that is run on `postinsall`.
This is the script that is run on `postinstall`.

### Extending

#### `lib/apply`

This directory is where all the logic for applying files lives. It should be
possible to add new files without modifying anything in this directory. To add a
file, add the templated file to `lib/content/$FILENAME` and add entry for it in
file, add the templated file to `lib/content/$FILENAME` and an entry for it in
`lib/content/index.js` depending on where and when it should be written (root vs
workspace, repo vs module, add vs remove, etc).

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -26,4 +26,4 @@ defaults:
run:
shell: $\{{ matrix.platform.shell }}
steps:
{{> stepsSetup jobIsMatrix=true }}
{{> stepsSetupYml jobIsMatrix=true }}
Expand Up @@ -29,7 +29,7 @@ defaults:
run:
shell: bash
steps:
{{> stepNode lockfile=false }}
{{> stepNodeYml lockfile=false }}
- name: View in Registry
run: |
EXIT_CODE=0
Expand Down
2 changes: 1 addition & 1 deletion lib/content/_job.yml → lib/content/_job-yml.hbs
Expand Up @@ -5,4 +5,4 @@ defaults:
run:
shell: bash
steps:
{{> stepsSetup }}
{{> stepsSetupYml }}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions lib/content/_steps-setup-yml.hbs
@@ -0,0 +1,6 @@
{{~#if jobCheck}}{{> stepChecksYml }}{{/if}}
{{~#unless jobSkipSetup}}
{{> stepGitYml }}
{{> stepNodeYml }}
{{> stepDepsYml }}
{{/unless}}
6 changes: 0 additions & 6 deletions lib/content/_steps-setup.yml

This file was deleted.

4 changes: 2 additions & 2 deletions lib/content/audit.yml → lib/content/audit-yml.hbs
Expand Up @@ -8,5 +8,5 @@ on:

jobs:
audit:
{{> job jobName="Audit Dependencies" jobDepFlags="--package-lock" }}
{{> stepAudit }}
{{> jobYml jobName="Audit Dependencies" jobDepFlags="--package-lock" }}
{{> stepAuditYml }}
File renamed without changes.
12 changes: 6 additions & 6 deletions lib/content/ci-release.yml → lib/content/ci-release-yml.hbs
Expand Up @@ -19,19 +19,19 @@ on:

jobs:
lint-all:
{{> job
{{> jobYml
jobName="Lint All"
jobCheck=(obj sha="inputs.check-sha")
jobCheckout=(obj ref="${{ inputs.ref }}")
}}
{{> stepLint jobRunFlags=allFlags }}
{{> stepChecks jobCheck=true }}
{{> stepLintYml jobRunFlags=allFlags }}
{{> stepChecksYml jobCheck=true }}

test-all:
{{> jobMatrix
{{> jobMatrixYml
jobName="Test All"
jobCheck=(obj sha="inputs.check-sha")
jobCheckout=(obj ref="${{ inputs.ref }}")
}}
{{> stepTest jobRunFlags=allFlags }}
{{> stepChecks jobCheck=true }}
{{> stepTestYml jobRunFlags=allFlags }}
{{> stepChecksYml jobCheck=true }}
13 changes: 13 additions & 0 deletions lib/content/ci-yml.hbs
@@ -0,0 +1,13 @@
name: CI {{~#if isWorkspace}} - {{ pkgName }}{{/if}}

on:
{{> onCiYml }}

jobs:
lint:
{{> jobYml jobName="Lint" }}
{{> stepLintYml jobRunFlags=pkgFlags }}

test:
{{> jobMatrixYml jobName="Test" }}
{{> stepTestYml jobRunFlags=pkgFlags }}
13 changes: 0 additions & 13 deletions lib/content/ci.yml

This file was deleted.

Expand Up @@ -24,7 +24,7 @@ jobs:
contents: read
security-events: write
steps:
{{> stepGit }}
{{> stepGitYml }}
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
52 changes: 26 additions & 26 deletions lib/content/index.js
Expand Up @@ -5,46 +5,46 @@ const isPublic = (p) => p.config.isPublic
const sharedRootAdd = (name) => ({
// release
'.github/workflows/release.yml': {
file: 'release.yml',
file: 'release-yml.hbs',
filter: isPublic,
},
'.github/workflows/ci-release.yml': {
file: 'ci-release.yml',
file: 'ci-release-yml.hbs',
filter: isPublic,
},
'.release-please-manifest.json': {
file: 'release-please-manifest.json',
file: 'release-please-manifest-json.hbs',
filter: isPublic,
parser: (p) => class extends p.JsonMerge {
comment = null
},
},
'release-please-config.json': {
file: 'release-please-config.json',
file: 'release-please-config-json.hbs',
filter: isPublic,
parser: (p) => class extends p.JsonMerge {
comment = null
},
},
// this lint commits which is only necessary for releases
'.github/workflows/pull-request.yml': {
file: 'pull-request.yml',
file: 'pull-request-yml.hbs',
filter: isPublic,
},
// ci
'.github/matchers/tap.json': 'tap.json',
[`.github/workflows/ci${name ? `-${name}` : ''}.yml`]: 'ci.yml',
'.github/matchers/tap.json': 'tap-json.hbs',
[`.github/workflows/ci${name ? `-${name}` : ''}.yml`]: 'ci-yml.hbs',
// dependabot
'.github/dependabot.yml': {
file: 'dependabot.yml',
file: 'dependabot-yml.hbs',
filter: (p) => p.config.dependabot,
},
'.github/workflows/post-dependabot.yml': {
file: 'post-dependabot.yml',
file: 'post-dependabot-yml.hbs',
filter: (p) => p.config.dependabot,
},
'.github/settings.yml': {
file: 'settings.yml',
file: 'settings-yml.hbs',
filter: (p) => !p.config.isReleaseBranch,
},
})
Expand All @@ -61,12 +61,12 @@ const sharedRootRm = () => ({
// Changes applied to the root of the repo
const rootRepo = {
add: {
'.commitlintrc.js': 'commitlintrc.js',
'.github/ISSUE_TEMPLATE/bug.yml': 'bug.yml',
'.github/ISSUE_TEMPLATE/config.yml': 'config.yml',
'.github/CODEOWNERS': 'CODEOWNERS',
'.github/workflows/audit.yml': 'audit.yml',
'.github/workflows/codeql-analysis.yml': 'codeql-analysis.yml',
'.commitlintrc.js': 'commitlintrc-js.hbs',
'.github/ISSUE_TEMPLATE/bug.yml': 'bug-yml.hbs',
'.github/ISSUE_TEMPLATE/config.yml': 'config-yml.hbs',
'.github/CODEOWNERS': 'CODEOWNERS.hbs',
'.github/workflows/audit.yml': 'audit-yml.hbs',
'.github/workflows/codeql-analysis.yml': 'codeql-analysis-yml.hbs',
...sharedRootAdd(),
},
rm: {
Expand All @@ -84,15 +84,15 @@ const rootRepo = {
const rootModule = {
add: {
'.eslintrc.js': {
file: 'eslintrc.js',
file: 'eslintrc-js.hbs',
filter: (p) => p.config.eslint,
},
'.gitignore': 'gitignore',
'.npmrc': 'npmrc',
'SECURITY.md': 'SECURITY.md',
'CODE_OF_CONDUCT.md': 'CODE_OF_CONDUCT.md',
'CONTRIBUTING.md': 'CONTRIBUTING.md',
'package.json': 'pkg.json',
'.gitignore': 'gitignore.hbs',
'.npmrc': 'npmrc.hbs',
'SECURITY.md': 'SECURITY-md.hbs',
'CODE_OF_CONDUCT.md': 'CODE_OF_CONDUCT-md.hbs',
'CONTRIBUTING.md': 'CONTRIBUTING-md.hbs',
'package.json': 'package-json.hbs',
},
rm: [
'.eslintrc.!(js|local.*)',
Expand All @@ -115,11 +115,11 @@ const workspaceRepo = {
const workspaceModule = {
add: {
'.eslintrc.js': {
file: 'eslintrc.js',
file: 'eslintrc-js.hbs',
filter: (p) => p.config.eslint,
},
'.gitignore': 'gitignore',
'package.json': 'pkg.json',
'.gitignore': 'gitignore.hbs',
'package.json': 'package-json.hbs',
},
rm: [
'.npmrc',
Expand Down
File renamed without changes.
File renamed without changes.
Expand Up @@ -8,7 +8,7 @@ permissions:

jobs:
template-oss:
{{> job
{{> jobYml
jobName="template-oss"
jobIf="github.actor == 'dependabot[bot]'"
jobCheckout=(obj ref="${{ github.event.pull_request.head.ref }}")
Expand Down
Expand Up @@ -10,7 +10,7 @@ on:

jobs:
commitlint:
{{> job jobName="Lint Commits" jobCheckout=(obj fetch-depth=0) }}
{{> jobYml jobName="Lint Commits" jobCheckout=(obj fetch-depth=0) }}
- name: Run Commitlint on Commits
id: commit
continue-on-error: true
Expand Down
File renamed without changes.
File renamed without changes.
20 changes: 10 additions & 10 deletions lib/content/release.yml → lib/content/release-yml.hbs
Expand Up @@ -27,7 +27,7 @@ jobs:
pr-number: $\{{ steps.release.outputs.pr-number }}
comment-id: $\{{ steps.pr-comment.outputs.result }}
check-id: $\{{ steps.check.outputs.check_id }}
{{> job jobName="Release" }}
{{> jobYml jobName="Release" }}
- name: Release Please
id: release
env:
Expand Down Expand Up @@ -66,14 +66,14 @@ jobs:
}

return commentId
{{> stepChecks jobCheck=(obj name="Release" sha="steps.release.outputs.pr-sha") }}
{{> stepChecksYml jobCheck=(obj name="Release" sha="steps.release.outputs.pr-sha") }}

update:
needs: release
outputs:
sha: $\{{ steps.commit.outputs.sha }}
check-id: $\{{ steps.check.outputs.check_id }}
{{> job
{{> jobYml
jobName="Update - Release"
jobIf="needs.release.outputs.pr"
jobCheckout=(obj ref="${{ needs.release.outputs.branch }}" fetch-depth=0)
Expand All @@ -94,8 +94,8 @@ jobs:
git commit --all --amend --no-edit || true
git push --force-with-lease
echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
{{> stepChecks jobName="Update - Release" jobCheck=(obj sha="steps.commit.outputs.sha" name="Release" )}}
{{> stepChecks jobCheck=(obj id="needs.release.outputs.check-id" )}}
{{> stepChecksYml jobName="Update - Release" jobCheck=(obj sha="steps.commit.outputs.sha" name="Release" )}}
{{> stepChecksYml jobCheck=(obj id="needs.release.outputs.check-id" )}}

ci:
name: CI - Release
Expand All @@ -108,7 +108,7 @@ jobs:

post-ci:
needs: [release, update, ci]
{{> job jobName="Post CI - Release" jobIf="needs.release.outputs.pr && always()" jobSkipSetup=true }}
{{> jobYml jobName="Post CI - Release" jobIf="needs.release.outputs.pr && always()" jobSkipSetup=true }}
- name: Get Needs Result
id: needs-result
run: |
Expand All @@ -121,11 +121,11 @@ jobs:
result="success"
fi
echo "result=$result" >> $GITHUB_OUTPUT
{{> stepChecks jobCheck=(obj id="needs.update.outputs.check-id" status="steps.needs-result.outputs.result") }}
{{> stepChecksYml jobCheck=(obj id="needs.update.outputs.check-id" status="steps.needs-result.outputs.result") }}

post-release:
needs: release
{{> job jobName="Post Release - Release" jobIf="needs.release.outputs.releases" jobSkipSetup=true }}
{{> jobYml jobName="Post Release - Release" jobIf="needs.release.outputs.releases" jobSkipSetup=true }}
- name: Create Release PR Comment
uses: actions/github-script@v6
env:
Expand Down Expand Up @@ -163,11 +163,11 @@ jobs:
needs: release
name: Release Integration
if: needs.release.outputs.release
{{> jobReleaseIntegration }}
{{> jobReleaseIntegrationYml }}

post-release-integration:
needs: [release, release-integration]
{{> job jobName="Post Release Integration - Release" jobIf="needs.release.outputs.release && always()" jobSkipSetup=true }}
{{> jobYml jobName="Post Release Integration - Release" jobIf="needs.release.outputs.release && always()" jobSkipSetup=true }}
- name: Get Needs Result
id: needs-result
run: |
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions test/apply/allow-paths.js
Expand Up @@ -34,8 +34,8 @@ t.test('works with custom content', async (t) => {
},
testdir: {
content_dir: {
'paths.json': '{{{json allowPaths}}}',
'index.js': 'module.exports={rootRepo:{add:{"paths.json":"paths.json"}}}',
'paths-json.hbs': '{{{json allowPaths}}}',
'index.js': 'module.exports={rootRepo:{add:{"paths.json":"paths-json.hbs"}}}',
},
},
})
Expand Down

0 comments on commit 3e1792c

Please sign in to comment.