@w5s/mrm-preset 1.0.0-alpha.8 → 1.0.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.
Files changed (53) hide show
  1. package/.turbo/turbo-build.log +6 -1
  2. package/.turbo/turbo-docs.log +9 -43
  3. package/.turbo/turbo-format.log +6 -0
  4. package/.turbo/turbo-lint.log +6 -52
  5. package/.turbo/turbo-prepare.log +1 -0
  6. package/.turbo/turbo-test.log +28 -21
  7. package/CHANGELOG.md +194 -39
  8. package/README.md +7 -7
  9. package/bootstrap/README.md +1 -1
  10. package/bootstrap/index.js +14 -38
  11. package/ci/_gitlab/AutoDevops.gitlab-ci.yml +1 -2
  12. package/ci/_gitlab/AutoDevopsInclude.gitlab-ci.yml +19 -19
  13. package/ci/_gitlab/Renovate.gitlab-ci.yml +6 -6
  14. package/ci/github.js +53 -0
  15. package/ci/gitlab.js +1 -2
  16. package/ci/index.js +7 -2
  17. package/commitlint/index.js +8 -2
  18. package/config.json +2 -1
  19. package/contributing/index.js +1 -1
  20. package/core/commitlint.js +5 -5
  21. package/core/cspell.js +2 -11
  22. package/core/eslint.js +25 -6
  23. package/core/git.js +4 -23
  24. package/core/githooks.js +13 -21
  25. package/core/githubCI.js +56 -0
  26. package/core/jest.js +26 -36
  27. package/core/jsonFile.js +8 -7
  28. package/core/lintStaged.js +3 -3
  29. package/core/npm.js +15 -13
  30. package/core/pkg.js +71 -14
  31. package/core/project.js +6 -0
  32. package/core/semanticRelease.js +3 -3
  33. package/core/turbo.js +52 -0
  34. package/core/typedoc.js +3 -3
  35. package/core/vitest.js +77 -0
  36. package/core/vscode.js +15 -5
  37. package/cspell/index.js +35 -14
  38. package/editorconfig/index.js +19 -9
  39. package/eslint/index.js +90 -47
  40. package/githooks/index.js +16 -12
  41. package/gitignore/index.js +1 -1
  42. package/lang/.eslintrc.json +1 -3
  43. package/lang/index.js +73 -36
  44. package/lang/templates/index.spec.ts +3 -2
  45. package/lang/templates/index.ts +1 -2
  46. package/licenses/index.js +26 -0
  47. package/package.json +22 -15
  48. package/postconfigure/index.js +11 -3
  49. package/project/index.js +253 -171
  50. package/release/index.js +5 -5
  51. package/renovate/index.js +4 -3
  52. package/tsconfig.json +3 -6
  53. package/{jest → vitest}/index.js +3 -3
@@ -1,9 +1,8 @@
1
- /* eslint-disable sort-keys-fix/sort-keys-fix */
2
- const path = require('path');
3
- const { packageJson, file } = require('mrm-core');
4
- const npm = require('../core/npm');
5
- const pkg = require('../core/pkg');
6
- const { gitIgnoreTemplate } = require('../core/git');
1
+ const path = require('node:path');
2
+ const { packageJson } = require('mrm-core');
3
+ const npm = require('../core/npm.js');
4
+ const pkg = require('../core/pkg.js');
5
+ const { gitIgnoreTemplate } = require('../core/git.js');
7
6
 
8
7
  /**
9
8
  * @param {{
@@ -14,7 +13,7 @@ const { gitIgnoreTemplate } = require('../core/git');
14
13
  * }} config
15
14
  * @returns {void}
16
15
  */
