ts-vibe 2.0.5 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-vibe",
3
- "version": "2.0.5",
3
+ "version": "2.1.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -52,7 +52,7 @@ 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 "),
55
+ () => exec("npm i -D prettier "),
56
56
  "npm i -D prettier",
57
57
  language.success,
58
58
  language.error,
@@ -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
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
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
  }