ts-vibe 2.1.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.
package/languages/en.json CHANGED
@@ -12,11 +12,9 @@
12
12
  "dir_is_not_empty": "Dir isn't empty. Clear? ",
13
13
  "lint_tip": "- To lint the project: `npm run lint`\n",
14
14
  "prettier_tip": "- To format the code: `npm prettier`\n",
15
- "readme_content": "# ts-vibe\n[Source code](https://github.com/yar1kpr0grammer/ts-vibe)\n\n***\n**Main file** is `src/index.ts`\n\n- To run the project: `npm start`\n",
16
- "use_git": "Use git?",
15
+ "readme_content": "# ts-vibe\n[Source code](https://github.com/yar1kpr0grammer/ts-vibe)\n\n***\n\n**Main file:** `src/index.ts`\n\n## Scripts\n\n| Command | Description |\n|---|---|\n| `npm run dev` | Starts the project in development mode with watch enabled |\n| `npm start` | Runs the project once using tsx |\n| `npm run build` | Compiles TypeScript files into the `dist` folder |\n| `npm run prod` | Runs the compiled production build |\n\n\n## Project Structure\n\n```txt\nsrc/ - source code\ndist/ - compiled JavaScript output\n```\n",
17
16
  "choose_project_template": "Choose project template:",
18
- "template_min": "Minimal",
19
- "template_max": "Maximal",
17
+ "template_recommended": "Recommended",
20
18
  "template_custom": "Custom",
21
19
  "choose_packages": "Choose options:"
22
20
  }
package/languages/ru.json CHANGED
@@ -12,11 +12,9 @@
12
12
  "dir_is_not_empty": "Папка не пуста. Очистить? ",
13
13
  "lint_tip": "- Чтобы запустить проверку ошибок: `npm run lint`\n",
14
14
  "prettier_tip": "- Чтобы отформатировать код: `npm run prettier`\n",
15
- "readme_content": "# ts-vibe\n[Исходный код](https://github.com/yar1kpr0grammer/ts-bootstrap)\n\n***\n**Главный файл:** `src/index.ts`\n\n- Чтобы запустить проект: `npm start`\n",
16
- "use_git": "Использовать git?",
15
+ "readme_content": "# ts-vibe\n[Исходный код](https://github.com/yar1kpr0grammer/ts-vibe)\n\n***\n\n**Главный файл:** `src/index.ts`\n\n## Скрипты\n\n| Команда | Описание |\n|---|---|\n| `npm run dev` | Запускает проект в режиме разработки с автоматической перезагрузкой |\n| `npm start` | Запускает проект один раз через tsx |\n| `npm run build` | Компилирует TypeScript-файлы в папку `dist` |\n| `npm run prod` | Запускает production-сборку из папки `dist` |\n\n\n## Структура проекта\n\n```txt\nsrc/ - исходный код\ndist/ - скомпилированный JavaScript\n```\n",
17
16
  "choose_project_template": "Выберите вариант проекта:",
18
- "template_min": "Минимальный",
19
- "template_max": "Максимальный",
20
- "template_custom": "Настраиваемый",
17
+ "template_recommended": "Рекомендуемый",
18
+ "template_custom": "Настроить самостоятельно",
21
19
  "choose_packages": "Выберете что добавить в проект:"
22
20
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-vibe",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -22,6 +22,7 @@
22
22
  "@inquirer/checkbox": "^5.1.4",
23
23
  "@inquirer/prompts": "^8.4.2",
24
24
  "chalk": "^5.6.2",
25
- "json5": "^2.2.3"
25
+ "json5": "^2.2.3",
26
+ "ora": "^9.4.0"
26
27
  }
27
28
  }
package/src/cmd.mjs CHANGED
@@ -1,18 +1,37 @@
1
1
  import chalk from "chalk";
2
- import { spawnSync } from "child_process";
2
+ import { spawn } from "child_process";
3
3
  import readline from "readline";
4
4
 
5
5
  export function exec(command) {
6
- const result = spawnSync(command, {
7
- shell: true,
8
- encoding: "utf-8",
9
- });
6
+ return new Promise((resolve, reject) => {
7
+ const child = spawn(command, {
8
+ shell: true,
9
+ stdio: "pipe",
10
+ });
11
+
12
+ let stdout = "";
13
+ let stderr = "";
14
+
15
+ child.stdout.on("data", (data) => {
16
+ stdout += data.toString();
17
+ });
10
18
 
11
- if (result.status !== 0) {
12
- throw new Error(result.stderr || result.stdout);
13
- }
19
+ child.stderr.on("data", (data) => {
20
+ stderr += data.toString();
21
+ });
14
22
 
15
- return result.stdout;
23
+ child.on("close", (code) => {
24
+ if (code === 0) {
25
+ resolve(stdout);
26
+ } else {
27
+ reject(new Error(stderr || stdout));
28
+ }
29
+ });
30
+
31
+ child.on("error", (err) => {
32
+ reject(err);
33
+ });
34
+ });
16
35
  }
17
36
 
