@p8ec/shared 2.5.2 → 2.6.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
@@ -64,8 +64,8 @@ p8-cli [command] [options]
64
64
  directory, etc.
65
65
  - Example: `p8-cli dirn 1` - shows the parent directory name.
66
66
  - `run` - Returns a script string using the detected or specified package manager. Options: `script` - script name,
67
- `packageManager` - npm, yarn, or pnpm (auto-detected by default), `workspaceMode` - mode of concurrency for workspaces
67
+ `packageManager` - `npm`, `yarn`, `pnpm` or `auto` (detected by default), `workspaceMode` - mode of concurrency for workspaces
68
68
  (if applicable): `seq` (default) or `par`.
69
69
  - Example: `p8-cli run build` - returns the `build` script using the detected package manager.
70
- - Example: `p8-cli run test pnpm par` - returns the `test` script using
71
- `pnpm` in parallel mode for workspaces.
70
+ - Example: `p8-cli run test auto par` - returns the `test` script using the detected
71
+ package manager in parallel mode for workspaces.
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
3
  /**
4
- * 2024 Copyright P8 Enterprise Components, Inc.
4
+ * 2026 Copyright P8 Enterprise Components, Inc.
5
5
  * All Rights Reserved.
6
6
  */
7
7
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
@@ -50,7 +50,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
50
50
  return (mod && mod.__esModule) ? mod : { "default": mod };
51
51
  };
52
52
  Object.defineProperty(exports, "__esModule", { value: true });
53
- exports.run = exports.dirn = exports.init = exports.detectPackageManager = exports.initCleanup = exports.cliUtils = exports.IS_DEV = void 0;
53
+ exports.run = exports.dirn = exports.init = exports.detectWorkspace = exports.detectPackageManager = exports.initCleanup = exports.cliUtils = exports.IS_DEV = void 0;
54
54
  /**
55
55
  * P8 Shared CLI tool.
56
56
  *
@@ -93,16 +93,8 @@ Commands:
93
93
  Returns a command to run a script with the specified package manager.
94
94
  Options:
95
95
  script: The script to run.
96
- - 'start': Starts the application.
97
- - 'build': Builds the application.
98
- - 'test': Runs tests.
99
- - 'lint': Lints the application.
100
- - 'start-workspace': Starts the workspace.
101
- - 'build-workspace': Builds the workspace.
102
- - 'test-workspace': Runs tests in the workspace.
103
- - 'lint-workspace': Lints the workspace.
104
- packageManager: The package manager to use (npm, yarn, pnpm). Defaults to npm.
105
- workspaceMode: Whether to run in workspace mode (seq or par for pnpm). Defaults to none.
96
+ packageManager: The package manager to use ('npm', 'yarn', 'pnpm' or 'auto'). Defaults to npm.
97
+ workspaceMode: Whether to run in workspace mode ('seq' or 'par' for pnpm and yarn, and 'seq' for npm). Defaults to none.
106
98
  `);
107
99
  if (exports.IS_DEV) {
108
100
  writeLn(`DEVELOPMENT MODE`);
@@ -138,6 +130,28 @@ const detectPackageManager = (cwd = process.cwd()) => {
138
130
  return 'npm';
139
131
  };
140
132
  exports.detectPackageManager = detectPackageManager;
133
+ /**
134
+ * Detects if the project is a workspace.
135
+ */
136
+ const detectWorkspace = (cwd = process.cwd()) => {
137
+ if (fs.existsSync(path.join(cwd, 'pnpm-workspace.yaml'))) {
138
+ return true;
139
+ }
140
+ const packageJsonPath = path.join(cwd, 'package.json');
141
+ if (fs.existsSync(packageJsonPath)) {
142
+ try {
143
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
144
+ if (packageJson.workspaces) {
145
+ return true;
146
+ }
147
+ }
148
+ catch (_a) {
149
+ return false;
150
+ }
151
+ }
152
+ return false;
153
+ };
154
+ exports.detectWorkspace = detectWorkspace;
141
155
  /**
142
156
  * Initializes a TypeScript project with P8 shared configurations.
143
157
  */
@@ -225,8 +239,14 @@ const dirn = (levelsUp) => {
225
239
  return process.cwd().split(path.sep).reverse()[levels];
226
240
  };
227
241
  exports.dirn = dirn;
