@p8ec/shared 2.2.5 → 2.4.1

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/README.md CHANGED
@@ -4,7 +4,13 @@ Shared TypeScript/JavaScript libraries for P(8) products.
4
4
 
5
5
  ## Shared Configuration
6
6
 
7
- Shared configuration for P(8) projects.
7
+ Shared (**and very opinionated**) configuration for P(8) projects.
8
+
9
+ **Contents:**
10
+ - ESLint configuration
11
+ - Prettier configuration
12
+ - Commitlint configuration
13
+ - Lefthook configuration
8
14
 
9
15
  ### Usage
10
16
 
@@ -23,20 +29,31 @@ p8-cli init
23
29
  This command will create the following files in your project and remove corresponding configuration entries
24
30
  from `package.json`:
25
31
 
26
- #### **`.eslintrc.js`**
32
+ #### **`.eslintrc.cjs`**
27
33
 
28
34
  ```javascript
35
+ /* eslint-disable */
29
36
  module.exports = require('@p8ec/shared').eslintConfigRecommended;
30
37
  ```
31
38
 
32
- #### **`.prettierrc.js`**
39
+ #### **`.prettierrc.cjs`**
33
40
 
34
41
  ```javascript
42
+ /* eslint-disable */
35
43
  module.exports = require('@p8ec/shared').prettierConfigRecommended;
36
44
  ```
37
45
 
46
+ #### **`.commitlintrc.cjs`**
47
+
48
+ ```javascript
49
+ /* eslint-disable */
50
+ module.exports = { extends: ["@commitlint/config-conventional"] };
51
+ ```
52
+
38
53
  ## P(8) CLI Tool
39
54
 
55
+ A command-line interface (CLI) tool for P(8) projects to simplify common tasks.
56
+
40
57
  ### Syntax
41
58
 
