@p8ec/shared 1.1.7 → 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 +22 -6
- package/dist/assets/.eslintrc.cjs +1 -0
- package/dist/assets/.eslintrc.mjs +3 -0
- package/dist/assets/.prettierrc.cjs +1 -0
- package/dist/assets/.prettierrc.mjs +3 -0
- package/dist/assets/lefthook.yml +7 -0
- package/dist/cjs/bin/p8-shared-cli.js +45 -16
- package/package.json +24 -25
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
# P(8)
|
|
1
|
+
# P(8) Shared Libraries for Node.js
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Shared TypeScript/JavaScript libraries for P(8) products.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Shared Configuration
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Shared configuration for P(8) projects.
|
|
8
8
|
|
|
9
9
|
### Usage
|
|
10
10
|
|
|
@@ -17,10 +17,11 @@ npm i -D @p8ec/shared
|
|
|
17
17
|
#### Initialization
|
|
18
18
|
|
|
19
19
|
```shell
|
|
20
|
-
p8-
|
|
20
|
+
p8-cli init
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
This command will create the following files in your project and remove corresponding configuration entries
|
|
23
|
+
This command will create the following files in your project and remove corresponding configuration entries
|
|
24
|
+
from `package.json`:
|
|
24
25
|
|
|
25
26
|
#### **`.eslintrc.js`**
|
|
26
27
|
|
|
@@ -33,3 +34,18 @@ module.exports = require('@p8ec/shared').eslintConfigRecommended;
|
|
|
33
34
|
```javascript
|
|
34
35
|
module.exports = require('@p8ec/shared').prettierConfigRecommended;
|
|
35
36
|
```
|
|
37
|
+
|
|
38
|
+
## P(8) CLI Tool
|
|
39
|
+
|
|
40
|
+
### Syntax
|
|
41
|
+
|
|
42
|
+
```shell
|
|
43
|
+
p8-cli [command] [options]
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Commands
|
|
47
|
+
|
|
48
|
+
- `init` - Initialize P(8) shared configuration in your project. Options: `cleanup` - remove configuration entries from `package.json`
|
|
49
|
+
- `dirn` - Get the directory name. Options: `0` - current directory (default), `1` - parent directory, `2` - 2 levels up
|
|
50
|
+
directory, etc.
|
|
51
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('@p8ec/shared').eslintConfigRecommended;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('@p8ec/shared').prettierConfigRecommended;
|
|
@@ -47,9 +47,11 @@ const fs = __importStar(require("fs"));
|
|
|
47
47
|
const ferramenta_1 = require("ferramenta");
|
|
48
48
|
const args = ferramenta_1.processArgs.args;
|
|
49
49
|
const self = path.parse(ferramenta_1.processArgs.name).name;
|
|
50
|
+
const writeLn = console.log;
|
|
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));
|
|
50
53
|
if (args.length === 0) {
|
|
51
|
-
|
|
52
|
-
console.log(`
|
|
54
|
+
writeLn(`
|
|
53
55
|
Usage: ${self} [command] [options]
|
|
54
56
|
|
|
55
57
|
Commands:
|
|
@@ -60,24 +62,51 @@ Commands:
|
|
|
60
62
|
`);
|
|
61
63
|
process.exit(1);
|
|
62
64
|
}
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
65
|
+
const initCleanup = (packageJson) => {
|
|
66
|
+
writeLn('Removing eslintConfig and prettier from package.json...');
|
|
67
|
+
if (packageJson['eslintConfig']) {
|
|
68
|
+
writeLn('Backing up eslintConfig to eslint.package.json.bak...');
|
|
69
|
+
writeFile('eslint.package.json.bak', packageJson['eslintConfig']);
|
|
70
|
+
delete packageJson['eslintConfig'];
|
|
71
|
+
}
|
|
72
|
+
if (packageJson['prettier']) {
|
|
73
|
+
writeLn('Backing up prettier to prettier.package.json.bak...');
|
|
74
|
+
writeFile('prettier.package.json.bak', packageJson['prettier']);
|
|
75
|
+
delete packageJson['prettier'];
|
|
76
|
+
}
|
|
77
|
+
writeFile('package.json', JSON.stringify(packageJson, null, 2));
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Initializes a TypeScript project with P8 shared configurations.
|
|
81
|
+
*/
|
|
82
|
+
const init = (option) => {
|
|
73
83
|
const packageJson = JSON.parse(String(fs.readFileSync(path.join(process.cwd(), 'package.json'))));
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Returns the directory name of the caller, optionally returns a directory name specified levels up.
|
|
97
|
+
*/
|
|
98
|
+
const dirn = (levelsUp) => {
|
|
99
|
+
const DEFAULT_LEVELS_UP = 0;
|
|
100
|
+
levelsUp !== null && levelsUp !== void 0 ? levelsUp : (levelsUp = `${DEFAULT_LEVELS_UP}`);
|
|
101
|
+
const levels = parseInt(levelsUp) || DEFAULT_LEVELS_UP;
|
|
102
|
+
return process.cwd().split(path.sep).reverse()[levels];
|
|
77
103
|
};
|
|
78
104
|
switch (args[0]) {
|
|
79
105
|
case 'init':
|
|
80
|
-
init();
|
|
106
|
+
init(args[1]);
|
|
107
|
+
break;
|
|
108
|
+
case 'dirn':
|
|
109
|
+
writeLn(dirn(args[1]));
|
|
81
110
|
break;
|
|
82
111
|
default:
|
|
83
112
|
// eslint-disable-next-line no-console
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@p8ec/shared",
|
|
3
|
-
"version": "1.
|
|
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,13 +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",
|
|
21
|
+
"cli": "ts-node src/bin/p8-shared-cli.ts",
|
|
19
22
|
"reset": "npm run clean && rm -rf node_modules && npm install",
|
|
20
|
-
"
|
|
23
|
+
"postinstall": "lefthook install",
|
|
21
24
|
"test": "jest --no-cache --runInBand",
|
|
22
25
|
"test:cov": "jest --coverage --no-cache --runInBand",
|
|
23
26
|
"lint": "eslint --cache \"src/**/*.{js,jsx,ts,tsx}\"",
|
|
@@ -27,26 +30,35 @@
|
|
|
27
30
|
"docs:clean": "rimraf docs"
|
|
28
31
|
},
|
|
29
32
|
"bin": {
|
|
30
|
-
"p8-shared-cli": "dist/cjs/bin/p8-shared-cli.js"
|
|
33
|
+
"p8-shared-cli": "dist/cjs/bin/p8-shared-cli.js",
|
|
34
|
+
"p8-cli": "dist/cjs/bin/p8-shared-cli.js"
|
|
31
35
|
},
|
|
32
36
|
"main": "dist/cjs/index.js",
|
|
33
37
|
"module": "dist/esm/index.js",
|
|
34
38
|
"types": "dist/types/index.d.ts",
|
|
35
|
-
"
|
|
39
|
+
"dependencies": {
|
|
36
40
|
"@commitlint/cli": "^19.3.0",
|
|
37
41
|
"@commitlint/config-conventional": "^19.2.2",
|
|
38
|
-
"
|
|
39
|
-
"@
|
|
40
|
-
"@
|
|
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": {
|
|
41
52
|
"@types/jest": "^29.5.12",
|
|
42
|
-
"husky": "^9.0.11",
|
|
43
53
|
"jest": "^29.7.0",
|
|
44
54
|
"lint-staged": "^15.2.5",
|
|
45
55
|
"rimraf": "^5.0.7",
|
|
46
56
|
"ts-node": "^10.9.2",
|
|
47
|
-
"typedoc": "^0.25.13",
|
|
48
57
|
"typescript": "^5.4.5"
|
|
49
58
|
},
|
|
59
|
+
"peerDependencies": {
|
|
60
|
+
"ferramenta": "^1.3.0"
|
|
61
|
+
},
|
|
50
62
|
"eslintConfig": {
|
|
51
63
|
"env": {
|
|
52
64
|
"node": true,
|
|
@@ -70,7 +82,8 @@
|
|
|
70
82
|
"*.config.ts",
|
|
71
83
|
"*.config.js",
|
|
72
84
|
"*rc.ts",
|
|
73
|
-
"*rc.js"
|
|
85
|
+
"*rc.js",
|
|
86
|
+
"src/assets"
|
|
74
87
|
],
|
|
75
88
|
"rules": {
|
|
76
89
|
"@typescript-eslint/interface-name-prefix": "off",
|
|
@@ -111,19 +124,5 @@
|
|
|
111
124
|
"extends": [
|
|
112
125
|
"@commitlint/config-conventional"
|
|
113
126
|
]
|
|
114
|
-
},
|
|
115
|
-
"license": "MIT",
|
|
116
|
-
"lint-staged1": {
|
|
117
|
-
"*.{js,jsx,ts,tsx}": "npm run lint:fix"
|
|
118
|
-
},
|
|
119
|
-
"peerDependencies": {
|
|
120
|
-
"ferramenta": "^1.3.0",
|
|
121
|
-
"@typescript-eslint/eslint-plugin": "^7.7.0",
|
|
122
|
-
"@typescript-eslint/parser": "^7.7.0",
|
|
123
|
-
"eslint": "^8 || ^9",
|
|
124
|
-
"eslint-config-prettier": "^9.1.0",
|
|
125
|
-
"eslint-plugin-header": "^3.1.1",
|
|
126
|
-
"eslint-plugin-prettier": "^5.1.0",
|
|
127
|
-
"prettier": "3.2.5"
|
|
128
127
|
}
|
|
129
128
|
}
|