@p8ec/shared 1.2.0 → 1.3.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.
package/README.md CHANGED
@@ -45,7 +45,7 @@ p8-cli [command] [options]
45
45
 
46
46
  ### Commands
47
47
 
48
- - `init` - Initialize P(8) shared configuration in your project.
48
+ - `init` - Initialize P(8) shared configuration in your project. Options: `cleanup` - remove configuration entries from `package.json`
49
49
  - `dirn` - Get the directory name. Options: `0` - current directory (default), `1` - parent directory, `2` - 2 levels up
50
50
  directory, etc.
51
51
 
@@ -0,0 +1 @@
1
+ module.exports = require('@p8ec/shared').eslintConfigRecommended;
@@ -0,0 +1,3 @@
1
+ import { eslintConfigRecommended } from '@p8ec/shared';
2
+
3
+ export default eslintConfigRecommended;
@@ -0,0 +1 @@
1
+ module.exports = require('@p8ec/shared').prettierConfigRecommended;
@@ -0,0 +1,3 @@
1
+ import { prettierConfigRecommended } from '@p8ec/shared';
2
+
3
+ export default prettierConfigRecommended;
@@ -0,0 +1,7 @@
1
+ # Refer for explanation to following link:
2
+ # https://github.com/evilmartians/lefthook/blob/master/docs/configuration.md
3
+
4
+ commit-msg:
5
+ commands:
6
+ commitlint:
7
+ run: npx --no -- commitlint --edit {1}
@@ -49,6 +49,7 @@ const args = ferramenta_1.processArgs.args;
49
49
  const self = path.parse(ferramenta_1.processArgs.name).name;
50
50
  const writeLn = console.log;
51
51
  const writeFile = (name, data) => fs.writeFileSync(path.join(process.cwd(), name), data);
52
+ const copyAsset = (name) => fs.copyFileSync(path.join(__dirname, '..', 'assets', name), path.join(process.cwd(), name));
52
53
  if (args.length === 0) {
53
54
  writeLn(`
54
55
  Usage: ${self} [command] [options]
@@ -61,17 +62,8 @@ Commands:
61
62
  `);
62
63
  process.exit(1);
63
64
  }
