@p8ec/shared 1.3.1 → 1.3.3

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.
@@ -0,0 +1,5 @@
1
+ module.exports = {
2
+ extends: [
3
+ "@commitlint/config-conventional"
4
+ ]
5
+ }
@@ -0,0 +1,5 @@
1
+ export default {
2
+ extends: [
3
+ "@commitlint/config-conventional"
4
+ ]
5
+ }
@@ -33,47 +33,46 @@ Object.defineProperty(exports, "__esModule", { value: true });
33
33
  *
34
34
  * This tool is used to simplify the process of creating new P8 components.
35
35
  *
36
- * Usage:
37
- * p8-shared [command] [options]
38
- *
39
- * Commands:
40
- * init [--flavor=recommended]
41
- * Initializes a new P8 component.
42
- * Options:
43
- * --flavor: The flavor of the component to create. Defaults to 'recommended'.
44
36
  */
45
37
  const path = __importStar(require("path"));
46
38
  const fs = __importStar(require("fs"));
47
39
  const ferramenta_1 = require("ferramenta");
40
+ const IS_DEV = process.env.NODE_ENV === 'development';
48
41
  const args = ferramenta_1.processArgs.args;
49
42
  const self = path.parse(ferramenta_1.processArgs.name).name;
50
43
  const writeLn = console.log;
51
44
  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));
45
+ const copyAsset = (name) => IS_DEV
46
+ ? fs.copyFileSync(path.join(__dirname, '..', 'assets', name), path.join(process.cwd(), name))
47
+ : fs.copyFileSync(path.join(__dirname, '..', '..', 'assets', name), path.join(process.cwd(), name));
53
48
  if (args.length === 0) {
54
49
  writeLn(`
55
50
  Usage: ${self} [command] [options]
56
51
 
57
52
  Commands:
58
- init [--flavor=recommended]
53
+ init [cleanup]
59
54
  Initializes a new P8 component.
60
55
  Options:
61
- --flavor: The flavor of the component to create. Defaults to 'recommended'.
56
+ cleanup: Removes redundant configurations from package.json.
62
57
  `);
58
+ if (IS_DEV) {
59
+ writeLn(`DEVELOPMENT MODE`);
60
+ }
63
61
  process.exit(1);
64
62
  }
65
63
  const initCleanup = (packageJson) => {
66
64
  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
- }
65
+ const configBackup = {};
66
+ const configBackupFile = 'p8-package-backup.json';
67
+ const configBackupSections = ['eslintConfig', 'prettier', 'commitlint'];
68
+ configBackupSections.forEach((section) => {
69
+ if (packageJson[section]) {
70
+ writeLn(`Backing up ${section} to ${section}.${configBackupFile}...`);
71
+ configBackup[section] = packageJson[section];
72
+ delete packageJson[section];
73
+ }
74
+ });
75
+ writeFile(`${configBackupFile}`, JSON.stringify(configBackup, null, 2));
77
76
  writeFile('package.json', JSON.stringify(packageJson, null, 2));
78
77
  };
79
78
  /**
@@ -86,6 +85,8 @@ const init = (option) => {
86
85
  copyAsset(`.eslintrc.${moduleType}`);
87
86
  writeLn(`Creating .prettierrc.${moduleType}...`);
88
87
  copyAsset(`.prettierrc.${moduleType}`);
88
+ writeLn(`Creating .commitlintrc.${moduleType}...`);
89
+ copyAsset(`.commitlintrc.${moduleType}`);
89
90
  writeLn('Creating lefthook.yml...');
90
91
  copyAsset('lefthook.yml');
91
92
  if (option === null || option === void 0 ? void 0 : option.split(',').includes('cleanup')) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@p8ec/shared",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "description": "P(8) Global Shared Library",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -18,7 +18,7 @@
18
18
  "build:types": "tsc -p configs/tsconfig.types.json",
19
19
  "build:assets": "cp -R src/assets dist",
20
20
  "clean": "rm -rf dist docs coverage",
21
- "cli": "ts-node src/bin/p8-shared-cli.ts",
21
+ "cli": "NODE_ENV=development ts-node src/bin/p8-shared-cli.ts",
22
22
  "reset": "npm run clean && rm -rf node_modules && npm install",
23
23
  "postinstall": "lefthook install",
24
24
  "test": "jest --no-cache --runInBand",