ts-vibe 2.0.1 → 2.1.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/index.js CHANGED
@@ -4,17 +4,19 @@ import { init } from "./src/project/index.mjs";
4
4
  import { setupProject } from "./src/project/setup.mjs";
5
5
  import { closeInput } from "./src/cmd.mjs";
6
6
 
7
- function logInstructions(name) {
8
- console.log("\n--------------");
9
- console.log(`\ncd ${name}`);
7
+ function logInstructions(name, dir) {
8
+ console.log("\n--------------\n");
9
+ if (dir !== ".") {
10
+ console.log(`cd ${name}`);
11
+ }
10
12
  console.log(`npm start\n`);
11
13
  console.log("--------------");
12
14
  }
13
15
 
14
16
  async function main() {
15
- const { name, language, config } = await setupProject();
17
+ const { name, language, config, dir } = await setupProject();
16
18
  closeInput();
17
19
  await init(language, config);
18
- logInstructions(name);
20
+ logInstructions(name, dir);
19
21
  }
20
22
  main().catch(console.error);
package/languages/en.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "enter_project_name": "Enter project name: ",
11
11
  "name_not_valid": "Not valid",
12
12
  "dir_is_not_empty": "Dir isn't empty. Clear? ",
13
- "lint_tip": "- To lint the project: `npm lint`\n",
13
+ "lint_tip": "- To lint the project: `npm run lint`\n",
14
14
  "prettier_tip": "- To format the code: `npm prettier`\n",
15
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
16
  "use_git": "Use git?",
package/languages/ru.json CHANGED
@@ -10,8 +10,8 @@
10
10
  "enter_project_name": "Введите название проекта: ",
11
11
  "name_not_valid": "Не правильное",
12
12
  "dir_is_not_empty": "Папка не пуста. Очистить? ",
13
- "lint_tip": "- Чтобы запустить проверку ошибок: `npm lint`\n",
14
- "prettier_tip": "- Чтобы отформатировать код: `npm prettier`\n",
13
+ "lint_tip": "- Чтобы запустить проверку ошибок: `npm run lint`\n",
14
+ "prettier_tip": "- Чтобы отформатировать код: `npm run prettier`\n",
15
15
  "readme_content": "# ts-vibe\n[Исходный код](https://github.com/yar1kpr0grammer/ts-bootstrap)\n\n***\n**Главный файл:** `src/index.ts`\n\n- Чтобы запустить проект: `npm start`\n",
16
16
  "use_git": "Использовать git?",
17
17
  "choose_project_template": "Выберите вариант проекта:",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-vibe",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -38,7 +38,7 @@ async function setupLint(language, config) {
38
38
  exec(
39
39
  "npm i -D eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-config-prettier",
40
40
  ),
41
- "Install eslint",
41
+ "npm i -D eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-config-prettier",
42
42
  language.success,
43
43
  language.error,
44
44
  );
@@ -52,8 +52,8 @@ async function setupPrettier(language, config) {
52
52
  File.create(".prettierrc", config.default_code.prettierrc);
53
53
  File.create(".prettierignore", config.ignores.prettier);
54
54
  await confirm(
55
- () => exec("npm i -D prettier "),
56
- "Install prettier",
55
+ () => exec("npm i -D prettier "),
56
+ "npm i -D prettier",
57
57
  language.success,
58
58
  language.error,
59
59
  );
@@ -77,19 +77,19 @@ async function setupNode(language) {
77
77
  await exec("npm i -D @types/node");
78
78
  ts.addType("node");
79
79
  },
80
- "Add node",
80
+ "npm i -D @types/node",
81
81
  language.success,
82
82
  language.error,
83
83
  );
84
84
  }