42
59
  ```shell
@@ -46,6 +63,8 @@ p8-cli [command] [options]
46
63
  ### Commands
47
64
 
48
65
  - `init` - Initialize P(8) shared configuration in your project. Options: `cleanup` - remove configuration entries from `package.json`
66
+ - Example: `p8-cli init --cleanup` - initializes the shared configuration and removes corresponding entries from `package.json`.
49
67
  - `dirn` - Get the directory name. Options: `0` - current directory (default), `1` - parent directory, `2` - 2 levels up
50
68
  directory, etc.
69
+ - Example: `p8-cli dirn 1` - shows the parent directory name.
51
70
 
@@ -1,6 +1,19 @@
1
- # Refer for explanation to following link:
1
+ # Refer for explanation to the following link:
2
2
  # https://github.com/evilmartians/lefthook/blob/master/docs/configuration.md
3
3
 
4
+ ### Pre-commit hook ###
5
+ # 1. Block commits to main, master, and release branches
6
+ pre-commit:
7
+ commands:
8
+ git:
9
+ run: |
10
+ if [[ $(git rev-parse --abbrev-ref HEAD) =~ ^(main|master|release)$ ]]; then
11
+ echo "Direct commits to main, master, and release branches are not allowed."
12
+ exit 1
13
+ fi
14
+
15
+ ### Commit message hook ###
16
+ # 1. Allow only commit messages that follow a conventional commit format
4
17
  commit-msg:
5
18
  commands:
6
19
  commitlint:
@@ -115,6 +115,8 @@ const init = (option) => __awaiter(void 0, void 0, void 0, function* () {
115
115
  copyAsset(`eslint.config.${moduleType}`);
116
116
  writeLn(`Creating prettier.config.${moduleType}...`);
117
117
  copyAsset(`prettier.config.${moduleType}`);
118
+ packageJson.scripts['npm:reset'] = 'rm -rf ./**/node_modules && rm -rf ./**/package-lock.json && npm install';
119
+ packageJson.scripts['npm:audit'] = 'npm audit --audit-level=moderate';
118
120
  const lefthook = yield (0, yesno_1.default)({
119
121
  question: 'Do you want to use commitlint/lefthook? [y]n',
120
122
  defaultValue: true,
@@ -130,10 +132,31 @@ const init = (option) => __awaiter(void 0, void 0, void 0, function* () {
130
132
  const lefthookInstall = 'lefthook install';
131
133
  packageJson.scripts.postinstall = lefthookInstall;
132
134
  const npmInstall = 'npm install --save-dev @commitlint/{config-conventional,cli} commitlint lefthook';
133
- writeLn(`Executing ${npmInstall}...`);
134
- execShell(npmInstall);
135
- writeLn(`Executing ${lefthookInstall}...`);
136
- execShell(lefthookInstall);
135
+ const pnpmInstall = 'pnpm install -D @commitlint/{config-conventional,cli} commitlint lefthook';
136
+ if (yield (0, yesno_1.default)({
137
+ question: `Do you want to run "${npmInstall}" now? [y]n`,
138
+ defaultValue: true,
139
+ yesValues: ['yes', 'y'],
140
+ noValues: ['no', 'n'],
141
+ })) {
142
+ writeLn(`Executing ${npmInstall}...`);
143
+ execShell(npmInstall);
144
+ }
145
+ else {
146
+ writeLn('You could run the following command to install needed dependencies:');
147
+ writeLn(npmInstall);
148
+ writeLn('Or, for pnpm users:');
149
+ writeLn(pnpmInstall);
150
+ }
151
+ if (yield (0, yesno_1.default)({
152
+ question: `Do you want to run "${lefthookInstall}" now? [y]n`,
153
+ defaultValue: true,
154
+ yesValues: ['yes', 'y'],
155
+ noValues: ['no', 'n'],
156
+ })) {
157
+ writeLn(`Executing ${lefthookInstall}...`);
158
+ execShell(lefthookInstall);
159
+ }
137
160
  }
138
161
  if (option === null || option === void 0 ? void 0 : option.split(',').includes('cleanup')) {
139
162
  initCleanup(packageJson);
@@ -153,13 +176,13 @@ const dirn = (levelsUp) => {
153
176
  return process.cwd().split(path.sep).reverse()[levels];
154
177
  };
155
178
  const setup = () => __awaiter(void 0, void 0, void 0, function* () {
156
- // Ask user for arguments if IS_DEV is true
179
+ // Ask the user for arguments if IS_DEV is true
157
180
  if (IS_DEV) {
158
181
  args = (yield (0, prompt_1.default)('Enter arguments: ')).split(' ');
159
182
  }
160
183
  switch (args[0]) {
161
184
  case 'init':
162
- init(args[1]);
185
+ yield init(args[1]);
163
186
  break;
164
187
  case 'dirn':
165
188
  writeLn(dirn(args[1]));
@@ -169,4 +192,16 @@ const setup = () => __awaiter(void 0, void 0, void 0, function* () {
169
192
  process.exit(1);
170
193
  }
171
194
  });
172
- setup();
195
+ setup()
196
+ .then((r) => {
197
+ if (IS_DEV) {
198
+ writeLn(`DEV: setup completed with result: ${r}`);
199
+ }
200
+ })
201
+ .catch((err) => {
202
+ if (IS_DEV) {
203
+ writeLn(`DEV: setup failed with error: ${err}`);
204
+ }
205
+ console.error(`Error: ${err}`);
206
+ process.exit(1);
207
+ });
@@ -27,9 +27,10 @@ declare const _default: (overrides?: PrettierConfigOverride) => {
27
27
  filepath?: string | undefined;
28
28
  requirePragma?: boolean | undefined;
29
29
  insertPragma?: boolean | undefined;
30
+ checkIgnorePragma?: boolean | undefined;
30
31
  proseWrap?: "preserve" | "always" | "never" | undefined;
31
32
  arrowParens?: "always" | "avoid" | undefined;
32
- plugins?: (string | import("prettier").Plugin<any>)[] | undefined;
33
+ plugins?: (string | URL | import("prettier").Plugin<any>)[] | undefined;
33
34
  htmlWhitespaceSensitivity?: "strict" | "ignore" | "css" | undefined;
34
35
  endOfLine?: "auto" | "lf" | "crlf" | "cr" | undefined;
35
36
  quoteProps?: "preserve" | "as-needed" | "consistent" | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@p8ec/shared",
3
- "version": "2.2.5",
3
+ "version": "2.4.1",
4
4
  "description": "P(8) Global Shared Library for Javascript",
5
5
  "repository": {
6
6
  "type": "git",
@@ -18,7 +18,7 @@
18
18
  "build:assets": "cp -R src/assets dist",
19
19
  "build:scripts": "cp -R ../scripts dist && chmod -R +x dist/scripts/*.sh",
20
20
  "clean": "rm -rf dist docs coverage",
21
- "cli": "NODE_ENV=development ts-node src/bin/p8-shared-cli.ts",
21
+ "cli:testrun": "NODE_ENV=development ts-node src/bin/p8-shared-cli.ts",
22
22
  "test": "jest --no-cache --runInBand",
23
23
  "test:cov": "jest --coverage --no-cache --runInBand",
24
24
  "lint": "eslint --cache \"src/**/*.{js,jsx,ts,tsx}\"",
@@ -28,7 +28,6 @@
28
28
  "docs:clean": "rimraf docs"
29
29
  },
30
30
  "bin": {
31
- "p8-shared-cli": "dist/cjs/bin/p8-shared-cli.js",
32
31
  "p8-cli": "dist/cjs/bin/p8-shared-cli.js"
33
32
  },
34
33
  "main": "dist/cjs/index.js",
@@ -36,13 +35,13 @@
36
35
  "types": "dist/types/index.d.ts",
37
36
  "license": "MIT",
38
37
  "dependencies": {
39
- "@eslint/js": "^9.28.0",
40
- "eslint": "^9.28.0",
41
- "eslint-config-prettier": "^10.1.5",
38
+ "@eslint/js": "^9.32.0",
39
+ "eslint": "^9.32.0",
40
+ "eslint-config-prettier": "^10.1.8",
42
41
  "eslint-plugin-headers": "^1.3.3",
43
- "eslint-plugin-prettier": "^5.4.1",
42
+ "eslint-plugin-prettier": "^5.5.3",
44
43
  "ferramenta": "^1.3.2",
45
- "prettier": "^3.5.3",
46
- "typescript-eslint": "^8.33.1"
44
+ "prettier": "^3.6.2",
45
+ "typescript-eslint": "^8.38.0"
47
46
  }
48
47
  }