From ae15022381725668a773ab09c5c38b784e7cd83d Mon Sep 17 00:00:00 2001 From: Lexus Drumgold Date: Wed, 15 Sep 2021 03:11:36 -0400 Subject: [PATCH] chore: refine commit scopes --- .eslintrc.base.js | 1 + commitlint.config.js | 61 ++++++------------------------------ packages/grease/CHANGELOG.md | 12 +++---- scripts/workspaces.js | 39 +++++++++++++++++++++++ 4 files changed, 55 insertions(+), 58 deletions(-) create mode 100644 scripts/workspaces.js diff --git a/.eslintrc.base.js b/.eslintrc.base.js index ca57ef83..27b73658 100644 --- a/.eslintrc.base.js +++ b/.eslintrc.base.js @@ -156,6 +156,7 @@ module.exports = { 'ver', 'wip', 'workspace', + 'workspaces', 'yargs', 'zsh' ], diff --git a/commitlint.config.js b/commitlint.config.js index 7241d320..4035ec4d 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -1,7 +1,3 @@ -const { RuleConfigTuple } = require('@commitlint/types') -const { lstatSync, readdirSync } = require('fs') -const { resolve } = require('path') - /** * @file Commitlint Configuration * @see https://commitlint.js.org/#/guides-local-setup @@ -41,40 +37,12 @@ module.exports = { 'scope-case': [2, 'always', 'kebab-case'], /** - * Returns the rules for valid commit scopes. - * - * @return {RuleConfigTuple} Scope rules + * Commit scopes. */ - 'scope-enum': () => { - /** - * Returns an array containing Yarn workspace directory names. - * - * @return {string[]} Array containing workspace directory names - */ - const workspaceDirectories = () => { - // Yarn project names - const projects = ['packages'] - - // Init array of workspace directory names - const workspaces = [] - - // Get subdirectories - projects.forEach(project => { - // Get path to Yarn project directory - const path = resolve(__dirname, project) - - // Add subdirectories under Yarn project directory - readdirSync(path).forEach(workspace => { - if (!lstatSync(resolve(path, workspace)).isDirectory()) return - return workspaces.push(workspace) - }) - }) - - // Return workspace directory names - return workspaces - } - - const scopes = [ + 'scope-enum': [ + 2, + 'always', + [ 'deploy', 'deps', 'deps-dev', @@ -83,22 +51,11 @@ module.exports = { 'scripts', 'tests', 'typescript', - 'yarn' - ] - - const workspaces = workspaceDirectories() - - return [ - 2, - 'always', - [ - ...scopes, - ...workspaces, - ...workspaces.map(d => scopes.map(s => `${d}-${s}`)).flat(), - 'workflows' - ] + 'workflows', + 'yarn', + ...require('./scripts/workspaces')() ] - }, + ], /** * Commit message subject casing. diff --git a/packages/grease/CHANGELOG.md b/packages/grease/CHANGELOG.md index b1411ecb..b12aed2a 100644 --- a/packages/grease/CHANGELOG.md +++ b/packages/grease/CHANGELOG.md @@ -7,8 +7,8 @@ All notable changes to this project will be documented in this file. See [standa ### :recycle: Code Improvements -* **grease-typescript:** update `SemanticVersionUnstable` definition ([66538cb](https://github.com/flex-development/grease/commit/66538cb6ba9811da0f3f69843aa0d410416fb770)) -* **grease-typescript:** update `SemanticVersionTag` definition ([549bf6d](https://github.com/flex-development/grease/commit/549bf6d3c6b4a6a60645eb0180950c1f517340e5)) +* **typescript:** update `SemanticVersionUnstable` definition ([66538cb](https://github.com/flex-development/grease/commit/66538cb6ba9811da0f3f69843aa0d410416fb770)) +* **typescript:** update `SemanticVersionTag` definition ([549bf6d](https://github.com/flex-development/grease/commit/549bf6d3c6b4a6a60645eb0180950c1f517340e5)) * **grease:** update `grease` options ([1c4c898](https://github.com/flex-development/grease/commit/1c4c8986e11470f2da069c6f0a42a29b948cae3b)) @@ -94,10 +94,10 @@ All notable changes to this project will be documented in this file. See [standa * `yarn set version 3.0.1` ([d3e9f8a](https://github.com/flex-development/grease/commit/d3e9f8ae00bdddd11f64849cfe9a20ec7bb872c0)) * add `publish:node` script ([3bbf8be](https://github.com/flex-development/grease/commit/3bbf8be104c85f30ee0674af96b252761a170018)) * add `scope:cache` label ([3d88b50](https://github.com/flex-development/grease/commit/3d88b50c95996d3b8794219b4ef2025645066fc5)) -* **grease-release:** allow users to download package from github ([796873b](https://github.com/flex-development/grease/commit/796873b1343c11eaabd68a7a7eeb50759ff56314)) -* **grease-scripts:** add release workflow script ([d15c166](https://github.com/flex-development/grease/commit/d15c166d75c60208b690e4d829c4d6065d2c62d3)) -* **grease-scripts:** update release workflow ([eb097c0](https://github.com/flex-development/grease/commit/eb097c0979a136892b6d2ac20d82c4ae5895be10)) -* **grease-scripts:** update release workflow ([78a4b6a](https://github.com/flex-development/grease/commit/78a4b6ab20dfd8f1f37fd87e1287370e97cc23c7)) +* **release:** allow users to download package from github ([796873b](https://github.com/flex-development/grease/commit/796873b1343c11eaabd68a7a7eeb50759ff56314)) +* **scripts:** add release workflow script ([d15c166](https://github.com/flex-development/grease/commit/d15c166d75c60208b690e4d829c4d6065d2c62d3)) +* **scripts:** update release workflow ([eb097c0](https://github.com/flex-development/grease/commit/eb097c0979a136892b6d2ac20d82c4ae5895be10)) +* **scripts:** update release workflow ([78a4b6a](https://github.com/flex-development/grease/commit/78a4b6ab20dfd8f1f37fd87e1287370e97cc23c7)) * **grease:** add `prepublish` script ([92c75a1](https://github.com/flex-development/grease/commit/92c75a157935246168ac8314c722dd24bf60dcd5)) * **grease:** update `package.json#publishConfig` ([800d232](https://github.com/flex-development/grease/commit/800d2329212633c3974a9ec1b5bf33fda929fc34)) * P010-1 initial commit ([2f29aa3](https://github.com/flex-development/grease/commit/2f29aa3698cf31043389f43502b7423c2dd106af)) diff --git a/scripts/workspaces.js b/scripts/workspaces.js new file mode 100644 index 00000000..7e1a5265 --- /dev/null +++ b/scripts/workspaces.js @@ -0,0 +1,39 @@ +const { lstatSync, readdirSync } = require('fs') +const { resolve } = require('path') + +/** + * @file Scripts - Workspaces + * @module scripts/workspaces + */ + +/** + * Returns an array containing Yarn workspace directory names. + * + * @return {string[]} Array containing workspace directory names + */ +const workspaces = () => { + // Yarn project names + const projects = ['packages'] + + /** + * Returns an array containing Yarn workspaces listed under `project`. + * + * @param {string} project - Yarn project directory + * @return {string[]} Yarn workspaces listed under `project` + */ + const callback = project => { + // Get path to Yarn project directory + const path = resolve(process.env.PROJECT_CWD, project) + + // Add subdirectories under Yarn project directory + return readdirSync(path).filter(workspace => { + if (!lstatSync(resolve(path, workspace)).isDirectory()) return + return workspace + }) + } + + // Return workspace directory names + return projects.map(callback).flat() +} + +module.exports = workspaces