@npmcli/template-oss 2.8.1 → 2.9.2

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.
@@ -3,6 +3,10 @@
3
3
  name: "Post Dependabot Actions"
4
4
  on: pull_request
5
5
 
6
+ # https://docs.github.com/en/rest/overview/permissions-required-for-github-apps
7
+ permissions:
8
+ contents: write
9
+
6
10
  jobs:
7
11
  Install:
8
12
  runs-on: ubuntu-latest
@@ -0,0 +1,29 @@
1
+ # This file is automatically added by @npmcli/template-oss. Do not edit.
2
+
3
+ name: Node Workspace Release Please %%pkgname%%
4
+
5
+ on:
6
+ push:
7
+ paths:
8
+ - %%pkgpath%%/**
9
+ branches:
10
+ - release-next
11
+ - latest
12
+
13
+ jobs:
14
+ release-please:
15
+ runs-on: ubuntu-latest
16
+ steps:
17
+ - uses: google-github-actions/release-please-action@v2
18
+ id: release
19
+ with:
20
+ release-type: node
21
+ monorepo-tags: true
22
+ path: %%pkgpath%%
23
+ # If you change changelog-types be sure to also update commitlintrc.js
24
+ changelog-types: >
25
+ [{"type":"feat","section":"Features","hidden":false},
26
+ {"type":"fix","section":"Bug Fixes","hidden":false},
27
+ {"type":"docs","section":"Documentation","hidden":false},
28
+ {"type":"deps","section":"Dependencies","hidden":false},
29
+ {"type":"chore","hidden":true}]
@@ -14,7 +14,6 @@ jobs:
14
14
  - uses: google-github-actions/release-please-action@v2
15
15
  id: release
16
16
  with:
17
- package-name: conventional-test
18
17
  release-type: node
19
18
  # If you change changelog-types be sure to also update commitlintrc.js
20
19
  changelog-types: >
@@ -27,9 +27,13 @@ const repoFiles = {
27
27
  '.github/workflows/release-please.yml': './release-please.yml',
28
28
  }
29
29
 
30
- // currently no workspace moduleFiles
31
- // const workspaceContent = {}
32
- // const workspaceRootContent = {}
30
+ // currently no workspace module files
31
+ // const workspaceModuleFiles = {}
32
+
33
+ const workspaceRepoFiles = {
34
+ '.github/workflows/release-please-%%pkgfsname%%.yml': './release-please-workspace.yml',
35
+ '.github/workflows/ci-%%pkgfsname%%.yml': './ci-workspace.yml',
36
+ }
33
37
 
34
38
  const filesToDelete = [
35
39
  // remove any eslint config files that aren't local to the project
@@ -43,10 +47,25 @@ const defaultConfig = {
43
47
  windowsCI: true,
44
48
  }
45
49
 
46
- const copyFiles = async (targetDir, files) => {
50
+ const findReplace = (str, replace = {}) => {
51
+ for (const [f, r] of Object.entries(replace)) {
52
+ str = str.replace(new RegExp(f, 'g'), r)
53
+ }
54
+ return str
55
+ }
56
+
57
+ const copyFile = async (source, target, replacements) => {
58
+ if (replacements) {
59
+ const content = await fs.readFile(source, { encoding: 'utf-8' })
60
+ return fs.writeFile(target, findReplace(content, replacements), { owner: 'inherit' })
61
+ }
62
+ return fs.copyFile(source, target, { owner: 'inherit' })
63
+ }
64
+
65
+ const copyFiles = async (targetDir, files, replacements) => {
47
66
  for (let [target, source] of Object.entries(files)) {
67
+ target = findReplace(join(targetDir, target), replacements)
48
68
  source = join(contentDir, source)
49
- target = join(targetDir, target)
50
69
  // if the target is a subdirectory of the path, mkdirp it first
51
70
  if (dirname(target) !== targetDir) {
52
71
  await fs.mkdir(dirname(target), {
@@ -55,7 +74,7 @@ const copyFiles = async (targetDir, files) => {
55
74
  force: true,
56
75
  })
57
76
  }
58
- await fs.copyFile(source, target, { owner: 'inherit' })
77
+ await copyFile(source, target, replacements)
59
78
  }
60
79
  }
61
80
 
@@ -94,34 +113,20 @@ const copyContent = async (path, rootPath, config) => {
94
113
 
95
114
  // only workspace now
96
115
 
97
- // TODO: await copyFiles(path, workspaceFiles)
116
+ // TODO: await copyFiles(path, workspaceModuleFiles)
98
117
  // if we ever have workspace specific files
99
118
 
119
+ // transform and copy all workspace repo files
100
120
  if (config.applyWorkspaceRepoFiles) {
101
- // copy and edit workspace repo file (ci github action)
102
121
  const workspacePkg = (await PackageJson.load(path)).content
103
- const workspaceName = workspacePkg.name
104
- let workspaceFile = `ci-${workspaceName.replace(/\//g, '-')}.yml`
105
- workspaceFile = workspaceFile.replace(/@/g, '')
106
- const workflowPath = join(rootPath, '.github', 'workflows')
107
- await fs.mkdir(workflowPath, {
108
- owner: 'inherit',
109
- recursive: true,
110
- force: true,
122
+ await copyFiles(rootPath, workspaceRepoFiles, {
123
+ '%%pkgname%%': workspacePkg.name,
124
+ '%%pkgfsname%%': workspacePkg.name.replace(/\//g, '-').replace(/@/g, ''),
125
+ '%%pkgpath%%': path.substring(rootPath.length + 1),
111
126
  })
112
-
113
- let workflowData = await fs.readFile(
114
- join(contentDir, './ci-workspace.yml'),
115
- { encoding: 'utf-8' }
116
- )
117
-
118
- const relPath = path.substring(rootPath.length + 1)
119
- workflowData = workflowData.replace(/%%pkgpath%%/g, relPath)
120
- workflowData = workflowData.replace(/%%pkgname%%/g, workspaceName)
121
-
122
- await fs.writeFile(join(workflowPath, workspaceFile), workflowData)
123
127
  }
124
128
  }
129
+
125
130
  copyContent.moduleFiles = moduleFiles
126
131
  copyContent.repoFiles = repoFiles
127
132
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@npmcli/template-oss",
3
- "version": "2.8.1",
3
+ "version": "2.9.2",
4
4
  "description": "templated files used in npm CLI team oss projects",
5
5
  "main": "lib/index.js",
6
6
  "bin": {
@@ -31,7 +31,7 @@
31
31
  "author": "GitHub Inc.",
32
32
  "license": "ISC",
33
33
  "dependencies": {
34
- "@npmcli/fs": "^1.1.1",
34
+ "@npmcli/fs": "^2.0.1",
35
35
  "@npmcli/map-workspaces": "^2.0.1",
36
36
  "@npmcli/package-json": "^1.0.1",
37
37
  "json-parse-even-better-errors": "^2.3.1",
@@ -45,7 +45,7 @@
45
45
  "@npmcli/eslint-config": "*",
46
46
  "@npmcli/promise-spawn": "^2.0.0",
47
47
  "@npmcli/template-oss": "file:./",
48
- "eslint": "^8.9.0",
48
+ "eslint": "^8.10.0",
49
49
  "eslint-plugin-node": "^11.1.0",
50
50
  "tap": "*"
51
51
  },