17
- function task({ mrmPreset, mrmTask, packageArchetype, packageManager }) {
16
+ function task({ mrmPreset, mrmTask, packageManager }) {
18
17
  /**
19
18
  * setup package.json from following object
20
19
  */
@@ -30,40 +29,23 @@ function task({ mrmPreset, mrmTask, packageArchetype, packageManager }) {
30
29
 
31
30
  npm.bootstrap(packageManager);
32
31
 
33
- npm.dependency({
34
- dev: true,
35
- name: ['mrm', mrmPreset],
36
- state: 'present',
37
- });
32
+ // npm.dependency({
33
+ // dev: true,
34
+ // name: ['mrm', mrmPreset],
35
+ // state: 'present',
36
+ // });
38
37
 
39
38
  pkg.withPackageJson((packageFile) => {
40
- const currentPackageManager = pkg.manager(packageFile);
41
-
42
39
  // Add MRM default scripts
43
40
  pkg.script(packageFile, {
44
41
  name: 'configure',
45
- state: 'default',
46
- script: currentPackageManager === 'npm' ? `npm run mrm -- ${mrmTask}` : `yarn mrm ${mrmTask}`,
42
+ state: 'present',
43
+ default: `npm run mrm -- ${mrmTask}`,
47
44
  });
48
45
  pkg.script(packageFile, {
49
46
  name: 'mrm',
50
- state: 'default',
51
- script: `${currentPackageManager} --preset ${mrmPreset}`,
52
- });
53
- });
54
-
55
- pkg.withPackageJson((packageFile) => {
56
- pkg.value(packageFile, {
57
- path: 'mrmConfig.packageArchetype',
58
47
  state: 'present',
59
- update: packageArchetype,
60
- default: () => {
61
- if (file('lerna.json').exists() || Boolean(packageFile.get('workspaces'))) {
62
- return 'workspace';
63
- }
64
-
65
- return 'library';
66
- },
48
+ default: `npm exec --package=mrm --package=${mrmPreset}@latest -- mrm --preset ${mrmPreset}`,
67
49
  });
68
50
  });
69
51
  }
@@ -81,12 +63,6 @@ task.parameters = {
81
63
  message: 'Default MRM task name ?',
82
64
  type: 'input',
83
65
  },
84
- packageArchetype: {
85
- choices: ['library', 'application', 'workspace'],
86
- message: 'What Archetype of package ?',
87
- name: 'packageArchetype',
88
- type: 'input',
89
- },
90
66
  packageManager: {
91
67
  default: 'yarn@berry',
92
68
  choices: ['yarn@berry', 'yarn@classic', 'npm'],
@@ -1,4 +1,4 @@
1
- ##
1
+ #
2
2
  # Follow the following standards
3
3
  #
4
4
  # @ref https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Auto-DevOps.gitlab-ci.yml
@@ -69,7 +69,6 @@ code_analysis:
69
69
  variables:
70
70
  CODE_ANALYSIS_HOUR: 7 # 7h UTC => 9h Paris
71
71
  # CODE_ANALYSIS_DISABLED: "🛑"
72
-
73
72
  # deploy_production:
74
73
  # extends:
75
74
  # - .autodevops_trigger_deploy
@@ -4,21 +4,19 @@ include:
4
4
 
5
5
  # Default variables
6
6
  variables:
7
-
8
-
9
7
  # To activate the auto release
10
- AUTO_DEVOPS_QUALITY_WHEN: 'always' # 'always'|'never'
11
- AUTO_DEVOPS_TEST_WHEN: 'always' # 'always'|'never'
12
- AUTO_DEVOPS_RELEASE_WHEN: 'manual' # 'on_success'|'manual'|'never'
13
- AUTO_DEVOPS_DEPLOY_ALLOW: 'tag' # 'tag'|'any'
14
- AUTO_DEVOPS_DEPLOY_WHEN: 'manual' # 'on_success'|'manual'|'never'
8
+ AUTO_DEVOPS_QUALITY_WHEN: always # 'always'|'never'
9
+ AUTO_DEVOPS_TEST_WHEN: always # 'always'|'never'
10
+ AUTO_DEVOPS_RELEASE_WHEN: manual # 'on_success'|'manual'|'never'
11
+ AUTO_DEVOPS_DEPLOY_ALLOW: tag # 'tag'|'any'
12
+ AUTO_DEVOPS_DEPLOY_WHEN: manual # 'on_success'|'manual'|'never'
15
13
 
16
14
  # Renovate variable
17
15
  # RENOVATE_DISABLED: "🛑"
18
16
 
19
- ##
17
+ # #
20
18
  # Contextual variables
21
- ##
19
+ # #
22
20
  # DEPLOY_ENVIRONMENT: production,staging,...
23
21
  # RENOVATE: true|false
24
22
 
@@ -33,14 +31,14 @@ variables:
33
31
  if: '$CI_PIPELINE_SOURCE == "schedule"'
34
32
  when: never
35
33
  - &autodevops_renovate_skip_rule
36
- if: "$RENOVATE"
34
+ if: $RENOVATE
37
35
  when: never
38
36
  - &autodevops_default_branch_only_rule
39
- if: '$CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH'
37
+ if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH
40
38
  when: never
41
39
  - when: on_success
42
40
 
43
- ##
41
+ # #
44
42
  # Generic trait for a trigger button for release stage
45
43
  #
46
44
  .autodevops_trigger_release:
@@ -53,7 +51,9 @@ variables:
53
51
  - <<: *autodevops_default_branch_only_rule
54
52
  - if: "$AUTO_DEVOPS_RELEASE_WHEN == 'never'"
55
53
  when: never
56
- - if: "$CI_COMMIT_TAG"
54
+ - if: $CI_COMMIT_TAG
55
+ when: never
56
+ - if: $CI_COMMIT_MESSAGE =~ /🔖 /
57
57
  when: never
58
58
  - if: $CI_COMMIT_MESSAGE =~ /chore\(release\):/
59
59
  when: never
@@ -75,7 +75,7 @@ variables:
75
75
  - npm config set '//registry.npmjs.org/:_authToken' "${NPM_TOKEN}"
76
76
  - npm run release
77
77
 
78
- ##
78
+ # #
79
79
  # Generic trait for a trigger button for deploy stage.
80
80
  # Use DEPLOY_ENVIRONMENT variable to choose environment
81
81
  #
@@ -176,7 +176,7 @@ variables:
176
176
  CODE_ANALYSIS_HOUR: 7 # 7h UTC => 9h Paris
177
177
  # CODE_ANALYSIS_DISABLED: "🛑"
178
178
  rules:
179
- - if: "$CODE_ANALYSIS_DISABLED"
179
+ - if: $CODE_ANALYSIS_DISABLED
180
180
  when: never
181
181
  - if: '$CI_PIPELINE_SOURCE == "schedule"'
182
182
  when: always
@@ -226,9 +226,9 @@ variables:
226
226
  expire_in: 1 week
227
227
  paths:
228
228
  - dist
229
- - "packages/*/dist"
229
+ - 'packages/*/dist'
230
230
  - lib
231
- - "packages/*/lib"
231
+ - 'packages/*/lib'
232
232
  - node_modules
233
233
 
234
234
  .autodevops_node_docs:
@@ -242,9 +242,9 @@ variables:
242
242
  .autodevops_renovate:
243
243
  stage: prepare
244
244
  rules:
245
- - if: "$RENOVATE_DISABLED"
245
+ - if: $RENOVATE_DISABLED
246
246
  when: never
247
- - if: "$RENOVATE"
247
+ - if: $RENOVATE
248
248
  when: always
249
249
  - when: never
250
250
  extends:
@@ -1,20 +1,20 @@
1
1
  # https://fotoallerlei.com/blog/post/2020/automatic-dependency-updates-with-renovate-and-gitlab/post
2
2
  .renovate:
3
3
  variables:
4
- RENOVATE_GIT_AUTHOR: "${GITLAB_USER_NAME} <${GITLAB_USER_EMAIL}>"
5
- RENOVATE_DRY_RUN: "false"
6
- RENOVATE_LOG_LEVEL: "debug"
7
- RENOVATE_ALLOWED_POST_UPGRADE: "^pod ,^yarn "
4
+ RENOVATE_GIT_AUTHOR: '${GITLAB_USER_NAME} <${GITLAB_USER_EMAIL}>'
5
+ RENOVATE_DRY_RUN: 'false'
6
+ RENOVATE_LOG_LEVEL: debug
7
+ RENOVATE_ALLOWED_POST_UPGRADE: '^pod ,^yarn '
8
8
  # RENOVATE_DISABLED: "🛑"
9
9
  rules:
10
- - if: "$RENOVATE_DISABLED"
10
+ - if: $RENOVATE_DISABLED
11
11
  when: never
12
12
  - if: '$CI_PIPELINE_SOURCE == "schedule"'
13
13
  when: always
14
14
  - when: never
15
15
  image:
16
16
  name: renovate/renovate
17
- entrypoint: [""]
17
+ entrypoint: ['']
18
18
  script:
19
19
  - >
20
20
  renovate
package/ci/github.js ADDED
@@ -0,0 +1,53 @@
1
+ const { packageJson } = require('mrm-core');
2
+ const githubCI = require('../core/githubCI.js');
3
+ const pkg = require('../core/pkg.js');
4
+
5
+ function task() {
6
+ const state = 'present';
7
+ const packageManager = pkg.manager(packageJson());
8
+ const baseBranch = 'main';
9
+ const packageInstall =
10
+ packageManager === 'npm'
11
+ ? `${packageManager} ci`
12
+ : packageManager === 'yarn'
13
+ ? `${packageManager} install --frozen-lockfile`
14
+ : `${packageManager} install`;
15
+ githubCI.workflow({
16
+ name: 'node.js.yml',
17
+ state,
18
+ update: (config) => ({
19
+ name: 'Node.js CI',
20
+ ...config,
21
+ on: {
22
+ push: {
23
+ branches: [baseBranch],
24
+ },
25
+ pull_request: {
26
+ branches: [baseBranch],
27
+ },
28
+ },
29
+ jobs: {
30
+ ...config.jobs,
31
+ build: {
32
+ 'runs-on': 'ubuntu-latest',
33
+ steps: [
34
+ { uses: 'actions/checkout@v3' },
35
+ {
36
+ name: 'Use Node.js',
37
+ uses: 'actions/setup-node@v3',
38
+ with: {
39
+ 'node-version': 'lts/*',
40
+ cache: packageManager,
41
+ },
42
+ },
43
+ { run: packageInstall },
44
+ { run: `${packageManager} run build` },
45
+ { run: `${packageManager} validate` },
46
+ ],
47
+ },
48
+ },
49
+ }),
50
+ });
51
+ }
52
+
53
+ module.exports = task;
package/ci/gitlab.js CHANGED
@@ -1,5 +1,4 @@
1
- /* eslint-disable global-require, sort-keys-fix/sort-keys-fix */
2
- const path = require('path');
1
+ const path = require('node:path');
3
2
  const { yaml } = require('mrm-core');
4
3
 
5
4
  /** @type {typeof import('sync-directory')['default']} */
package/ci/index.js CHANGED
@@ -1,11 +1,16 @@
1
- const gitlabCI = require('../core/gitlabCI');
2
- const gitlab = require('./gitlab');
1
+ const gitlabCI = require('../core/gitlabCI.js');
2
+ const githubCI = require('../core/githubCI.js');
3
+ const gitlab = require('./gitlab.js');
4
+ const github = require('./github.js');
3
5
 
4
6
  function task() {
5
7
  // check gitlab support
6
8
  if (gitlabCI.isSupported()) {
7
9
  gitlab();
8
10
  }
11
+ if (githubCI.isSupported()) {
12
+ github();
13
+ }
9
14
  }
10
15
 
11
16
  task.description = 'Setup Continuous Integration';
@@ -1,5 +1,6 @@
1
- const { commitlint } = require('../core/commitlint');
2
- const { hasGit } = require('../core/git');
1
+ const { vscodeRecommendedExtension } = require('../core/vscode.js');
2
+ const { commitlint } = require('../core/commitlint.js');
3
+ const { hasGit } = require('../core/git.js');
3
4
 
4
5
  /**
5
6
  *
@@ -21,6 +22,11 @@ function createCommitLint({ commitLintPreset: commitLintPresetDefault }) {
21
22
  preset: commitLintPreset,
22
23
  state: gitPresent ? 'present' : 'absent',
23
24
  });
25
+
26
+ vscodeRecommendedExtension({
27
+ name: 'seatonjiang.gitmoji-vscode',
28
+ state: gitPresent ? 'present' : 'absent',
29
+ });
24
30
  }
25
31
 
26
32
  task.description = 'Setup CommitLint';
package/config.json CHANGED
@@ -4,6 +4,7 @@
4
4
  "gitignore",
5
5
  "project",
6
6
  "contributing",
7
+ "licenses",
7
8
  "release",
8
9
  "ci",
9
10
  "lang",
@@ -11,7 +12,7 @@
11
12
  "editorconfig",
12
13
  "eslint",
13
14
  "cspell",
14
- "jest",
15
+ "vitest",
15
16
  "renovate",
16
17
  "githooks",
17
18
  "postconfigure"
@@ -1,4 +1,4 @@
1
- const path = require('path');
1
+ const path = require('node:path');
2
2
  const { file } = require('mrm-core');
3
3
 
4
4
  function task() {
@@ -1,6 +1,6 @@
1
- const pkg = require('./pkg');
2
- const npm = require('./npm');
3
- const { gitHook } = require('./githooks');
1
+ const pkg = require('./pkg.js');
2
+ const npm = require('./npm.js');
3
+ const { gitHook } = require('./githooks.js');
4
4
 
5
5
  /**
6
6
  * @param {{
@@ -23,13 +23,13 @@ function commitlint({ state, preset }) {
23
23
 
24
24
  gitHook({
25
25
  name: 'commit-msg',
26
- content: 'npm exec --no -- commitlint --edit $1',
26
+ content: 'npm exec -- commitlint --edit $1',
27
27
  state,
28
28
  });
29
29
 
30
30
  npm.dependency({
31
31
  dev: true,
32
- name: ['@commitlint/cli', preset],
32
+ name: [preset],
33
33
  state,
34
34
  });
35
35
  }
package/core/cspell.js CHANGED
@@ -1,6 +1,5 @@
1
1
  const { json } = require('mrm-core');
2
- const pkg = require('./pkg');
3
- const npm = require('./npm');
2
+ const npm = require('./npm.js');
4
3
  /**
5
4
  * @typedef {{
6
5
  * version: '0.2',
@@ -22,15 +21,7 @@ const npm = require('./npm');
22
21
  function cspell({ state, update }) {
23
22
  const hasCSpell = state === 'present';
24
23
 
25
- pkg.withPackageJson((packageFile) => {
26
- pkg.script(packageFile, {
27
- name: 'cspell',
28
- script: 'cspell',
29
- state,
30
- });
31
- });
32
-
33
- const cSpellFile = json('cSpell.json', {
24
+ const cSpellFile = json('.cspell.json', {
34
25
  version: '0.2',
35
26
  language: 'en',
36
27
  words: [],
package/core/eslint.js CHANGED
@@ -1,14 +1,29 @@
1
1
  const { packageJson } = require('mrm-core');
2
-
2
+ const jsonFile = require('./jsonFile.js');
3
+ /**
4
+ * @typedef {import('eslint').Linter.Config} ESLintConfig
5
+ */
3
6
  /**
4
- * @param {import('eslint').Linter.Config} config
7
+ * @param {{
8
+ * state: 'present'|'absent',
9
+ * update: (config: ESLintConfig) => ESLintConfig
10
+ * }} config
5
11
  */
6
- function eslintConfig(config) {
12
+ function eslintConfig({ state, update }) {
7
13
  const packageFile = packageJson();
8
- packageFile.merge({ eslintConfig: config });
14
+
15
+ jsonFile.value(packageFile, {
16
+ path: 'eslintConfig',
17
+ state,
18
+ // @ts-ignore
19
+ update,
20
+ /** @type {ESLintConfig} */
21
+ // @ts-ignore
22
+ default: {},
23
+ });
24
+
9
25
  packageFile.save();
10
26
  }
11
- exports.eslintConfig = eslintConfig;
12
27
 
13
28
  /**
14
29
  *
@@ -19,4 +34,8 @@ function eslintIgnore(ignorePatterns) {
19
34
  packageFile.merge({ eslintIgnore: ignorePatterns });
20
35
  packageFile.save();
21
36
  }
22
- exports.eslintIgnore = eslintIgnore;
37
+
38
+ module.exports = {
39
+ eslintConfig,
40
+ eslintIgnore,
41
+ };
package/core/git.js CHANGED
@@ -1,30 +1,14 @@
1
1
  const { file, ini } = require('mrm-core');
2
- const block = require('./block');
3
-
2
+ const block = require('./block.js');
3
+ const templateMap = require('./git.ignore.js');
4
4
  /**
5
5
  *
6
6
  */
7
7
  function remoteSync() {
8
8
  try {
9
9
  const gitConfig = ini('.git/config');
10
- const remoteURL = gitConfig.get('[remote "origin"]').url;
11
-
12
- return remoteURL
13
- ? [
14
- /**
15
- * 1. filter github URL
16
- *
17
- * @param {string} returnValue
18
- */
19
- (returnValue) => returnValue.replace(/^git@github.com:/, 'https://github.com/'),
20
- /**
21
- * 2. filter gitlab URL
22
- *
23
- * @param {string} returnValue
24
- */
25
- (returnValue) => returnValue.replace(/^git@gitlab.com:/, 'https://gitlab.com/'),
26
- ].reduce((returnValue, filter) => filter(returnValue), remoteURL)
27
- : remoteURL;
10
+ const remoteURL = gitConfig.get('remote "origin"').url.trim();
11
+ return remoteURL;
28
12
  } catch {
29
13
  // ignore error
30
14
  }
@@ -68,9 +52,6 @@ exports.gitIgnore = gitIgnore;
68
52
  * @param {string[]} flags
69
53
  */
70
54
  function gitIgnoreTemplate(flags) {
71
- // eslint-disable-next-line global-require, import/no-dynamic-require
72
- const templateMap = require('./git.ignore');
73
-
74
55
  flags.forEach((flag) => {
75
56
  // @ts-ignore
76
57
  if (templateMap[flag]) {
package/core/githooks.js CHANGED
@@ -1,10 +1,12 @@
1
- const { execSync } = require('child_process');
2
- const path = require('path');
3
- const { file, packageJson, makeDirs } = require('mrm-core');
4
- const project = require('./project');
5
- const npm = require('./npm');
6
- const pkg = require('./pkg');
7
- const block = require('./block');
1
+ const { execSync } = require('node:child_process');
2
+ const path = require('node:path');
3
+ const { file, makeDirs } = require('mrm-core');
4
+ const project = require('./project.js');
5
+ const npm = require('./npm.js');
6
+ const pkg = require('./pkg.js');
7
+ const block = require('./block.js');
8
+
9
+ const hookDirectory = '.githooks';
8
10
 
9
11
  /**
10
12
  * @param {{
@@ -17,21 +19,14 @@ function husky({ state }) {
17
19
  npm.dependency({
18
20
  dev: true,
19
21
  name: ['husky'],
20
- state: hasHusky ? 'present' : 'absent',
22
+ state: 'absent',
21
23
  });
22
- if (hasHusky) {
23
- npm.dependency({
24
- dev: true,
25
- name: ['is-ci'],
26
- state: 'present',
27
- });
28
- }
29
24
 
30
25
  pkg.withPackageJson((packageFile) => {
31
26
  pkg.script(packageFile, {
32
- name: `${project.prepare}:husky`,
27
+ name: `${project.prepare}:githooks`,
33
28
  state: hasHusky ? 'present' : 'absent',
34
- script: 'is-ci || husky install',
29
+ update: `[ -n "\${CI:-}" ] || npx husky install ${hookDirectory}`,
35
30
  });
36
31
  });
37
32
  }
@@ -44,10 +39,7 @@ function husky({ state }) {
44
39
  * }} options
45
40
  */
46
41
  function gitHook({ name, state, content }) {
47
- const packageFileDefault = packageJson();
48
- const hasHusky = pkg.hasDependency(packageFileDefault, 'husky', 'dev');
49
- const hasGitHook = hasHusky && state === 'present';
50
- const hookDirectory = '.husky';
42
+ const hasGitHook = state === 'present';
51
43
  const hookFileName = path.join(hookDirectory, name);
52
44
  if (hasGitHook) {
53
45
  makeDirs(hookDirectory);
@@ -0,0 +1,56 @@
1
+ const { yaml } = require('mrm-core');
2
+ const path = require('node:path');
3
+ const fs = require('node:fs');
4
+
5
+ const FILE_PATH = '.github/workflows';
6
+
7
+ function isSupported() {
8
+ return fs.existsSync(FILE_PATH);
9
+ }
10
+ exports.isSupported = isSupported;
11
+
12
+ /**
13
+ * @typedef { string | {
14
+ * group: string,
15
+ * 'cancel-in-progress': boolean,
16
+ * }} GithubWorkflowConcurrency
17
+ */
18
+ // TODO: add strict typing
19
+ /**
20
+ * @typedef {{
21
+ * name?: string,
22
+ * jobs?: Record<string, any>
23
+ * on?: any,
24
+ * env?: Record<string, string>,
25
+ * permissions?: any,
26
+ * defaults?: Record<string, any>,
27
+ * concurrency?: GithubWorkflowConcurrency,
28
+ * }} GithubWorkflowConfig
29
+ */
30
+
31
+ /**
32
+ * @param {{
33
+ * state: 'present'|'absent',
34
+ * name: string,
35
+ * update?: (config: GithubWorkflowConfig) => GithubWorkflowConfig
36
+ * }} options
37
+ */
38
+ function workflow({ name, state, update }) {
39
+ const workflowFile = yaml(path.join(FILE_PATH, name));
40
+ if (state === 'present') {
41
+ /** @type {GithubWorkflowConfig} */
42
+ let value = workflowFile.get() || {
43
+ jobs: {},
44
+ };
45
+ if (update) {
46
+ value = update(value);
47
+ // @ts-ignore
48
+ workflowFile.set(value);
49
+ }
50
+
51
+ workflowFile.save();
52
+ } else {
53
+ workflowFile.delete();
54
+ }
55
+ }
56
+ exports.workflow = workflow;