klei-cli 1.0.3 → 1.0.7
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/README.md +13 -7
- package/bin/cli.js +85 -22
- package/package.json +74 -74
package/README.md
CHANGED
|
@@ -16,7 +16,19 @@ pnpm install -g klei-cli
|
|
|
16
16
|
|
|
17
17
|
Para usar la CLI, puedes ejecutar los siguientes comandos:
|
|
18
18
|
|
|
19
|
-
###
|
|
19
|
+
### create
|
|
20
|
+
|
|
21
|
+
Este comando crea un nuevo proyecto.
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# klei create <nombre> [opciones]
|
|
25
|
+
# klei create mi-proyecto
|
|
26
|
+
# klei create --t npmjs
|
|
27
|
+
# klei create --type npmjs
|
|
28
|
+
klei create mi-proyecto --type npmjs
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### help
|
|
20
32
|
|
|
21
33
|
Este comando muestra la ayuda y los comandos disponibles.
|
|
22
34
|
|
|
@@ -30,12 +42,6 @@ klei help
|
|
|
30
42
|
- `--t, --type <type>`: Especifica el tipo de proyecto.
|
|
31
43
|
- `help`: Muestra la ayuda y los comandos disponibles.
|
|
32
44
|
|
|
33
|
-
## Ejemplos
|
|
34
|
-
|
|
35
|
-
```bash
|
|
36
|
-
klei create mi-proyecto --type npmjs
|
|
37
|
-
```
|
|
38
|
-
|
|
39
45
|
## Contribuir
|
|
40
46
|
|
|
41
47
|
Si deseas contribuir a este proyecto, por favor sigue los siguientes pasos:
|
package/bin/cli.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// src/index.ts
|
|
5
5
|
import chalk4 from "chalk";
|
|
6
6
|
import { program } from "commander";
|
|
7
|
+
import fs3 from "fs";
|
|
7
8
|
|
|
8
9
|
// src/utils/banner.ts
|
|
9
10
|
import chalk from "chalk";
|
|
@@ -47,10 +48,10 @@ var npmjs = [
|
|
|
47
48
|
scripts: {
|
|
48
49
|
start: "tsx src/index.ts",
|
|
49
50
|
xtart: "npx -y tsx src/index.ts",
|
|
50
|
-
watch: 'tsup --entry.index src/index.ts --watch --onSuccess "node dist/index.js"',
|
|
51
|
-
build: "tsup --entry.index src/index.ts --format esm,cjs --dts",
|
|
52
|
-
"test:esm": 'tsup --entry.test src/index.ts --format esm --
|
|
53
|
-
"test:spec": 'tsup test/test.spec.ts --format esm --onSuccess "cross-env NODE_ENV=test node --test dist/test.spec.js"'
|
|
51
|
+
watch: 'tsup --entry.index src/index.ts --format esm --clean --watch --onSuccess "node dist/index.js"',
|
|
52
|
+
build: "tsup --entry.index src/index.ts --format esm,cjs --dts --clean",
|
|
53
|
+
"test:esm": 'tsup --entry.test src/index.ts --format esm --clean --onSuccess "node dist/test.js"',
|
|
54
|
+
"test:spec": 'tsup test/test.spec.ts --format esm --clean --onSuccess "cross-env NODE_ENV=test node --test dist/test.spec.js"'
|
|
54
55
|
},
|
|
55
56
|
keywords: [],
|
|
56
57
|
author: "",
|
|
@@ -60,7 +61,7 @@ var npmjs = [
|
|
|
60
61
|
"@eslint/js": "latest",
|
|
61
62
|
// "@types/assert": 'latest',
|
|
62
63
|
"@types/node": "latest",
|
|
63
|
-
|
|
64
|
+
"cross-env": "latest",
|
|
64
65
|
eslint: "latest",
|
|
65
66
|
nodemon: "latest",
|
|
66
67
|
"ts-node": "latest",
|
|
@@ -89,15 +90,16 @@ export default defineConfig(${JSON.stringify({
|
|
|
89
90
|
$schema: "https://json.schemastore.org/tsconfig",
|
|
90
91
|
display: "Default",
|
|
91
92
|
compilerOptions: {
|
|
92
|
-
target: "
|
|
93
|
-
module: "
|
|
94
|
-
outDir:
|
|
95
|
-
rootDir:
|
|
93
|
+
target: "ES2024",
|
|
94
|
+
module: "ES2022",
|
|
95
|
+
// outDir: './dist',
|
|
96
|
+
// rootDir: './src',
|
|
96
97
|
strict: true,
|
|
97
98
|
esModuleInterop: true,
|
|
98
99
|
skipLibCheck: true,
|
|
99
100
|
forceConsistentCasingInFileNames: true,
|
|
100
101
|
declaration: true,
|
|
102
|
+
moduleResolution: "node",
|
|
101
103
|
resolveJsonModule: true,
|
|
102
104
|
noUnusedLocals: false,
|
|
103
105
|
noImplicitThis: false,
|
|
@@ -109,8 +111,8 @@ export default defineConfig(${JSON.stringify({
|
|
|
109
111
|
]
|
|
110
112
|
}
|
|
111
113
|
},
|
|
112
|
-
include: ["
|
|
113
|
-
exclude: ["node_modules", "
|
|
114
|
+
include: ["."],
|
|
115
|
+
exclude: ["node_modules", "dist", "build", "docs"]
|
|
114
116
|
}, null, 2),
|
|
115
117
|
pathFileName: "tsconfig.json"
|
|
116
118
|
},
|
|
@@ -129,12 +131,12 @@ interface User {
|
|
|
129
131
|
type GreetUser = (user: User) => string;
|
|
130
132
|
|
|
131
133
|
// Example implementation of the GreetUser function
|
|
132
|
-
const greetUser: GreetUser = (user) => {
|
|
134
|
+
export const greetUser: GreetUser = (user) => {
|
|
133
135
|
return \`Hello, \${user.name}! Your email is \${user.email}.\`;
|
|
134
136
|
};
|
|
135
137
|
|
|
136
138
|
// Example usage
|
|
137
|
-
const exampleUser: User = {
|
|
139
|
+
export const exampleUser: User = {
|
|
138
140
|
id: 1,
|
|
139
141
|
name: 'John Doe',
|
|
140
142
|
email: 'john.doe@example.com',
|
|
@@ -169,19 +171,43 @@ export default tseslint.config(
|
|
|
169
171
|
'spaced-comment': ['error', 'always', { markers: ['/'] }],
|
|
170
172
|
'comma-dangle': ['error', 'never'],
|
|
171
173
|
'no-multiple-empty-lines': ['error', { max: 1 }],
|
|
172
|
-
'no-async-promise-executor': 'off'
|
|
174
|
+
'no-async-promise-executor': 'off',
|
|
175
|
+
'no-unused-vars': 'warn',
|
|
176
|
+
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }]
|
|
173
177
|
}
|
|
174
178
|
}
|
|
175
179
|
)`,
|
|
176
180
|
pathFileName: "eslint.config.mjs"
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
content: `// \u2501\u2501 IMPORT MODULES \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
|
|
184
|
+
// \xBB IMPORT NATIVE NODE MODULES
|
|
185
|
+
|
|
186
|
+
import { describe, it } from 'node:test'
|
|
187
|
+
|
|
188
|
+
import assert from 'node:assert'
|
|
189
|
+
|
|
190
|
+
// \xBB IMPORT MODULES
|
|
191
|
+
import { greetUser, exampleUser } from '@/index'
|
|
192
|
+
|
|
193
|
+
// \u2501\u2501 TEST \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
|
|
194
|
+
|
|
195
|
+
describe('greetUser', () => {
|
|
196
|
+
it('should return a greeting message with the provided name', () => {
|
|
197
|
+
const result = greetUser(exampleUser)
|
|
198
|
+
assert.strictEqual(result, 'Hello, John Doe! Your email is john.doe@example.com.')
|
|
199
|
+
})
|
|
200
|
+
})`,
|
|
201
|
+
pathFileName: "test/test.spec.ts"
|
|
177
202
|
}
|
|
178
203
|
];
|
|
179
204
|
|
|
180
|
-
// src/lib/utils/npm-utils.
|
|
205
|
+
// src/lib/utils/npm-utils.ts
|
|
181
206
|
import fs from "node:fs";
|
|
182
207
|
import spawn from "cross-spawn";
|
|
183
208
|
import path from "node:path";
|
|
184
209
|
import process2 from "node:process";
|
|
210
|
+
import console2 from "node:console";
|
|
185
211
|
function findPackageJson(startDir) {
|
|
186
212
|
let dir = path.resolve(startDir || process2.cwd());
|
|
187
213
|
do {
|
|
@@ -197,11 +223,15 @@ function findPackageJson(startDir) {
|
|
|
197
223
|
function installSyncSaveDev(packages, packageManager = "npm", cwd, installFlags = ["-D"]) {
|
|
198
224
|
const packageList = Array.isArray(packages) ? packages : [packages];
|
|
199
225
|
const installCmd = packageManager === "yarn" ? "add" : "install";
|
|
200
|
-
const installProcess = spawn.sync(
|
|
226
|
+
const installProcess = spawn.sync(
|
|
227
|
+
packageManager,
|
|
228
|
+
[installCmd, ...installFlags].concat(packageList),
|
|
229
|
+
{ stdio: "inherit", cwd }
|
|
230
|
+
);
|
|
201
231
|
const error = installProcess.error;
|
|
202
232
|
if (error && error.code === "ENOENT") {
|
|
203
233
|
const pluralS = packageList.length > 1 ? "s" : "";
|
|
204
|
-
|
|
234
|
+
console2.error(`Could not execute ${packageManager}. Please install the following package${pluralS} with a package manager of your choice: ${packageList.join(", ")}`);
|
|
205
235
|
}
|
|
206
236
|
}
|
|
207
237
|
function parsePackageName(packageName) {
|
|
@@ -213,8 +243,8 @@ function parsePackageName(packageName) {
|
|
|
213
243
|
}
|
|
214
244
|
return { name: packageName, version: "latest" };
|
|
215
245
|
}
|
|
216
|
-
function getPkgs(
|
|
217
|
-
return JSON.parse(fs.readFileSync(
|
|
246
|
+
function getPkgs(filePath) {
|
|
247
|
+
return JSON.parse(fs.readFileSync(filePath, "utf-8"));
|
|
218
248
|
}
|
|
219
249
|
|
|
220
250
|
// src/utils/project.ts
|
|
@@ -235,6 +265,39 @@ var createProjectStructure = async (answers, spinner) => {
|
|
|
235
265
|
for (const file of projectStr) {
|
|
236
266
|
const { content, pathFileName } = file;
|
|
237
267
|
const filePath = path2.join(projectDir, pathFileName);
|
|
268
|
+
if (answers.projectName === "." && pathFileName === "package.json") {
|
|
269
|
+
spinner.info(`Actualizando ${chalk2.yellow("package.json")} existente`);
|
|
270
|
+
try {
|
|
271
|
+
const currentPackageJsonPath = path2.join(process.cwd(), "package.json");
|
|
272
|
+
let currentPackageJson = {};
|
|
273
|
+
if (fs2.existsSync(currentPackageJsonPath)) {
|
|
274
|
+
const currentContent = fs2.readFileSync(currentPackageJsonPath, "utf-8");
|
|
275
|
+
currentPackageJson = JSON.parse(currentContent);
|
|
276
|
+
}
|
|
277
|
+
const templatePackageJson = JSON.parse(content);
|
|
278
|
+
const mergedPackageJson = {
|
|
279
|
+
...currentPackageJson,
|
|
280
|
+
...templatePackageJson,
|
|
281
|
+
dependencies: {
|
|
282
|
+
...currentPackageJson.dependencies,
|
|
283
|
+
...templatePackageJson.dependencies
|
|
284
|
+
},
|
|
285
|
+
devDependencies: {
|
|
286
|
+
...currentPackageJson.devDependencies,
|
|
287
|
+
...templatePackageJson.devDependencies
|
|
288
|
+
},
|
|
289
|
+
scripts: {
|
|
290
|
+
...currentPackageJson.scripts,
|
|
291
|
+
...templatePackageJson.scripts
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
fs2.writeFileSync(currentPackageJsonPath, JSON.stringify(mergedPackageJson, null, 2));
|
|
295
|
+
spinner.succeed(`${chalk2.green("package.json actualizado exitosamente")}`);
|
|
296
|
+
} catch (error) {
|
|
297
|
+
spinner.warn(`Error al actualizar package.json: ${error}`);
|
|
298
|
+
}
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
238
301
|
if (answers.projectName === "." && fs2.existsSync(filePath)) {
|
|
239
302
|
spinner.warn(`El archivo ${chalk2.yellow(filePath)} ya existe. Se omitir\xE1 su creaci\xF3n.`);
|
|
240
303
|
continue;
|
|
@@ -289,8 +352,8 @@ var questionsMain = [
|
|
|
289
352
|
name: "projectInstall",
|
|
290
353
|
message: " \xBFQuieres instalar dependencias?",
|
|
291
354
|
choices: [
|
|
292
|
-
{ name: "
|
|
293
|
-
{ name: "
|
|
355
|
+
{ name: "No", value: false },
|
|
356
|
+
{ name: "S\xED", value: true }
|
|
294
357
|
]
|
|
295
358
|
},
|
|
296
359
|
{
|
|
@@ -352,7 +415,7 @@ function showError(error) {
|
|
|
352
415
|
|
|
353
416
|
// src/index.ts
|
|
354
417
|
var { version } = JSON.parse(
|
|
355
|
-
|
|
418
|
+
fs3.readFileSync(new URL("../package.json", import.meta.url), "utf-8")
|
|
356
419
|
);
|
|
357
420
|
printBanner();
|
|
358
421
|
program.name("klei").version(version, "-v, --version", "Muestra la versi\xF3n actual").description("CLI con m\xFAltiples caracter\xEDsticas");
|
package/package.json
CHANGED
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "klei-cli",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "cli for creating and managing packages",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"funding": {
|
|
7
|
-
"type": "buymeacoffee",
|
|
8
|
-
"url": "https://www.buymeacoffee.com/kreisler"
|
|
9
|
-
},
|
|
10
|
-
"scripts": {
|
|
11
|
-
"start": "node ./bin/cli.js",
|
|
12
|
-
"w": "tsup --entry.cli src/index.ts --watch --onSuccess \"node bin/cli.js\"",
|
|
13
|
-
"b": "rm -rf bin/** && tsup",
|
|
14
|
-
"n:latest": "npm install -g npm@latest",
|
|
15
|
-
"p:latest": "pnpm add -g pnpm",
|
|
16
|
-
"p:update": "corepack install -g pnpm@10.4.1",
|
|
17
|
-
"pp": "npm run b && npm publish --access public",
|
|
18
|
-
"n:cache": "npm config get cache"
|
|
19
|
-
},
|
|
20
|
-
"files": [
|
|
21
|
-
"bin/**"
|
|
22
|
-
],
|
|
23
|
-
"main": "bin/cli.js",
|
|
24
|
-
"bin": {
|
|
25
|
-
"klei": "./bin/cli.js"
|
|
26
|
-
},
|
|
27
|
-
"repository": {
|
|
28
|
-
"type": "git",
|
|
29
|
-
"url": "git+https://github.com/itskreisler/klei.git"
|
|
30
|
-
},
|
|
31
|
-
"homepage": "https://github.com/itskreisler/klei#readme",
|
|
32
|
-
"bugs": {
|
|
33
|
-
"url": "https://github.com/itskreisler/klei/issues"
|
|
34
|
-
},
|
|
35
|
-
"keywords": [
|
|
36
|
-
"cli",
|
|
37
|
-
"packages"
|
|
38
|
-
],
|
|
39
|
-
"author": "kreisler <tempkreisler@outlook.com> (https://linktr.ee/itskreisler)",
|
|
40
|
-
"contributors": [
|
|
41
|
-
{
|
|
42
|
-
"name": "Kreisler Ramirez Sierra",
|
|
43
|
-
"email": "tempkreisler@outlook.com",
|
|
44
|
-
"url": "https://linktr.ee/itskreisler"
|
|
45
|
-
}
|
|
46
|
-
],
|
|
47
|
-
"license": "MIT",
|
|
48
|
-
"devDependencies": {
|
|
49
|
-
"@eslint/js": "^9.21.0",
|
|
50
|
-
"@types/assert": "^1.5.11",
|
|
51
|
-
"@types/cross-spawn": "^6.0.6",
|
|
52
|
-
"@types/figlet": "^1.7.0",
|
|
53
|
-
"@types/node": "^22.13.5",
|
|
54
|
-
"eslint": "^9.21.0",
|
|
55
|
-
"tsup": "^8.4.0",
|
|
56
|
-
"typescript": "^5.8.3",
|
|
57
|
-
"typescript-eslint": "^8.25.0"
|
|
58
|
-
},
|
|
59
|
-
"packageManager": "pnpm@10.10.0+sha512.d615db246fe70f25dcfea6d8d73dee782ce23e2245e3c4f6f888249fb568149318637dca73c2c5c8ef2a4ca0d5657fb9567188bfab47f566d1ee6ce987815c39",
|
|
60
|
-
"pnpm": {
|
|
61
|
-
"onlyBuiltDependencies": [
|
|
62
|
-
"esbuild"
|
|
63
|
-
]
|
|
64
|
-
},
|
|
65
|
-
"dependencies": {
|
|
66
|
-
"chalk": "^5.4.1",
|
|
67
|
-
"commander": "^13.1.0",
|
|
68
|
-
"cross-spawn": "^7.0.6",
|
|
69
|
-
"figlet": "^1.8.0",
|
|
70
|
-
"inquirer": "^12.4.2",
|
|
71
|
-
"ora": "^8.2.0",
|
|
72
|
-
"simple-git": "^3.27.0"
|
|
73
|
-
}
|
|
74
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "klei-cli",
|
|
3
|
+
"version": "1.0.7",
|
|
4
|
+
"description": "cli for creating and managing packages",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"funding": {
|
|
7
|
+
"type": "buymeacoffee",
|
|
8
|
+
"url": "https://www.buymeacoffee.com/kreisler"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"start": "node ./bin/cli.js",
|
|
12
|
+
"w": "tsup --entry.cli src/index.ts --watch --onSuccess \"node bin/cli.js\"",
|
|
13
|
+
"b": "rm -rf bin/** && tsup",
|
|
14
|
+
"n:latest": "npm install -g npm@latest",
|
|
15
|
+
"p:latest": "pnpm add -g pnpm",
|
|
16
|
+
"p:update": "corepack install -g pnpm@10.4.1",
|
|
17
|
+
"pp": "npm run b && npm publish --access public",
|
|
18
|
+
"n:cache": "npm config get cache"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"bin/**"
|
|
22
|
+
],
|
|
23
|
+
"main": "bin/cli.js",
|
|
24
|
+
"bin": {
|
|
25
|
+
"klei": "./bin/cli.js"
|
|
26
|
+
},
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git+https://github.com/itskreisler/klei.git"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://github.com/itskreisler/klei#readme",
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/itskreisler/klei/issues"
|
|
34
|
+
},
|
|
35
|
+
"keywords": [
|
|
36
|
+
"cli",
|
|
37
|
+
"packages"
|
|
38
|
+
],
|
|
39
|
+
"author": "kreisler <tempkreisler@outlook.com> (https://linktr.ee/itskreisler)",
|
|
40
|
+
"contributors": [
|
|
41
|
+
{
|
|
42
|
+
"name": "Kreisler Ramirez Sierra",
|
|
43
|
+
"email": "tempkreisler@outlook.com",
|
|
44
|
+
"url": "https://linktr.ee/itskreisler"
|
|
45
|
+
}
|
|
46
|
+
],
|
|
47
|
+
"license": "MIT",
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@eslint/js": "^9.21.0",
|
|
50
|
+
"@types/assert": "^1.5.11",
|
|
51
|
+
"@types/cross-spawn": "^6.0.6",
|
|
52
|
+
"@types/figlet": "^1.7.0",
|
|
53
|
+
"@types/node": "^22.13.5",
|
|
54
|
+
"eslint": "^9.21.0",
|
|
55
|
+
"tsup": "^8.4.0",
|
|
56
|
+
"typescript": "^5.8.3",
|
|
57
|
+
"typescript-eslint": "^8.25.0"
|
|
58
|
+
},
|
|
59
|
+
"packageManager": "pnpm@10.10.0+sha512.d615db246fe70f25dcfea6d8d73dee782ce23e2245e3c4f6f888249fb568149318637dca73c2c5c8ef2a4ca0d5657fb9567188bfab47f566d1ee6ce987815c39",
|
|
60
|
+
"pnpm": {
|
|
61
|
+
"onlyBuiltDependencies": [
|
|
62
|
+
"esbuild"
|
|
63
|
+
]
|
|
64
|
+
},
|
|
65
|
+
"dependencies": {
|
|
66
|
+
"chalk": "^5.4.1",
|
|
67
|
+
"commander": "^13.1.0",
|
|
68
|
+
"cross-spawn": "^7.0.6",
|
|
69
|
+
"figlet": "^1.8.0",
|
|
70
|
+
"inquirer": "^12.4.2",
|
|
71
|
+
"ora": "^8.2.0",
|
|
72
|
+
"simple-git": "^3.27.0"
|
|
73
|
+
}
|
|
74
|
+
}
|