18
37
  const rl = readline.createInterface({
@@ -29,7 +48,8 @@ export async function ask(
29
48
  confirmVariants = ["y", "yes"],
30
49
  ) {
31
50
  const ans = await input(chalk.bold(prompt + questionPrompt));
32
- return confirmVariants.includes(ans.toLowerCase());
51
+
52
+ return confirmVariants.includes(ans.trim().toLowerCase());
33
53
  }
34
54
 
35
55
  export function closeInput() {
package/src/npm.mjs CHANGED
@@ -10,7 +10,10 @@ export function updatePackageJSON(nodeType) {
10
10
  const config = getPackageConfig();
11
11
 
12
12
  config.scripts ??= {};
13
- config.scripts.start = "tsc && node dist/index.js";
13
+ config.scripts.dev = "tsx watch src/index.ts";
14
+ config.scripts.start = "tsx src/index.ts";
15
+ config.scripts.build = "tsc";
16
+ config.scripts.prod = "node dist/index.js";
14
17
  config.type = nodeType;
15
18
 
16
19
  json.write(PACKAGE_PATH, config);
@@ -86,7 +86,7 @@ export async function init(language, config) {
86
86
  const commands = [
87
87
  { command: "npm init -y", message: "npm init -y" },
88
88
  {
89
- command: "npm i -D typescript",
89
+ command: "npm i -D typescript tsx @types/node",
90
90
  message: "npm i -D typescript",
91
91
  },
92
92
  { command: "npx tsc --init", message: "npx tsc --init" },
@@ -86,19 +86,15 @@ export async function setupProject() {
86
86
 
87
87
  console.log();
88
88
 
89
- const template = await radio("Выберите вариант проекта:", [
90
- language.template_min,
91
- language.template_max,
89
+ const template = await radio(language.choose_project_template, [
90
+ language.template_recommended,
92
91
  language.template_custom,
93
92
  ]);
94
93
 
95
94
  switch (template) {
96
- case language.template_max:
97
- config.options = allOptions;
98
- break;
99
-
100
- case language.template_min:
101
- config.options = ["README.md"];
95
+ case language.template_recommended:
96
+ config.options = ["git", "README.md", "node"];
97
+ config.nodeType = "module";
102
98
  break;
103
99
 
104
100
  case language.template_custom:
@@ -106,15 +102,13 @@ export async function setupProject() {
106
102
  language.choose_project_template,
107
103
  allOptions,
108
104
  );
105
+ console.log();
106
+ config.nodeType = await chooseNodeType(language);
109
107
  break;
110
108
  }
111
109
 
112
110
  console.log();
113
111
 
114
- config.nodeType = await chooseNodeType(language);
115
-
116
- console.log();
117
-
118
112
  return {
119
113
  name,
120
114
  language,
package/src/ts.mjs CHANGED
@@ -17,8 +17,29 @@ export function updateTsConfig() {
17
17
  throw new Error("tsconfig.json not found");
18
18
  }
19
19
 
20
- config.compilerOptions.rootDir = "./src";
21
- config.compilerOptions.outDir = "./dist";
20
+ const options = (config.compilerOptions ??= {});
21
+
22
+ options.rootDir = "./src"; // source code in src dir
23
+ options.outDir = "./dist"; // code output in dist dir
24
+ options.lib = ["ESNext"]; // adds modern JS API
25
+ options.esModuleInterop = true; // more comfortable imports
26
+ options.allowSyntheticDefaultImports = true;
27
+ options.resolveJsonModule = true; // allows to import JSON files
28
+ options.forceConsistentCasingInFileNames = true; // strict file names in imports
29
+ options.moduleResolution = "bundler"; // allows to use bundlers
30
+ options.module = "esnext"; // ts generates modern ESM
31
+
32
+ // @ in imports as src dir
33
+ options.baseUrl = ".";
34
+ options.paths ??= {};
35
+ options.paths["@/*"] = ["src/*"];
36
+
37
+ delete options.verbatimModuleSyntax;
38
+ delete options.moduleDetection;
39
+ delete options.noUncheckedSideEffectImports;
40
+ delete options.declaration;
41
+ delete options.declarationMap;
42
+
22
43
  write("tsconfig.json", config);
23
44
  }
24
45
 
package/src/utils/cmd.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import chalk from "chalk";
2
2
  import { select } from "@inquirer/prompts";
3
3
  import checkboxPrompt from "@inquirer/checkbox";
4
+ import ora from "ora";
4
5
 
5
6
  export async function confirm(
6
7
  fn,
@@ -8,15 +9,23 @@ export async function confirm(
8
9
  success = "Success",
9
10
  error = "Error",
10
11
  ) {
12
+ const spinner = ora({
13
+ text: chalk.cyan(message),
14
+ color: "cyan",
15
+ }).start();
16
+
11
17
  try {
12
18
  const res = await fn();
13
19
 
14
- console.log(`${chalk.bold(chalk.green(success))}: ${message}`);
20
+ spinner.succeed(`${chalk.bold.green(success)}: ${message}`);
21
+
15
22
  return res;
16
23
  } catch (e) {
17
- console.log(`${chalk.bold(chalk.red(error))}: ${message}`);
18
- console.error(e.message || e);
19
- return e;
24
+ spinner.fail(`${chalk.bold.red(error)}: ${message}`);
25
+
26
+ console.error(chalk.red(e instanceof Error ? e.message : String(e)));
27
+
28
+ throw e;
20
29
  }
21
30
  }
22
31
 
@@ -25,9 +34,12 @@ export async function radio(prompt, options = []) {
25
34
  throw new Error("radio: options is empty");
26
35
  }
27
36
 
28
- return await select({
29
- message: prompt,
30
- choices: options.map((o) => ({ name: o, value: o })),
37
+ return select({
38
+ message: chalk.bold(prompt),
39
+ choices: options.map((option) => ({
40
+ name: option,
41
+ value: option,
42
+ })),
31
43
  });
32
44
  }
33
45
 
@@ -36,8 +48,11 @@ export async function checkbox(prompt, options = []) {
36
48
  throw new Error("checkbox: options is empty");
37
49
  }
38
50
 
39
- return await checkboxPrompt({
40
- message: prompt,
41
- choices: options.map((o) => ({ name: o, value: o })),
51
+ return checkboxPrompt({
52
+ message: chalk.bold(prompt),
53
+ choices: options.map((option) => ({
54
+ name: option,
55
+ value: option,
56
+ })),
42
57
  });
43
58
  }