ts-vibe 2.0.5 → 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/index.js +7 -5
- package/languages/en.json +2 -4
- package/languages/ru.json +3 -5
- package/package.json +3 -2
- package/src/cmd.mjs +30 -10
- package/src/npm.mjs +4 -1
- package/src/project/index.mjs +2 -2
- package/src/project/setup.mjs +62 -30
- package/src/ts.mjs +23 -2
- package/src/utils/cmd.mjs +25 -10
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
|
-
|
|
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
|
@@ -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
|
|
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
|
-
"
|
|
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-
|
|
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
|
-
"
|
|
19
|
-
"
|
|
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.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 {
|
|
2
|
+
import { spawn } from "child_process";
|
|
3
3
|
import readline from "readline";
|
|
4
4
|
|
|
5
5
|
export function exec(command) {
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
19
|
+
child.stderr.on("data", (data) => {
|
|
20
|
+
stderr += data.toString();
|
|
21
|
+
});
|
|
14
22
|
|
|
15
|
-
|
|
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
|
-
|
|
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.
|
|
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);
|
package/src/project/index.mjs
CHANGED
|
@@ -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
|
|
55
|
+
() => exec("npm i -D prettier "),
|
|
56
56
|
"npm i -D prettier",
|
|
57
57
|
language.success,
|
|
58
58
|
language.error,
|
|
@@ -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" },
|
package/src/project/setup.mjs
CHANGED
|
@@ -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
|
-
|
|
17
|
+
|
|
16
18
|
while (true) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (checkProjectName(value)) {
|
|
37
|
+
return {
|
|
38
|
+
name: value,
|
|
39
|
+
dir: value,
|
|
40
|
+
};
|
|
20
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(
|
|
31
|
-
if (!Path.exists(
|
|
32
|
-
Dir.create(
|
|
51
|
+
export async function prepareDir(dirPath, language) {
|
|
52
|
+
if (!Path.exists(dirPath)) {
|
|
53
|
+
Dir.create(dirPath);
|
|
33
54
|
}
|
|
34
55
|
|
|
35
|
-
Path.cd(
|
|
56
|
+
Path.cd(dirPath);
|
|
36
57
|
|
|
37
58
|
if (await Dir.hasFiles()) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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,38 +70,49 @@ export async function prepareDir(path, language) {
|
|
|
49
70
|
|
|
50
71
|
export async function setupProject() {
|
|
51
72
|
const language = languageLib.init(languageLib.choose());
|
|
52
|
-
|
|
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
|
-
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
language.
|
|
88
|
+
|
|
89
|
+
const template = await radio(language.choose_project_template, [
|
|
90
|
+
language.template_recommended,
|
|
64
91
|
language.template_custom,
|
|
65
92
|
]);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
config.options = ["README.md"];
|
|
93
|
+
|
|
94
|
+
switch (template) {
|
|
95
|
+
case language.template_recommended:
|
|
96
|
+
config.options = ["git", "README.md", "node"];
|
|
97
|
+
config.nodeType = "module";
|
|
72
98
|
break;
|
|
99
|
+
|
|
73
100
|
case language.template_custom:
|
|
74
101
|
config.options = await checkbox(
|
|
75
102
|
language.choose_project_template,
|
|
76
103
|
allOptions,
|
|
77
104
|
);
|
|
105
|
+
console.log();
|
|
106
|
+
config.nodeType = await chooseNodeType(language);
|
|
78
107
|
break;
|
|
79
108
|
}
|
|
80
|
-
console.log();
|
|
81
109
|
|
|
82
|
-
config.nodeType = await chooseNodeType(language);
|
|
83
110
|
console.log();
|
|
84
111
|
|
|
85
|
-
return {
|
|
112
|
+
return {
|
|
113
|
+
name,
|
|
114
|
+
language,
|
|
115
|
+
config,
|
|
116
|
+
dir,
|
|
117
|
+
};
|
|
86
118
|
}
|
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
|
|
21
|
-
|
|
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
|
-
|
|
20
|
+
spinner.succeed(`${chalk.bold.green(success)}: ${message}`);
|
|
21
|
+
|
|
15
22
|
return res;
|
|
16
23
|
} catch (e) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
|
29
|
-
message: prompt,
|
|
30
|
-
choices: options.map((
|
|
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
|
|
40
|
-
message: prompt,
|
|
41
|
-
choices: options.map((
|
|
51
|
+
return checkboxPrompt({
|
|
52
|
+
message: chalk.bold(prompt),
|
|
53
|
+
choices: options.map((option) => ({
|
|
54
|
+
name: option,
|
|
55
|
+
value: option,
|
|
56
|
+
})),
|
|
42
57
|
});
|
|
43
58
|
}
|