@adbayb/stack 2.0.0 → 2.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.
@@ -1,6 +1,6 @@
1
1
  <br>
2
2
  <div align="center">
3
- <h1>@adbayb/stack/typescript</h1>
3
+ <h1>@adbayb/stack/eslint</h1>
4
4
  <strong>My opinionated linter standards</strong>
5
5
  </div>
6
6
  <br>
package/dist/index.js CHANGED
@@ -6,10 +6,6 @@ import { writeFile, chmod, mkdir, symlink } from 'node:fs/promises';
6
6
  import { existsSync, cpSync, readFileSync, renameSync, writeFileSync, readdirSync } from 'node:fs';
7
7
  import { fdir } from 'fdir';
8
8
 
9
- var version = "2.0.0";
10
-
11
- const VERSION = version;
12
-
13
9
  const require = createRequire(import.meta.url);
14
10
  function assert(expectedCondition, createError) {
15
11
  if (!expectedCondition) {
@@ -22,7 +18,7 @@ function assert(expectedCondition, createError) {
22
18
  * @param input.title - Title input.
23
19
  * @param input.description - Description input.
24
20
  * @param input.body - Body input.
25
- * @param options - Formatting option.
21
+ * @param input.type - Message type.
26
22
  * @example
27
23
  * botMessage(
28
24
  * {
@@ -30,20 +26,27 @@ function assert(expectedCondition, createError) {
30
26
  * description:
31
27
  * "Keep calm and carry on with some coffee ☕️",
32
28
  * body: String(previousTaskError),
33
- * },
34
- * {
35
29
  * type: "error",
36
30
  * },
37
31
  * );
38
- */ const botMessage = (input, options)=>{
39
- helpers.message(`
32
+ */ const botMessage = (input)=>{
33
+ const { type } = input;
34
+ const log = type === "error" ? console.error : console.log;
35
+ const colorByType = {
36
+ error: "red",
37
+ information: "blue",
38
+ success: "green"
39
+ };
40
+ log(helpers.format(`
40
41
  ╭─────╮
41
42
  │ ◠ ◠ ${input.title}
42
- │ ${options?.type === "error" ? "◠" : "◡"} │ ${input.description}
43
+ │ ${type === "error" ? "◠" : "◡"} │ ${input.description}
43
44
  ╰─────╯
44
45
  ${!input.body ? "" : `
45
46
  ${input.body}
46
- `}`, options);
47
+ `}`, {
48
+ color: colorByType[type]
49
+ }));
47
50
  };
48
51
  /**
49
52
  * Resolve a relative path to an absolute one resolved from the generated project root directory.
@@ -165,6 +168,10 @@ const ESLINT_EXTENSIONS = [
165
168
  "mdx"
166
169
  ];
167
170
 
171
+ var version = "2.2.0";
172
+
173
+ const VERSION = version;
174
+
168
175
  const createWatchCommand = (program)=>{
169
176
  program.command({
170
177
  name: "watch",
@@ -242,7 +249,7 @@ const ifNotEqualTo = (validOption)=>(context)=>{
242
249
  const createInstallCommand = (program)=>{
243
250
  program.command({
244
251
  name: "install",
245
- description: "Setup initial requirements"
252
+ description: "Install required setup"
246
253
  }).task({
247
254
  label: label$4("Install `git.pre-commit` hook"),
248
255
  async handler () {
@@ -330,11 +337,16 @@ const createCreateCommand = (program)=>{
330
337
  handler () {
331
338
  botMessage({
332
339
  title: `I'm Stack v${VERSION}, your bot assistant`,
333
- description: "I can guarantee you a project creation in under 1 minute 🚀"
334
- }, {
340
+ description: "I can guarantee you a project creation in under 1 minute 🚀",
335
341
  type: "information"
336
342
  });
337
343
  }
344
+ }).task({
345
+ label: label$2("Check pre-requisites"),
346
+ async handler () {
347
+ // Check pnpm availability by verifying its version
348
+ await getNpmVersion();
349
+ }
338
350
  }).input({
339
351
  key: "inputName",
340
352
  label: "What's your project name?",
@@ -357,22 +369,19 @@ const createCreateCommand = (program)=>{
357
369
  "multi-projects"
358
370
  ],
359
371
  type: "select"
360
- }).task({
361
- label: label$2("Check pre-requisites"),
362
- async handler () {
363
- // Check pnpm availability by verifying its version
364
- await getNpmVersion();
365
- }
366
372
  }).task({
367
373
  key: "data",
368
- label: label$2("Evaluate contextual data"),
374
+ label: label$2("Check and format input"),
369
375
  async handler ({ inputDescription, inputName, inputUrl }) {
370
- const nodeVersion = (await request.get("https://resolve-node.vercel.app/lts", "text")).replace("v", "");
371
- const npmVersion = (await request.get("https://registry.npmjs.org/pnpm/latest", "json")).version;
376
+ if (!inputName) {
377
+ throw createError("stack create", "The project name is not optional. Make sure to provide a valid value (non-empty string).");
378
+ }
372
379
  const { repoName, repoOwner } = (inputUrl.startsWith("git") ? /^git@.*:(?<repoOwner>.*)\/(?<repoName>.*)\.git$/ : /^https?:\/\/.*\/(?<repoOwner>.*)\/(?<repoName>.*)\.git$/).exec(inputUrl)?.groups ?? {};
373
380
  if (!repoOwner || !repoName) {
374
381
  throw createError("git", "The owner and repository name can not be extracted. Please make sure to follow either `/^git@.*:(?<repoOwner>.*)/(?<repoName>.*).git$/` or `/^https?://.*/(?<repoOwner>.*)/(?<repoName>.*).git$/` pattern.");
375
382
  }
383
+ const nodeVersion = (await request.get("https://resolve-node.vercel.app/lts", "text")).replace("v", "");
384
+ const npmVersion = (await request.get("https://registry.npmjs.org/pnpm/latest", "json")).version;
376
385
  return {
377
386
  licenseYear: new Date().getFullYear().toString(),
378
387
  nodeVersion,
@@ -403,6 +412,16 @@ const createCreateCommand = (program)=>{
403
412
  handler ({ data, inputTemplate }) {
404
413
  applyTemplate(inputTemplate, data);
405
414
  }
415
+ }).task({
416
+ label: label$2("Create a symlink to `README.md` file"),
417
+ async handler ({ data: { projectName }, inputTemplate }) {
418
+ await symlink(join(inputTemplate === "single-project" ? projectName : join("libraries", projectName), "README.md"), "./README.md");
419
+ }
420
+ }).task({
421
+ label: label$2("Set up the package manager"),
422
+ async handler () {
423
+ await setPkgManager();
424
+ }
406
425
  }).task({
407
426
  label: label$2("Install dependencies"),
408
427
  async handler ({ data }) {
@@ -416,45 +435,27 @@ const createCreateCommand = (program)=>{
416
435
  try {
417
436
  await helpers.exec(`pnpm add ${globalDevDependencies.join(" ")} --save-dev --ignore-workspace-root-check`);
418
437
  await helpers.exec(`pnpm add ${localDevDependencies.join(" ")} --save-dev --filter ${data.projectName}`);
438
+ await helpers.exec("pnpm install");
419
439
  } catch (error) {
420
440
  throw createError("pnpm", error);
421
441
  }
422
442
  }
423
443
  }).task({
424
- key: "error",
425
- label: label$2("Clean up"),
426
- async handler ({ data }) {
427
- try {
428
- // Symlink the package `README.md` file to the root project directory
429
- await symlink(`./${data.projectName}/README.md`, "./README.md");
430
- // Set the Node package manager runtime by following the `packageManager` field instruction
431
- await setPkgManager();
432
- // Run install command to add git hooks
433
- await helpers.exec("stack install");
434
- // Commit (and run check/fix command via git hooks)
435
- await helpers.exec("git add -A");
436
- await helpers.exec('git commit -m "chore: initial commit"');
437
- return;
438
- } catch (error) {
439
- return error;
440
- }
444
+ label: label$2("Run `stack install`"),
445
+ async handler () {
446
+ await helpers.exec("stack install");
441
447
  }
442
448
  }).task({
443
- handler ({ data, error }) {
444
- if (error) {
445
- botMessage({
446
- title: "Oops, an error occurred",
447
- description: "Keep calm and carry on with some coffee ☕️",
448
- body: String(error)
449
- }, {
450
- type: "error"
451
- });
452
- return;
453
- }
449
+ label: label$2("Commit"),
450
+ async handler () {
451
+ await helpers.exec("git add -A");
452
+ await helpers.exec('git commit -m "chore: initial commit"');
453
+ }
454
+ }).task({
455
+ handler ({ data }) {
454
456
  botMessage({
455
457
  title: "The project was successfully created",
456
- description: `Run \`cd ./${data.projectName}\` and Enjoy 🚀`
457
- }, {
458
+ description: `Run \`cd ./${data.projectName}\` and Enjoy 🚀`,
458
459
  type: "success"
459
460
  });
460
461
  }
@@ -753,6 +754,14 @@ const createProgram = (...commandFactories)=>{
753
754
  name: "stack",
754
755
  description: "Toolbox to easily scaffold and maintain a project",
755
756
  version: VERSION
757
+ }, {
758
+ onException () {
759
+ botMessage({
760
+ title: "Oops, an error occurred",
761
+ description: "Keep calm and carry on with some coffee ☕️",
762
+ type: "error"
763
+ });
764
+ }
756
765
  });
757
766
  for (const commandBuilder of commandFactories){
758
767
  commandBuilder(program);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adbayb/stack",
3
- "version": "2.0.0",
3
+ "version": "2.2.0",
4
4
  "description": "My opinionated JavaScript-based toolchain",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "license": "MIT",
44
44
  "devDependencies": {
45
- "@types/node": "22.8.7",
45
+ "@types/node": "22.9.0",
46
46
  "quickbundle": "2.6.0"
47
47
  },
48
48
  "dependencies": {
@@ -68,11 +68,11 @@
68
68
  "eslint-plugin-sort-keys-custom-order": "^2.2.0",
69
69
  "eslint": "^9.14.0",
70
70
  "fdir": "^6.4.2",
71
- "globals": "^15.11.0",
71
+ "globals": "^15.12.0",
72
72
  "prettier": "^3.3.3",
73
73
  "termost": "^0.18.0",
74
74
  "turbo": "^2.2.3",
75
- "typescript-eslint": "^8.12.2",
75
+ "typescript-eslint": "^8.13.0",
76
76
  "typescript": "^5.6.3"
77
77
  },
78
78
  "scripts": {