@devrune/cli 1.0.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/LICENSE +23 -0
- package/README.md +20 -0
- package/devrune-cli-1.0.0.tgz +0 -0
- package/package.json +25 -0
- package/scripts/check-file-name-style-guide.ts +115 -0
- package/scripts/constants.ts +10 -0
- package/scripts/generate-feature.ts +65 -0
- package/tsconfig.json +10 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO```
|
|
17
|
+
MIT License
|
|
18
|
+
|
|
19
|
+
Copyright (c) 2026
|
|
20
|
+
|
|
21
|
+
You are allowed to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of this software and its documentation, free of charge, provided that the copyright notice and this permission notice are included in all copies or significant portions of the software.
|
|
22
|
+
|
|
23
|
+
This software is provided "as is", without any warranty of any kind, either express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages, or other liability, whether in an action of contract, tort, or otherwise, arising from, out of, or in connection with the software or the use or other dealings in the software.
|
package/README.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Introduction
|
|
2
|
+
TODO: Give a short introduction of your project. Let this section explain the objectives or the motivation behind this project.
|
|
3
|
+
|
|
4
|
+
# Getting Started
|
|
5
|
+
TODO: Guide users through getting your code up and running on their own system. In this section you can talk about:
|
|
6
|
+
1. Installation process
|
|
7
|
+
2. Software dependencies
|
|
8
|
+
3. Latest releases
|
|
9
|
+
4. API references
|
|
10
|
+
|
|
11
|
+
# Build and Test
|
|
12
|
+
TODO: Describe and show how to build your code and run the tests.
|
|
13
|
+
|
|
14
|
+
# Contribute
|
|
15
|
+
TODO: Explain how other users and developers can contribute to make your code better.
|
|
16
|
+
|
|
17
|
+
If you want to learn more about creating good readme files then refer the following [guidelines](https://docs.microsoft.com/en-us/azure/devops/repos/git/create-a-readme?view=azure-devops). You can also seek inspiration from the below readme files:
|
|
18
|
+
- [ASP.NET Core](https://github.com/aspnet/Home)
|
|
19
|
+
- [Visual Studio Code](https://github.com/Microsoft/vscode)
|
|
20
|
+
- [Chakra Core](https://github.com/Microsoft/ChakraCore)
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@devrune/cli",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"scripts": {
|
|
5
|
+
"generate-feature": "ts-node ./scripts/generate-feature.ts",
|
|
6
|
+
"check-file-name": "ts-node ./scripts/check-file-name-style-guide.ts"
|
|
7
|
+
},
|
|
8
|
+
"devDependencies": {
|
|
9
|
+
"@types/node": "^25.3.0",
|
|
10
|
+
"ts-node": "^10.9.2",
|
|
11
|
+
"typescript": "^5.9.3"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@inquirer/prompts": "^8.3.0",
|
|
15
|
+
"@inquirer/select": "^5.1.0"
|
|
16
|
+
},
|
|
17
|
+
"description": "CLI tool for DevRune project. Provides commands to generate features and check file name style guide.",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://devrune@dev.azure.com/devrune/DevRune/_git/devrune-cli"
|
|
21
|
+
},
|
|
22
|
+
"author": "DevRune Team",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"main": "index.js"
|
|
25
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
|
|
4
|
+
const SRC_DIR = path.join(process.cwd(), "src");
|
|
5
|
+
|
|
6
|
+
const RESERVED_NEXT_FILES = new Set([
|
|
7
|
+
"page.tsx",
|
|
8
|
+
"layout.tsx",
|
|
9
|
+
"template.tsx",
|
|
10
|
+
"loading.tsx",
|
|
11
|
+
"error.tsx",
|
|
12
|
+
"global-error.tsx",
|
|
13
|
+
"not-found.tsx",
|
|
14
|
+
"default.tsx",
|
|
15
|
+
"route.ts",
|
|
16
|
+
"middleware.ts",
|
|
17
|
+
"instrumentation.ts",
|
|
18
|
+
"sitemap.ts",
|
|
19
|
+
"robots.ts",
|
|
20
|
+
"icon.tsx",
|
|
21
|
+
"apple-icon.tsx",
|
|
22
|
+
"opengraph-image.tsx",
|
|
23
|
+
"twitter-image.tsx",
|
|
24
|
+
]);
|
|
25
|
+
|
|
26
|
+
const IGNORED_DIRS = new Set([
|
|
27
|
+
".husky",
|
|
28
|
+
".next",
|
|
29
|
+
".vscode",
|
|
30
|
+
"node_modules",
|
|
31
|
+
"public",
|
|
32
|
+
"scripts",
|
|
33
|
+
"dist",
|
|
34
|
+
"build",
|
|
35
|
+
]);
|
|
36
|
+
|
|
37
|
+
let hasErrors = false;
|
|
38
|
+
|
|
39
|
+
const walk = (dir:string) => {
|
|
40
|
+
const files = fs.readdirSync(dir);
|
|
41
|
+
|
|
42
|
+
for (const file of files) {
|
|
43
|
+
const fullPath = path.join(dir, file);
|
|
44
|
+
const stat = fs.statSync(fullPath);
|
|
45
|
+
|
|
46
|
+
if (stat.isDirectory()) {
|
|
47
|
+
if (!IGNORED_DIRS.has(file)) {
|
|
48
|
+
walk(fullPath);
|
|
49
|
+
}
|
|
50
|
+
} else {
|
|
51
|
+
checkFile(fullPath);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const reportError = (filePath: string, message: string) => {
|
|
57
|
+
hasErrors = true;
|
|
58
|
+
console.log(`❌ ${filePath}`);
|
|
59
|
+
console.log(` → ${message}\n`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const checkFile = (filePath: string) => {
|
|
63
|
+
const fileName = path.basename(filePath);
|
|
64
|
+
|
|
65
|
+
//Skip non TS/TSX files, reserved Next.js files, and declaration files
|
|
66
|
+
if (!fileName.endsWith(".ts") && !fileName.endsWith(".tsx")) return;
|
|
67
|
+
if (RESERVED_NEXT_FILES.has(fileName)) return;
|
|
68
|
+
if (fileName.endsWith(".d.ts")) return;
|
|
69
|
+
|
|
70
|
+
// Check for uppercase letters
|
|
71
|
+
if (/[A-Z]/.test(fileName)) {
|
|
72
|
+
reportError(filePath, "File name should be lowercase");
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Hooks (check hooks before UI components since hooks can also be in TSX files)
|
|
77
|
+
if (fileName.startsWith("use-") && (fileName.endsWith(".hook.ts") || fileName.endsWith(".hook.tsx"))) return;
|
|
78
|
+
|
|
79
|
+
// UI components
|
|
80
|
+
if (fileName.endsWith(".ui.tsx")) return;
|
|
81
|
+
|
|
82
|
+
// Types
|
|
83
|
+
if (fileName.endsWith(".type.ts")) return;
|
|
84
|
+
|
|
85
|
+
// Classes
|
|
86
|
+
if (fileName.endsWith(".class.ts")) return;
|
|
87
|
+
|
|
88
|
+
// Utils
|
|
89
|
+
if (fileName.endsWith(".util.ts")) return;
|
|
90
|
+
|
|
91
|
+
//Constants
|
|
92
|
+
if (fileName.endsWith(".const.ts")) return;
|
|
93
|
+
|
|
94
|
+
// API
|
|
95
|
+
if (fileName.endsWith(".api.ts")) return;
|
|
96
|
+
|
|
97
|
+
// Modals
|
|
98
|
+
if (fileName.endsWith(".modal.tsx")) return;
|
|
99
|
+
|
|
100
|
+
reportError(filePath, "File name does not follow naming convention.");
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (!fs.existsSync(SRC_DIR)) {
|
|
104
|
+
console.error("❌ src folder not found in the project root");
|
|
105
|
+
process.exit(1);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
walk(SRC_DIR);
|
|
109
|
+
|
|
110
|
+
if (hasErrors) {
|
|
111
|
+
console.log("⛔ Found files that do not follow the naming convention. Please fix the above issues.");
|
|
112
|
+
process.exit(1);
|
|
113
|
+
} else {
|
|
114
|
+
console.log("✅ All files follow the naming convention!");
|
|
115
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const FEATURE_DIR = "features";
|
|
2
|
+
export const SHARED_DIR = "shared";
|
|
3
|
+
export const ROOT_DIR = "src";
|
|
4
|
+
export const API_DIR = "api";
|
|
5
|
+
export const UI_DIR = "ui";
|
|
6
|
+
export const HOOKS_DIR = "hooks";
|
|
7
|
+
export const UTILS_DIR = "utils";
|
|
8
|
+
export const TYPES_DIR = "types";
|
|
9
|
+
export const MODALS_DIR = "modals";
|
|
10
|
+
// CLI api - name.api.ts, ui - name.ui.ts, hooks - name.hook.ts, utils - name.util.ts, types name.type.ts, classes - name.class.ts
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { API_DIR, HOOKS_DIR, MODALS_DIR, FEATURE_DIR, ROOT_DIR, SHARED_DIR, TYPES_DIR, UI_DIR, UTILS_DIR } from "./constants";
|
|
5
|
+
import select from "@inquirer/select";
|
|
6
|
+
import {input} from '@inquirer/prompts';
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
function toPascalCase(str: string) {
|
|
10
|
+
return str
|
|
11
|
+
.split("-")
|
|
12
|
+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
13
|
+
.join("");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function toCamelCase(str: string) {
|
|
17
|
+
const pascalCase = toPascalCase(str);
|
|
18
|
+
return pascalCase.charAt(0).toLowerCase() + pascalCase.slice(1);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
function ensureDir(dirPath: string) {
|
|
23
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
async function main() {
|
|
28
|
+
const type = await select(
|
|
29
|
+
{
|
|
30
|
+
message: 'What do you want to create?',
|
|
31
|
+
choices: [{name: 'Feature', value: 'feature', description: 'Create feature if it should be private and nothing should be imported outside'}, {name: 'Shared', value: 'shared', description: 'Create shared feature that can be imported anywhere'}],
|
|
32
|
+
},
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const name = await input(
|
|
36
|
+
{
|
|
37
|
+
message: `Enter ${type} name:`,
|
|
38
|
+
validate: (input: string) =>
|
|
39
|
+
input ? true : 'Name cannot be empty',
|
|
40
|
+
},
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
const ROOT_DIR_PATH = type === 'feature' ? path.join(ROOT_DIR, FEATURE_DIR) : path.join(ROOT_DIR, SHARED_DIR);
|
|
44
|
+
ensureDir(path.join(ROOT_DIR_PATH, name));
|
|
45
|
+
fs.writeFileSync(path.join(ROOT_DIR_PATH, name, `${name}.class.ts`), `// export class ${toPascalCase(name)} = {}`);
|
|
46
|
+
ensureDir(path.join(ROOT_DIR_PATH, name, API_DIR));
|
|
47
|
+
fs.writeFileSync(path.join(ROOT_DIR_PATH, name, API_DIR, `${name}.api.ts`), `// export const ${toCamelCase(`${name}Api`)} = {}`);
|
|
48
|
+
ensureDir(path.join(ROOT_DIR_PATH, name, UI_DIR));
|
|
49
|
+
fs.writeFileSync(path.join(ROOT_DIR_PATH, name, UI_DIR, `${name}.ui.ts`), `import { ${toPascalCase(name)}Props } from '../types/${name}.type';\n\nexport const ${toPascalCase(name)} = ({}: ${toPascalCase(name)}Props) => { \n return null;\n};`);
|
|
50
|
+
ensureDir(path.join(ROOT_DIR_PATH, name, HOOKS_DIR));
|
|
51
|
+
fs.writeFileSync(path.join(ROOT_DIR_PATH, name, HOOKS_DIR, `use-${name}.hook.ts`), `// export const ${toCamelCase(`use${toPascalCase(name)}`)} = () => {}`);
|
|
52
|
+
ensureDir(path.join(ROOT_DIR_PATH, name, UTILS_DIR));
|
|
53
|
+
fs.writeFileSync(path.join(ROOT_DIR_PATH, name, UTILS_DIR, `${name}.util.ts`), `// utils for ${name} feature`);
|
|
54
|
+
ensureDir(path.join(ROOT_DIR_PATH, name, TYPES_DIR));
|
|
55
|
+
fs.writeFileSync(path.join(ROOT_DIR_PATH, name, TYPES_DIR, `${name}.type.ts`), `// export type ${toPascalCase(name)}ModalProps = {};\nexport type ${toPascalCase(name)}Props = {};`);
|
|
56
|
+
ensureDir(path.join(ROOT_DIR_PATH, name, MODALS_DIR));
|
|
57
|
+
fs.writeFileSync(path.join(ROOT_DIR_PATH, name, MODALS_DIR, `${name}.modal.ts`), `// import { ${toPascalCase(name)}ModalProps } from '../types/${name}.type';\n\n// export const ${toPascalCase(name)}Modal = ({}: ${toPascalCase(name)}ModalProps) => {\n// return null;\n// };`);
|
|
58
|
+
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
main()
|
|
62
|
+
.catch((e) => {
|
|
63
|
+
console.error(e);
|
|
64
|
+
process.exit(1);
|
|
65
|
+
});
|