@p8ec/shared 1.1.7 → 1.2.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/cjs/bin/p8-shared-cli.js +41 -14
- package/package.json +10 -8
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.
|
|
49
|
+
- `dirn` - Get the directory name. Options: `0` - current directory (default), `1` - parent directory, `2` - 2 levels up
|
|
50
|
+
directory, etc.
|
|
51
|
+
|
|
@@ -47,9 +47,10 @@ 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);
|
|
50
52
|
if (args.length === 0) {
|
|
51
|
-
|
|
52
|
-
console.log(`
|
|
53
|
+
writeLn(`
|
|
53
54
|
Usage: ${self} [command] [options]
|
|
54
55
|
|
|
55
56
|
Commands:
|
|
@@ -60,25 +61,51 @@ Commands:
|
|
|
60
61
|
`);
|
|
61
62
|
process.exit(1);
|
|
62
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Initializes a TypeScript project with P8 shared configurations.
|
|
66
|
+
*/
|
|
63
67
|
const init = () => {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
// Remove eslintConfig and prettier from package.json
|
|
71
|
-
// eslint-disable-next-line no-console
|
|
72
|
-
console.log('Removing eslintConfig and prettier from package.json...');
|
|
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
|
|
73
|
+
writeLn('Removing eslintConfig and prettier from package.json...');
|
|
73
74
|
const packageJson = JSON.parse(String(fs.readFileSync(path.join(process.cwd(), 'package.json'))));
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
if (packageJson['eslintConfig']) {
|
|
76
|
+
writeLn('Backing up eslintConfig to eslint.package.json.bak...');
|
|
77
|
+
writeFile('eslint.package.json.bak', packageJson['eslintConfig']);
|
|
78
|
+
delete packageJson['eslintConfig'];
|
|
79
|
+
}
|
|
80
|
+
if (packageJson['prettier']) {
|
|
81
|
+
writeLn('Backing up prettier to prettier.package.json.bak...');
|
|
82
|
+
writeFile('prettier.package.json.bak', packageJson['prettier']);
|
|
83
|
+
delete packageJson['prettier'];
|
|
84
|
+
}
|
|
85
|
+
writeFile('package.json', JSON.stringify(packageJson, null, 2));
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Returns the directory name of the caller, optionally returns a directory name specified levels up.
|
|
89
|
+
*/
|
|
90
|
+
const dirn = (levelsUp) => {
|
|
91
|
+
const DEFAULT_LEVELS_UP = 0;
|
|
92
|
+
levelsUp !== null && levelsUp !== void 0 ? levelsUp : (levelsUp = `${DEFAULT_LEVELS_UP}`);
|
|
93
|
+
const levels = parseInt(levelsUp) || DEFAULT_LEVELS_UP;
|
|
94
|
+
return process.cwd().split(path.sep).reverse()[levels];
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Returns the caller PID
|
|
98
|
+
*/
|
|
99
|
+
const pid = () => {
|
|
100
|
+
return process.pid;
|
|
77
101
|
};
|
|
78
102
|
switch (args[0]) {
|
|
79
103
|
case 'init':
|
|
80
104
|
init();
|
|
81
105
|
break;
|
|
106
|
+
case 'dirn':
|
|
107
|
+
writeLn(dirn(args[1]));
|
|
108
|
+
break;
|
|
82
109
|
default:
|
|
83
110
|
// eslint-disable-next-line no-console
|
|
84
111
|
console.error(`Unknown command: ${args[0]}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@p8ec/shared",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "P(8) Global Shared Library",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"build:cjs": "tsc -p configs/tsconfig.cjs.json && chmod -R +x dist/cjs/bin/*.js",
|
|
17
17
|
"build:types": "tsc -p configs/tsconfig.types.json",
|
|
18
18
|
"clean": "rm -rf dist docs coverage",
|
|
19
|
+
"cli": "ts-node src/bin/p8-shared-cli.ts",
|
|
19
20
|
"reset": "npm run clean && rm -rf node_modules && npm install",
|
|
20
21
|
"prepare": "husky install",
|
|
21
22
|
"test": "jest --no-cache --runInBand",
|
|
@@ -27,7 +28,8 @@
|
|
|
27
28
|
"docs:clean": "rimraf docs"
|
|
28
29
|
},
|
|
29
30
|
"bin": {
|
|
30
|
-
"p8-shared-cli": "dist/cjs/bin/p8-shared-cli.js"
|
|
31
|
+
"p8-shared-cli": "dist/cjs/bin/p8-shared-cli.js",
|
|
32
|
+
"p8-cli": "dist/cjs/bin/p8-shared-cli.js"
|
|
31
33
|
},
|
|
32
34
|
"main": "dist/cjs/index.js",
|
|
33
35
|
"module": "dist/esm/index.js",
|
|
@@ -117,13 +119,13 @@
|
|
|
117
119
|
"*.{js,jsx,ts,tsx}": "npm run lint:fix"
|
|
118
120
|
},
|
|
119
121
|
"peerDependencies": {
|
|
120
|
-
"
|
|
121
|
-
"@typescript-eslint/eslint-plugin": "^7.7.0",
|
|
122
|
+
"@typescript-eslint/eslint-plugin": "^7",
|
|
122
123
|
"@typescript-eslint/parser": "^7.7.0",
|
|
123
124
|
"eslint": "^8 || ^9",
|
|
124
|
-
"eslint-config-prettier": "^9
|
|
125
|
-
"eslint-plugin-header": "^3
|
|
126
|
-
"eslint-plugin-prettier": "^5
|
|
127
|
-
"
|
|
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"
|
|
128
130
|
}
|
|
129
131
|
}
|