228
- const run = (script, packageManager = (0, exports.detectPackageManager)(), workspaceMode = 'none') => {
242
+ const run = (script, packageManager = (0, exports.detectPackageManager)(), workspaceMode) => {
229
243
  var _a;
244
+ if (!workspaceMode || workspaceMode === 'none') {
245
+ workspaceMode = (0, exports.detectWorkspace)() ? 'seq' : 'none';
246
+ }
247
+ if (packageManager === 'auto') {
248
+ packageManager = (0, exports.detectPackageManager)();
249
+ }
230
250
  const pnpmWorkspaceSeq = '-r --workspace-concurrency=1 --if-present --reporter-hide-prefix';
231
251
  const pnpmWorkspacePar = '-r --if-present --parallel';
232
252
  const yarnWorkspaceSeq = 'workspaces foreach -A';
@@ -259,7 +279,7 @@ exports.run = run;
259
279
  const main = () => __awaiter(void 0, void 0, void 0, function* () {
260
280
  // Ask the user for arguments if IS_DEV is true
261
281
  if (exports.IS_DEV) {
262
- args = (yield (0, prompt_1.default)('Enter arguments: ')).split(' ');
282
+ args = (yield (0, prompt_1.default)('Enter arguments:')).split(' ');
263
283
  }
264
284
  switch (args[0]) {
265
285
  case 'init':
@@ -269,7 +289,7 @@ const main = () => __awaiter(void 0, void 0, void 0, function* () {
269
289
  writeLn((0, exports.dirn)(args[1]));
270
290
  break;
271
291
  case 'run':
272
- writeLn((0, exports.run)(args[1], args[2]));
292
+ writeLn((0, exports.run)(args[1], args[2], args[3]));
273
293
  break;
274
294
  default:
275
295
  console.error(`Unknown command: ${args[0]}`);
@@ -280,14 +300,14 @@ if (require.main === module) {
280
300
  main()
281
301
  .then((r) => {
282
302
  if (exports.IS_DEV) {
283
- writeLn(`DEV: setup completed with result: ${r}`);
303
+ writeLn(`DEV: setup completed successfully with result: ${JSON.stringify(r)}`);
284
304
  }
285
305
  })
286
306
  .catch((err) => {
287
307
  if (exports.IS_DEV) {
288
- writeLn(`DEV: setup failed with error: ${err}`);
308
+ writeLn(`DEV: setup failed with error: ${JSON.stringify(err)}`);
289
309
  }
290
- console.error(`Error: ${err}`);
310
+ console.error(err.toString());
291
311
  process.exit(1);
292
312
  });
293
313
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /**
3
- * 2024 Copyright P8 Enterprise Components, Inc.
3
+ * 2026 Copyright P8 Enterprise Components, Inc.
4
4
  * All Rights Reserved.
5
5
  */
6
6
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /**
3
- * 2024 Copyright P8 Enterprise Components, Inc.
3
+ * 2026 Copyright P8 Enterprise Components, Inc.
4
4
  * All Rights Reserved.
5
5
  */
6
6
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /**
3
- * 2024 Copyright P8 Enterprise Components, Inc.
3
+ * 2026 Copyright P8 Enterprise Components, Inc.
4
4
  * All Rights Reserved.
5
5
  */
6
6
  var __importDefault = (this && this.__importDefault) || function (mod) {
package/dist/cjs/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /**
3
- * 2024 Copyright P8 Enterprise Components, Inc.
3
+ * 2026 Copyright P8 Enterprise Components, Inc.
4
4
  * All Rights Reserved.
5
5
  */
6
6
  var __importDefault = (this && this.__importDefault) || function (mod) {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /**
3
- * 2024 Copyright P8 Enterprise Components, Inc.
3
+ * 2026 Copyright P8 Enterprise Components, Inc.
4
4
  * All Rights Reserved.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 2024 Copyright P8 Enterprise Components, Inc.
2
+ * 2026 Copyright P8 Enterprise Components, Inc.
3
3
  * All Rights Reserved.
4
4
  */
5
5
  /**
package/dist/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 2024 Copyright P8 Enterprise Components, Inc.
2
+ * 2026 Copyright P8 Enterprise Components, Inc.
3
3
  * All Rights Reserved.
4
4
  */
5
5
  import eslintConfigRecommended from './eslintConfigRecommended';
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 2024 Copyright P8 Enterprise Components, Inc.
2
+ * 2026 Copyright P8 Enterprise Components, Inc.
3
3
  * All Rights Reserved.
4
4
  */
5
5
  /**
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 2024 Copyright P8 Enterprise Components, Inc.
2
+ * 2026 Copyright P8 Enterprise Components, Inc.
3
3
  * All Rights Reserved.
4
4
  */
5
5
  import { ConfigWithExtends } from 'typescript-eslint';
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 2024 Copyright P8 Enterprise Components, Inc.
2
+ * 2026 Copyright P8 Enterprise Components, Inc.
3
3
  * All Rights Reserved.
4
4
  */
5
5
  import eslintConfigRecommended, { EslintConfigOverride } from './eslintConfigRecommended';
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 2024 Copyright P8 Enterprise Components, Inc.
2
+ * 2026 Copyright P8 Enterprise Components, Inc.
3
3
  * All Rights Reserved.
4
4
  */
5
5
  import { Options } from 'prettier';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@p8ec/shared",
3
- "version": "2.5.2",
3
+ "version": "2.6.0",
4
4
  "description": "P(8) Global Shared Library for Javascript",
5
5
  "repository": {
6
6
  "type": "git",
@@ -18,9 +18,10 @@
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:testrun": "NODE_ENV=development ts-node src/bin/p8-shared-cli.ts",
22
21
  "test": "jest --no-cache --runInBand",
23
22
  "test:cov": "jest --coverage --no-cache --runInBand",
23
+ "test:cli:dev": "NODE_ENV=development ts-node src/bin/p8-shared-cli.ts",
24
+ "test:cli": "ts-node src/bin/p8-shared-cli.ts",
24
25
  "lint": "eslint --cache \"src/**/*.{js,jsx,ts,tsx}\"",
25
26
  "lint:fix": "eslint --cache --fix \"src/**/*.{js,jsx,ts,tsx}\"",
26
27
  "docs:build": "typedoc --name 'P(8) Global Shared Library' --includeVersion --out docs src",