Skip to content

Commit

Permalink
feat: add content config option to allow a module to set own content
Browse files Browse the repository at this point in the history
This also removes a lot of the redundant snapshot tests in favor of
testing the actual files written.

This also adds a few other features to allow `npm/cli` to use this in
the root workspace:

- set `npm` and `npx` paths in workflows via config
- dependabot now works with workspaces
- templated files now include more partials which can be overwritten
  with `content` directory config
- only file config options are merged between root and workspaces. this
  allows for the root to set config which will only apply to itself
- workspace paths are ignored from linting and testing in the root
  • Loading branch information
lukekarrys committed Sep 15, 2022
1 parent 423450f commit 849cecc
Show file tree
Hide file tree
Showing 63 changed files with 1,999 additions and 1,657 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ permissions:

jobs:
release-please:
runs-on: ubuntu-latest
outputs:
pr: ${{ steps.release.outputs.pr }}
release: ${{ steps.release.outputs.release }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup git user
Expand Down Expand Up @@ -73,7 +73,7 @@ jobs:
release-test:
needs: post-pr
if: needs.post-pr.outputs.ref
uses: ./.github/workflows/release-test.yml
uses: ./.github/workflows/release.yml
with:
ref: ${{ needs.post-pr.outputs.ref }}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
- run: npm -v
- run: npm i --ignore-scripts --no-audit --no-fund
- run: npm run lint --if-present --workspaces --include-workspace-root
- run: npm run lint -ws -iwr --if-present

test-all:
strategy:
Expand Down Expand Up @@ -83,4 +83,4 @@ jobs:
- run: npm i --ignore-scripts --no-audit --no-fund
- name: add tap problem matcher
run: echo "::add-matcher::.github/matchers/tap.json"
- run: npm run test --if-present --workspaces --include-workspace-root
- run: npm run test -ws -iwr --if-present
22 changes: 11 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@
/*

# keep these
!/.eslintrc.local.*
!**/.gitignore
!/docs/
!/tap-snapshots/
!/test/
!/map.js
!/scripts/
!/README*
!/LICENSE*
!/CHANGELOG*
!/.commitlintrc.js
!/.eslintrc.js
!/.eslintrc.local.*
!/.github/
!/.gitignore
!/.npmrc
!/.release-please-manifest.json
!/CODE_OF_CONDUCT.md
!/SECURITY.md
!/bin/
!/CHANGELOG*
!/CODE_OF_CONDUCT.md
!/docs/
!/lib/
!/LICENSE*
!/map.js
!/package.json
!/README*
!/release-please-config.json
!/scripts/
!/SECURITY.md
!/tap-snapshots/
!/test/
2 changes: 1 addition & 1 deletion lib/apply/apply-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const log = require('proc-log')
const { rmEach, parseEach } = require('../util/files.js')

const run = async (dir, files, options) => {
const { rm = [], add = {} } = files
const { rm, add } = files

log.verbose('apply-files', 'rm', rm)
await rmEach(dir, rm, options, (f) => fs.rm(f))
Expand Down
2 changes: 1 addition & 1 deletion lib/apply/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const run = require('../index.js')

module.exports = (root, content) => run(root, content, [
module.exports = (root) => run(root, [
require('./apply-files.js'),
require('./apply-version.js'),
])
9 changes: 5 additions & 4 deletions lib/check/check-apply.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ const log = require('proc-log')
const { relative, basename } = require('path')
const { rmEach, parseEach } = require('../util/files.js')
const { partition } = require('lodash')
const localeCompare = require('@isaacs/string-locale-compare')('en')

const solution = 'npx template-oss-apply --force'

const run = async (type, dir, files, options) => {
const res = []
const rel = (f) => relative(options.root, f)
const { add: addFiles = {}, rm: rmFiles = [] } = files
const { add: addFiles, rm: rmFiles } = files

const rm = await rmEach(dir, rmFiles, options, (f) => rel(f))
const [add, update] = partition(await parseEach(dir, addFiles, options, async (p) => {
Expand All @@ -28,7 +29,7 @@ const run = async (type, dir, files, options) => {
if (rm.length) {
res.push({
title: `The following ${type} files need to be deleted:`,
body: rm,
body: rm.sort(localeCompare),
solution,
})
}
Expand All @@ -37,13 +38,13 @@ const run = async (type, dir, files, options) => {
if (add.length) {
res.push({
title: `The following ${type} files need to be added:`,
body: add,
body: add.sort(localeCompare),
solution,
})
}

log.verbose('check-apply', 'update', update)
res.push(...update.map(({ file, diff }) => ({
res.push(...update.sort((a, b) => localeCompare(a.file, b.file)).map(({ file, diff }) => ({
title: `The ${type} file ${basename(file)} needs to be updated:`,
body: [`${file}\n${'='.repeat(40)}\n${diff}`],
solution,
Expand Down
2 changes: 1 addition & 1 deletion lib/check/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const run = require('../index.js')

module.exports = (root, content) => run(root, content, [
module.exports = (root) => run(root, [
require('./check-apply.js'),
require('./check-required.js'),
require('./check-unwanted.js'),
Expand Down
Loading

0 comments on commit 849cecc

Please sign in to comment.