@npmcli/template-oss 4.1.2 → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/release-please.js +42 -28
- package/lib/apply/apply-files.js +1 -1
- package/lib/apply/index.js +1 -1
- package/lib/check/check-apply.js +5 -4
- package/lib/check/index.js +1 -1
- package/lib/config.js +178 -121
- package/lib/content/_job-matrix.yml +29 -0
- package/lib/content/_job.yml +8 -0
- package/lib/content/_on-ci.yml +30 -0
- package/lib/content/_step-checks.yml +24 -0
- package/lib/content/_step-deps.yml +2 -0
- package/lib/content/_step-git.yml +12 -0
- package/lib/content/_step-lint.yml +4 -0
- package/lib/content/{setup-node.yml → _step-node.yml} +12 -9
- package/lib/content/_step-test.yml +4 -0
- package/lib/content/_steps-setup.yml +6 -0
- package/lib/content/audit.yml +3 -6
- package/lib/content/ci-release.yml +31 -0
- package/lib/content/ci.yml +6 -54
- package/lib/content/codeql-analysis.yml +10 -17
- package/lib/content/commitlintrc.js +1 -1
- package/lib/content/dependabot.yml +2 -2
- package/lib/content/eslintrc.js +7 -0
- package/lib/content/gitignore +1 -14
- package/lib/content/index.js +62 -27
- package/lib/content/npmrc +1 -1
- package/lib/content/pkg.json +34 -14
- package/lib/content/post-dependabot.yml +55 -16
- package/lib/content/pull-request.yml +11 -13
- package/lib/content/release-please-config.json +5 -5
- package/lib/content/release-please-manifest.json +1 -1
- package/lib/content/release.yml +125 -0
- package/lib/index.js +27 -30
- package/lib/release-please/index.js +26 -5
- package/lib/util/files.js +71 -27
- package/lib/util/gitignore.js +34 -0
- package/lib/util/merge.js +21 -0
- package/lib/util/parser.js +76 -18
- package/lib/util/template.js +30 -21
- package/package.json +7 -2
- package/lib/content/release-please.yml +0 -73
- package/lib/content/release-test.yml +0 -46
- package/lib/content/setup-deps.yml +0 -1
- package/lib/content/setup-git.yml +0 -11
package/lib/util/template.js
CHANGED
|
@@ -3,35 +3,44 @@ const { basename, extname, join } = require('path')
|
|
|
3
3
|
const fs = require('fs')
|
|
4
4
|
const DELETE = '__DELETE__'
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
6
|
+
const safeValues = (obj) => Object.entries(obj).map(([key, value]) =>
|
|
7
|
+
[key, new Handlebars.SafeString(value)])
|
|
8
|
+
|
|
9
|
+
const partialName = (s) => basename(s, extname(s)) // remove extension
|
|
10
|
+
.replace(/^_/, '') // remove leading underscore
|
|
11
|
+
.replace(/-([a-z])/g, (_, g) => g.toUpperCase()) // camelcase
|
|
12
|
+
|
|
13
|
+
const setupHandlebars = (...partialDirs) => {
|
|
14
|
+
Handlebars.registerHelper('obj', ({ hash }) => Object.fromEntries(safeValues(hash)))
|
|
15
|
+
Handlebars.registerHelper('join', (arr, sep) => arr.join(typeof sep === 'string' ? sep : ', '))
|
|
16
|
+
Handlebars.registerHelper('pluck', (arr, key) => arr.map(a => a[key]))
|
|
17
|
+
Handlebars.registerHelper('quote', (arr) => arr.map(a => `'${a}'`))
|
|
18
|
+
Handlebars.registerHelper('last', (arr) => arr[arr.length - 1])
|
|
11
19
|
Handlebars.registerHelper('json', (c) => JSON.stringify(c))
|
|
12
20
|
Handlebars.registerHelper('del', () => JSON.stringify(DELETE))
|
|
13
21
|
|
|
14
|
-
// Load all
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
// Load all files as camelcase partial names.
|
|
23
|
+
// all other content dirs only get special underscore leading
|
|
24
|
+
// files as partials. this prevents recursion loops when overwriting
|
|
25
|
+
// a filename to use as a enw file
|
|
26
|
+
let isBase = true
|
|
27
|
+
for (const dir of partialDirs) {
|
|
28
|
+
for (const f of fs.readdirSync(dir)) {
|
|
29
|
+
if (f.startsWith('_') || isBase) {
|
|
30
|
+
Handlebars.registerPartial(
|
|
31
|
+
partialName(f),
|
|
32
|
+
fs.readFileSync(join(dir, f)).toString()
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
isBase = false
|
|
20
37
|
}
|
|
21
38
|
}
|
|
22
39
|
|
|
23
|
-
const cache = new Map()
|
|
24
|
-
|
|
25
40
|
const template = (str, { config, ...options }) => {
|
|
26
|
-
|
|
27
|
-
setupHandlebars(config.sourceDir)
|
|
28
|
-
}
|
|
41
|
+
setupHandlebars(...config.__PARTIAL_DIRS__)
|
|
29
42
|
|
|
30
|
-
|
|
31
|
-
if (t == null) {
|
|
32
|
-
t = Handlebars.compile(str, { strict: true })
|
|
33
|
-
cache.set(str, t)
|
|
34
|
-
}
|
|
43
|
+
const t = Handlebars.compile(str, { strict: true })
|
|
35
44
|
|
|
36
45
|
// merge in config as top level data in templates
|
|
37
46
|
return t({ ...options, ...config })
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@npmcli/template-oss",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.0",
|
|
4
4
|
"description": "templated files used in npm CLI team oss projects",
|
|
5
5
|
"main": "lib/content/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
"handlebars": "^4.7.7",
|
|
43
43
|
"hosted-git-info": "^5.0.0",
|
|
44
44
|
"json-parse-even-better-errors": "^2.3.1",
|
|
45
|
+
"just-deep-map-values": "^1.1.1",
|
|
45
46
|
"just-diff": "^5.0.1",
|
|
46
47
|
"lodash": "^4.17.21",
|
|
47
48
|
"npm-package-arg": "^9.0.1",
|
|
@@ -60,7 +61,11 @@
|
|
|
60
61
|
"tap": "^16.0.0"
|
|
61
62
|
},
|
|
62
63
|
"tap": {
|
|
63
|
-
"timeout": 600
|
|
64
|
+
"timeout": 600,
|
|
65
|
+
"nyc-arg": [
|
|
66
|
+
"--exclude",
|
|
67
|
+
"tap-snapshots/**"
|
|
68
|
+
]
|
|
64
69
|
},
|
|
65
70
|
"templateOSS": {
|
|
66
71
|
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten."
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
name: Release Please
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches:
|
|
6
|
-
{{#each branches}}
|
|
7
|
-
- {{.}}
|
|
8
|
-
{{/each}}
|
|
9
|
-
{{#each releaseBranches}}
|
|
10
|
-
- {{.}}
|
|
11
|
-
{{/each}}
|
|
12
|
-
|
|
13
|
-
permissions:
|
|
14
|
-
contents: write
|
|
15
|
-
pull-requests: write
|
|
16
|
-
|
|
17
|
-
jobs:
|
|
18
|
-
release-please:
|
|
19
|
-
runs-on: ubuntu-latest
|
|
20
|
-
outputs:
|
|
21
|
-
pr: $\{{ steps.release.outputs.pr }}
|
|
22
|
-
release: $\{{ steps.release.outputs.release }}
|
|
23
|
-
steps:
|
|
24
|
-
{{> setupGit}}
|
|
25
|
-
{{> setupNode}}
|
|
26
|
-
{{> setupDeps}}
|
|
27
|
-
- name: Release Please
|
|
28
|
-
id: release
|
|
29
|
-
run: npx --offline template-oss-release-please $\{{ github.ref_name }}
|
|
30
|
-
env:
|
|
31
|
-
GITHUB_TOKEN: $\{{ secrets.GITHUB_TOKEN }}
|
|
32
|
-
|
|
33
|
-
post-pr:
|
|
34
|
-
needs: release-please
|
|
35
|
-
if: needs.release-please.outputs.pr
|
|
36
|
-
runs-on: ubuntu-latest
|
|
37
|
-
outputs:
|
|
38
|
-
ref: $\{{ steps.ref.outputs.branch }}
|
|
39
|
-
steps:
|
|
40
|
-
- name: Output ref
|
|
41
|
-
id: ref
|
|
42
|
-
run: echo "::set-output name=branch::$\{{ fromJSON(needs.release-please.outputs.pr).headBranchName }}"
|
|
43
|
-
{{> setupGit with=(obj ref="${{ steps.ref.outputs.branch }}" fetch-depth=0)}}
|
|
44
|
-
{{> setupNode}}
|
|
45
|
-
{{> setupDeps}}
|
|
46
|
-
- name: Post pull request actions
|
|
47
|
-
env:
|
|
48
|
-
GITHUB_TOKEN: $\{{ secrets.GITHUB_TOKEN }}
|
|
49
|
-
run: |
|
|
50
|
-
npm run rp-pull-request --ignore-scripts --if-present -ws -iwr
|
|
51
|
-
git commit -am "chore: post pull request" || true
|
|
52
|
-
git push
|
|
53
|
-
|
|
54
|
-
release-test:
|
|
55
|
-
needs: post-pr
|
|
56
|
-
if: needs.post-pr.outputs.ref
|
|
57
|
-
uses: ./.github/workflows/{{releaseTest}}
|
|
58
|
-
with:
|
|
59
|
-
ref: $\{{ needs.post-pr.outputs.ref }}
|
|
60
|
-
|
|
61
|
-
post-release:
|
|
62
|
-
needs: release-please
|
|
63
|
-
if: needs.release-please.outputs.release
|
|
64
|
-
runs-on: ubuntu-latest
|
|
65
|
-
steps:
|
|
66
|
-
{{> setupGit}}
|
|
67
|
-
{{> setupNode}}
|
|
68
|
-
{{> setupDeps}}
|
|
69
|
-
- name: Post release actions
|
|
70
|
-
env:
|
|
71
|
-
GITHUB_TOKEN: $\{{ secrets.GITHUB_TOKEN }}
|
|
72
|
-
run: |
|
|
73
|
-
npm run rp-release --ignore-scripts --if-present -ws -iwr
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
name: Release
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
workflow_call:
|
|
5
|
-
inputs:
|
|
6
|
-
ref:
|
|
7
|
-
required: true
|
|
8
|
-
type: string
|
|
9
|
-
|
|
10
|
-
jobs:
|
|
11
|
-
lint-all:
|
|
12
|
-
runs-on: ubuntu-latest
|
|
13
|
-
steps:
|
|
14
|
-
{{> setupGit with=(obj ref="${{ inputs.ref }}")}}
|
|
15
|
-
{{> setupNode}}
|
|
16
|
-
{{> setupDeps}}
|
|
17
|
-
- run: npm run lint --if-present --workspaces --include-workspace-root
|
|
18
|
-
|
|
19
|
-
test-all:
|
|
20
|
-
strategy:
|
|
21
|
-
fail-fast: false
|
|
22
|
-
matrix:
|
|
23
|
-
node-version:
|
|
24
|
-
{{#each ciVersions}}
|
|
25
|
-
- {{.}}
|
|
26
|
-
{{/each}}
|
|
27
|
-
platform:
|
|
28
|
-
- os: ubuntu-latest
|
|
29
|
-
shell: bash
|
|
30
|
-
- os: macos-latest
|
|
31
|
-
shell: bash
|
|
32
|
-
{{#if windowsCI}}
|
|
33
|
-
- os: windows-latest
|
|
34
|
-
shell: cmd
|
|
35
|
-
{{/if}}
|
|
36
|
-
runs-on: $\{{ matrix.platform.os }}
|
|
37
|
-
defaults:
|
|
38
|
-
run:
|
|
39
|
-
shell: $\{{ matrix.platform.shell }}
|
|
40
|
-
steps:
|
|
41
|
-
{{> setupGit with=(obj ref="${{ inputs.ref }}")}}
|
|
42
|
-
{{> setupNode useMatrix=true}}
|
|
43
|
-
{{> setupDeps}}
|
|
44
|
-
- name: add tap problem matcher
|
|
45
|
-
run: echo "::add-matcher::.github/matchers/tap.json"
|
|
46
|
-
- run: npm run test --if-present --workspaces --include-workspace-root
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
- run: npm i --ignore-scripts --no-audit --no-fund {{~#if flags}} {{flags}}{{/if}}
|