85
85
  export async function init(language, config) {
86
86
  const commands = [
87
- { command: "npm init -y", message: "npm project init" },
87
+ { command: "npm init -y", message: "npm init -y" },
88
88
  {
89
89
  command: "npm i -D typescript",
90
- message: "install typescript",
90
+ message: "npm i -D typescript",
91
91
  },
92
- { command: "npx tsc --init", message: "init typescript" },
92
+ { command: "npx tsc --init", message: "npx tsc --init" },
93
93
  ];
94
94
 
95
95
  for (const cmd of commands) {
@@ -1,6 +1,8 @@
1
1
  import { radio, checkbox } from "../utils/cmd.mjs";
2
2
  import { input, ask } from "../cmd.mjs";
3
3
  import fs from "fs";
4
+ import path from "path";
5
+
4
6
  import languageLib from "../utils/language.mjs";
5
7
  import Path from "../fs/path.mjs";
6
8
  import { checkProjectName } from "../npm.mjs";
@@ -12,36 +14,55 @@ export async function getName(
12
14
  ) {
13
15
  process.stdin.setRawMode(false);
14
16
  process.stdin.resume();
15
- let name;
17
+
16
18
  while (true) {
17
- name = await input(prompt);
18
- if (checkProjectName(name)) {
19
- break;
19
+ const value = await input(prompt);
20
+
21
+ // "." означает текущую папку
22
+ if (value === ".") {
23
+ const currentDirName = path.basename(process.cwd());
24
+
25
+ if (checkProjectName(currentDirName)) {
26
+ return {
27
+ name: currentDirName,
28
+ dir: ".",
29
+ };
30
+ }
31
+
32
+ console.log(error);
33
+ continue;
20
34
  }
35
+
36
+ if (checkProjectName(value)) {
37
+ return {
38
+ name: value,
39
+ dir: value,
40
+ };
41
+ }
42
+
21
43
  console.log(error);
22
44
  }
23
- return name;
24
45
  }
25
46
 
26
47
  export async function chooseNodeType(language) {
27
- return await radio(language.choose_node_type, ["commonjs", "module"]);
48
+ return await radio(language.choose_node_type, ["module", "commonjs"]);
28
49
  }
29
50
 
30
- export async function prepareDir(path, language) {
31
- if (!Path.exists(path)) {
32
- Dir.create(path);
51
+ export async function prepareDir(dirPath, language) {
52
+ if (!Path.exists(dirPath)) {
53
+ Dir.create(dirPath);
33
54
  }
34
55
 
35
- Path.cd(path);
56
+ Path.cd(dirPath);
36
57
 
37
58
  if (await Dir.hasFiles()) {
38
- if (
39
- await ask(
40
- language.dir_is_not_empty,
41
- language.question_prompt,
42
- language.confirm_variants,
43
- )
44
- ) {
59
+ const shouldClear = await ask(
60
+ language.dir_is_not_empty,
61
+ language.question_prompt,
62
+ language.confirm_variants,
63
+ );
64
+
65
+ if (shouldClear) {
45
66
  await Dir.clear();
46
67
  }
47
68
  }
@@ -49,27 +70,37 @@ export async function prepareDir(path, language) {
49
70
 
50
71
  export async function setupProject() {
51
72
  const language = languageLib.init(languageLib.choose());
52
- const name = await getName(language.enter_project_name);
73
+
74
+ const { name, dir } = await getName(language.enter_project_name);
75
+
53
76
  console.log();
54
77
 
55
78
  const configPath = Path.resolveCliPath("config.json");
79
+
56
80
  const config = JSON.parse(fs.readFileSync(configPath, "utf-8"));
57
- await prepareDir(name, language);
81
+
82
+ // Используем dir, а не name
83
+ await prepareDir(dir, language);
58
84
 
59
85
  const allOptions = ["git", "eslint", "prettier", "README.md", "node"];
86
+
60
87
  console.log();
61
- const res = await radio("Выберите вариант проекта:", [
88
+
89
+ const template = await radio("Выберите вариант проекта:", [
62
90
  language.template_min,
63
91
  language.template_max,
64
92
  language.template_custom,
65
93
  ]);
66
- switch (res) {
94
+
95
+ switch (template) {
67
96
  case language.template_max:
68
97
  config.options = allOptions;
69
98
  break;
99
+
70
100
  case language.template_min:
71
- config.options = [];
101
+ config.options = ["README.md"];
72
102
  break;
103
+
73
104
  case language.template_custom:
74
105
  config.options = await checkbox(
75
106
  language.choose_project_template,
@@ -77,10 +108,17 @@ export async function setupProject() {
77
108
  );
78
109
  break;
79
110
  }
111
+
80
112
  console.log();
81
113
 
82
114
  config.nodeType = await chooseNodeType(language);
115
+
83
116
  console.log();
84
117
 
85
- return { name, language, config };
118
+ return {
119
+ name,
120
+ language,
121
+ config,
122
+ dir,
123
+ };
86
124
  }
package/src/ts.mjs CHANGED
@@ -10,7 +10,7 @@ export function readConfig() {
10
10
 
11
11
  export function updateTsConfig() {
12
12
  if (!config) {
13
- readConfig(); // автоматически читаем, если еще не прочитан
13
+ readConfig();
14
14
  }
15
15
 
16
16
  if (!config) {
@@ -24,7 +24,7 @@ export function updateTsConfig() {
24
24
 
25
25
  export function addType(typeName) {
26
26
  if (!config) {
27
- readConfig(); // автоматически читаем, если еще не прочитан
27
+ readConfig();
28
28
  }
29
29
 
30
30
  if (!config) {