64
- /**
65
- * Initializes a TypeScript project with P8 shared configurations.
66
- */
67
- const init = () => {
68
- writeLn('Creating .eslintrc.js...');
69
- writeFile('.eslintrc.js', `module.exports = require('@p8ec/shared').eslintConfigRecommended;`);
70
- writeLn('Creating .prettierrc.js...');
71
- writeFile('.prettierrc.js', `module.exports = require('@p8ec/shared').prettierConfigRecommended;`);
72
- // Cleanup package.json
65
+ const initCleanup = (packageJson) => {
73
66
  writeLn('Removing eslintConfig and prettier from package.json...');
74
- const packageJson = JSON.parse(String(fs.readFileSync(path.join(process.cwd(), 'package.json'))));
75
67
  if (packageJson['eslintConfig']) {
76
68
  writeLn('Backing up eslintConfig to eslint.package.json.bak...');
77
69
  writeFile('eslint.package.json.bak', packageJson['eslintConfig']);
@@ -84,6 +76,22 @@ const init = () => {
84
76
  }
85
77
  writeFile('package.json', JSON.stringify(packageJson, null, 2));
86
78
  };
79
+ /**
80
+ * Initializes a TypeScript project with P8 shared configurations.
81
+ */
82
+ const init = (option) => {
83
+ const packageJson = JSON.parse(String(fs.readFileSync(path.join(process.cwd(), 'package.json'))));
84
+ const moduleType = packageJson['type'] === 'module' ? 'mjs' : 'cjs';
85
+ writeLn(`Creating .eslintrc.${moduleType}...`);
86
+ copyAsset(`.eslintrc.${moduleType}`);
87
+ writeLn(`Creating .prettierrc.${moduleType}...`);
88
+ copyAsset(`.prettierrc.${moduleType}`);
89
+ writeLn('Creating lefthook.yml...');
90
+ copyAsset('lefthook.yml');
91
+ if (option.split(',').includes('cleanup')) {
92
+ initCleanup(packageJson);
93
+ }
94
+ };
87
95
  /**
88
96
  * Returns the directory name of the caller, optionally returns a directory name specified levels up.
89
97
  */
@@ -93,15 +101,9 @@ const dirn = (levelsUp) => {
93
101
  const levels = parseInt(levelsUp) || DEFAULT_LEVELS_UP;
94
102
  return process.cwd().split(path.sep).reverse()[levels];
95
103
  };
96
- /**
97
- * Returns the caller PID
98
- */
99
- const pid = () => {
100
- return process.pid;
101
- };
102
104
  switch (args[0]) {
103
105
  case 'init':
104
- init();
106
+ init(args[1]);
105
107
  break;
106
108
  case 'dirn':
107
109
  writeLn(dirn(args[1]));
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@p8ec/shared",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "P(8) Global Shared Library",
5
+ "license": "MIT",
5
6
  "repository": {
6
7
  "type": "git",
7
8
  "url": "git+https://github.com/p8ec/p8-shared.git"
@@ -11,14 +12,15 @@
11
12
  },
12
13
  "homepage": "https://github.com/p8ec/p8-shared",
13
14
  "scripts": {
14
- "build": "npm run clean && npm run build:esm && npm run build:cjs && npm run build:types",
15
+ "build": "npm run clean && npm run build:esm && npm run build:cjs && npm run build:types && npm run build:assets",
15
16
  "build:esm": "tsc -p configs/tsconfig.esm.json",
16
17
  "build:cjs": "tsc -p configs/tsconfig.cjs.json && chmod -R +x dist/cjs/bin/*.js",
17
18
  "build:types": "tsc -p configs/tsconfig.types.json",
19
+ "build:assets": "cp -R src/assets dist",
18
20
  "clean": "rm -rf dist docs coverage",
19
21
  "cli": "ts-node src/bin/p8-shared-cli.ts",
20
22
  "reset": "npm run clean && rm -rf node_modules && npm install",
21
- "prepare": "husky install",
23
+ "postinstall": "lefthook install",
22
24
  "test": "jest --no-cache --runInBand",
23
25
  "test:cov": "jest --coverage --no-cache --runInBand",
24
26
  "lint": "eslint --cache \"src/**/*.{js,jsx,ts,tsx}\"",
@@ -34,21 +36,29 @@
34
36
  "main": "dist/cjs/index.js",
35
37
  "module": "dist/esm/index.js",
36
38
  "types": "dist/types/index.d.ts",
37
- "devDependencies": {
39
+ "dependencies": {
38
40
  "@commitlint/cli": "^19.3.0",
39
41
  "@commitlint/config-conventional": "^19.2.2",
40
- "@swc/cli": "^0.3.12",
41
- "@swc/core": "^1.5.27",
42
- "@swc/jest": "^0.2.36",
42
+ "lefthook": "^1.7.6",
43
+ "@typescript-eslint/eslint-plugin": "^7",
44
+ "@typescript-eslint/parser": "^7.7.0",
45
+ "eslint": "^8 || ^9",
46
+ "eslint-config-prettier": "^9",
47
+ "eslint-plugin-header": "^3",
48
+ "eslint-plugin-prettier": "^5",
49
+ "prettier": "^3.3.3"
50
+ },
51
+ "devDependencies": {
43
52
  "@types/jest": "^29.5.12",
44
- "husky": "^9.0.11",
45
53
  "jest": "^29.7.0",
46
54
  "lint-staged": "^15.2.5",
47
55
  "rimraf": "^5.0.7",
48
56
  "ts-node": "^10.9.2",
49
- "typedoc": "^0.25.13",
50
57
  "typescript": "^5.4.5"
51
58
  },
59
+ "peerDependencies": {
60
+ "ferramenta": "^1.3.0"
61
+ },
52
62
  "eslintConfig": {
53
63
  "env": {
54
64
  "node": true,
@@ -72,7 +82,8 @@
72
82
  "*.config.ts",
73
83
  "*.config.js",
74
84
  "*rc.ts",
75
- "*rc.js"
85
+ "*rc.js",
86
+ "src/assets"
76
87
  ],
77
88
  "rules": {
78
89
  "@typescript-eslint/interface-name-prefix": "off",
@@ -113,19 +124,5 @@
113
124
  "extends": [
114
125
  "@commitlint/config-conventional"
115
126
  ]
116
- },
117
- "license": "MIT",
118
- "lint-staged1": {
119
- "*.{js,jsx,ts,tsx}": "npm run lint:fix"
120
- },
121
- "peerDependencies": {
122
- "@typescript-eslint/eslint-plugin": "^7",
123
- "@typescript-eslint/parser": "^7.7.0",
124
- "eslint": "^8 || ^9",
125
- "eslint-config-prettier": "^9",
126
- "eslint-plugin-header": "^3",
127
- "eslint-plugin-prettier": "^5",
128
- "ferramenta": "^1.3.0",
129
- "prettier": "^3.3.3"
130
127
  }
131
128
  }