@devrune/cli 1.0.0 → 1.0.1
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/dist/check-file-name-style-guide.js +110 -0
- package/dist/constants.js +13 -0
- package/dist/generate-feature.js +54 -0
- package/dist/index.js +20 -0
- package/package.json +4 -1
- package/scripts/index.ts +20 -0
- package/devrune-cli-1.0.0.tgz +0 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const fs_1 = __importDefault(require("fs"));
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const SRC_DIR = path_1.default.join(process.cwd(), "src");
|
|
9
|
+
const RESERVED_NEXT_FILES = new Set([
|
|
10
|
+
"page.tsx",
|
|
11
|
+
"layout.tsx",
|
|
12
|
+
"template.tsx",
|
|
13
|
+
"loading.tsx",
|
|
14
|
+
"error.tsx",
|
|
15
|
+
"global-error.tsx",
|
|
16
|
+
"not-found.tsx",
|
|
17
|
+
"default.tsx",
|
|
18
|
+
"route.ts",
|
|
19
|
+
"middleware.ts",
|
|
20
|
+
"instrumentation.ts",
|
|
21
|
+
"sitemap.ts",
|
|
22
|
+
"robots.ts",
|
|
23
|
+
"icon.tsx",
|
|
24
|
+
"apple-icon.tsx",
|
|
25
|
+
"opengraph-image.tsx",
|
|
26
|
+
"twitter-image.tsx",
|
|
27
|
+
]);
|
|
28
|
+
const IGNORED_DIRS = new Set([
|
|
29
|
+
".husky",
|
|
30
|
+
".next",
|
|
31
|
+
".vscode",
|
|
32
|
+
"node_modules",
|
|
33
|
+
"public",
|
|
34
|
+
"scripts",
|
|
35
|
+
"dist",
|
|
36
|
+
"build",
|
|
37
|
+
]);
|
|
38
|
+
let hasErrors = false;
|
|
39
|
+
const walk = (dir) => {
|
|
40
|
+
const files = fs_1.default.readdirSync(dir);
|
|
41
|
+
for (const file of files) {
|
|
42
|
+
const fullPath = path_1.default.join(dir, file);
|
|
43
|
+
const stat = fs_1.default.statSync(fullPath);
|
|
44
|
+
if (stat.isDirectory()) {
|
|
45
|
+
if (!IGNORED_DIRS.has(file)) {
|
|
46
|
+
walk(fullPath);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
checkFile(fullPath);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const reportError = (filePath, message) => {
|
|
55
|
+
hasErrors = true;
|
|
56
|
+
console.log(`❌ ${filePath}`);
|
|
57
|
+
console.log(` → ${message}\n`);
|
|
58
|
+
};
|
|
59
|
+
const checkFile = (filePath) => {
|
|
60
|
+
const fileName = path_1.default.basename(filePath);
|
|
61
|
+
//Skip non TS/TSX files, reserved Next.js files, and declaration files
|
|
62
|
+
if (!fileName.endsWith(".ts") && !fileName.endsWith(".tsx"))
|
|
63
|
+
return;
|
|
64
|
+
if (RESERVED_NEXT_FILES.has(fileName))
|
|
65
|
+
return;
|
|
66
|
+
if (fileName.endsWith(".d.ts"))
|
|
67
|
+
return;
|
|
68
|
+
// Check for uppercase letters
|
|
69
|
+
if (/[A-Z]/.test(fileName)) {
|
|
70
|
+
reportError(filePath, "File name should be lowercase");
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
// Hooks (check hooks before UI components since hooks can also be in TSX files)
|
|
74
|
+
if (fileName.startsWith("use-") && (fileName.endsWith(".hook.ts") || fileName.endsWith(".hook.tsx")))
|
|
75
|
+
return;
|
|
76
|
+
// UI components
|
|
77
|
+
if (fileName.endsWith(".ui.tsx"))
|
|
78
|
+
return;
|
|
79
|
+
// Types
|
|
80
|
+
if (fileName.endsWith(".type.ts"))
|
|
81
|
+
return;
|
|
82
|
+
// Classes
|
|
83
|
+
if (fileName.endsWith(".class.ts"))
|
|
84
|
+
return;
|
|
85
|
+
// Utils
|
|
86
|
+
if (fileName.endsWith(".util.ts"))
|
|
87
|
+
return;
|
|
88
|
+
//Constants
|
|
89
|
+
if (fileName.endsWith(".const.ts"))
|
|
90
|
+
return;
|
|
91
|
+
// API
|
|
92
|
+
if (fileName.endsWith(".api.ts"))
|
|
93
|
+
return;
|
|
94
|
+
// Modals
|
|
95
|
+
if (fileName.endsWith(".modal.tsx"))
|
|
96
|
+
return;
|
|
97
|
+
reportError(filePath, "File name does not follow naming convention.");
|
|
98
|
+
};
|
|
99
|
+
if (!fs_1.default.existsSync(SRC_DIR)) {
|
|
100
|
+
console.error("❌ src folder not found in the project root");
|
|
101
|
+
process.exit(1);
|
|
102
|
+
}
|
|
103
|
+
walk(SRC_DIR);
|
|
104
|
+
if (hasErrors) {
|
|
105
|
+
console.log("⛔ Found files that do not follow the naming convention. Please fix the above issues.");
|
|
106
|
+
process.exit(1);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
console.log("✅ All files follow the naming convention!");
|
|
110
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MODALS_DIR = exports.TYPES_DIR = exports.UTILS_DIR = exports.HOOKS_DIR = exports.UI_DIR = exports.API_DIR = exports.ROOT_DIR = exports.SHARED_DIR = exports.FEATURE_DIR = void 0;
|
|
4
|
+
exports.FEATURE_DIR = "features";
|
|
5
|
+
exports.SHARED_DIR = "shared";
|
|
6
|
+
exports.ROOT_DIR = "src";
|
|
7
|
+
exports.API_DIR = "api";
|
|
8
|
+
exports.UI_DIR = "ui";
|
|
9
|
+
exports.HOOKS_DIR = "hooks";
|
|
10
|
+
exports.UTILS_DIR = "utils";
|
|
11
|
+
exports.TYPES_DIR = "types";
|
|
12
|
+
exports.MODALS_DIR = "modals";
|
|
13
|
+
// 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,54 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const constants_1 = require("./constants");
|
|
10
|
+
const select_1 = __importDefault(require("@inquirer/select"));
|
|
11
|
+
const prompts_1 = require("@inquirer/prompts");
|
|
12
|
+
function toPascalCase(str) {
|
|
13
|
+
return str
|
|
14
|
+
.split("-")
|
|
15
|
+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
16
|
+
.join("");
|
|
17
|
+
}
|
|
18
|
+
function toCamelCase(str) {
|
|
19
|
+
const pascalCase = toPascalCase(str);
|
|
20
|
+
return pascalCase.charAt(0).toLowerCase() + pascalCase.slice(1);
|
|
21
|
+
}
|
|
22
|
+
function ensureDir(dirPath) {
|
|
23
|
+
node_fs_1.default.mkdirSync(dirPath, { recursive: true });
|
|
24
|
+
}
|
|
25
|
+
async function main() {
|
|
26
|
+
const type = await (0, select_1.default)({
|
|
27
|
+
message: 'What do you want to create?',
|
|
28
|
+
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' }],
|
|
29
|
+
});
|
|
30
|
+
const name = await (0, prompts_1.input)({
|
|
31
|
+
message: `Enter ${type} name:`,
|
|
32
|
+
validate: (input) => input ? true : 'Name cannot be empty',
|
|
33
|
+
});
|
|
34
|
+
const ROOT_DIR_PATH = type === 'feature' ? node_path_1.default.join(constants_1.ROOT_DIR, constants_1.FEATURE_DIR) : node_path_1.default.join(constants_1.ROOT_DIR, constants_1.SHARED_DIR);
|
|
35
|
+
ensureDir(node_path_1.default.join(ROOT_DIR_PATH, name));
|
|
36
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(ROOT_DIR_PATH, name, `${name}.class.ts`), `// export class ${toPascalCase(name)} = {}`);
|
|
37
|
+
ensureDir(node_path_1.default.join(ROOT_DIR_PATH, name, constants_1.API_DIR));
|
|
38
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(ROOT_DIR_PATH, name, constants_1.API_DIR, `${name}.api.ts`), `// export const ${toCamelCase(`${name}Api`)} = {}`);
|
|
39
|
+
ensureDir(node_path_1.default.join(ROOT_DIR_PATH, name, constants_1.UI_DIR));
|
|
40
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(ROOT_DIR_PATH, name, constants_1.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};`);
|
|
41
|
+
ensureDir(node_path_1.default.join(ROOT_DIR_PATH, name, constants_1.HOOKS_DIR));
|
|
42
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(ROOT_DIR_PATH, name, constants_1.HOOKS_DIR, `use-${name}.hook.ts`), `// export const ${toCamelCase(`use${toPascalCase(name)}`)} = () => {}`);
|
|
43
|
+
ensureDir(node_path_1.default.join(ROOT_DIR_PATH, name, constants_1.UTILS_DIR));
|
|
44
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(ROOT_DIR_PATH, name, constants_1.UTILS_DIR, `${name}.util.ts`), `// utils for ${name} feature`);
|
|
45
|
+
ensureDir(node_path_1.default.join(ROOT_DIR_PATH, name, constants_1.TYPES_DIR));
|
|
46
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(ROOT_DIR_PATH, name, constants_1.TYPES_DIR, `${name}.type.ts`), `// export type ${toPascalCase(name)}ModalProps = {};\nexport type ${toPascalCase(name)}Props = {};`);
|
|
47
|
+
ensureDir(node_path_1.default.join(ROOT_DIR_PATH, name, constants_1.MODALS_DIR));
|
|
48
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(ROOT_DIR_PATH, name, constants_1.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// };`);
|
|
49
|
+
}
|
|
50
|
+
main()
|
|
51
|
+
.catch((e) => {
|
|
52
|
+
console.error(e);
|
|
53
|
+
process.exit(1);
|
|
54
|
+
});
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const select_1 = __importDefault(require("@inquirer/select"));
|
|
8
|
+
console.log("Welcome to DevRune CLI! Use this tool to generate features and check file name style guide.");
|
|
9
|
+
(0, select_1.default)({
|
|
10
|
+
message: 'What do you want to create?',
|
|
11
|
+
choices: [{ name: 'Check Style Guide 🖌', value: 'check', description: 'Check project folders according style guide' },
|
|
12
|
+
{ name: 'Create new feature', value: 'feature', description: 'Create new feature' }],
|
|
13
|
+
}).then((answer) => {
|
|
14
|
+
if (answer === 'check') {
|
|
15
|
+
require('./check-file-name-style-guide');
|
|
16
|
+
}
|
|
17
|
+
if (answer === 'feature') {
|
|
18
|
+
require('./generate-feature');
|
|
19
|
+
}
|
|
20
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devrune/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"bin": {
|
|
5
|
+
"devrune": "./dist/index.js"
|
|
6
|
+
},
|
|
4
7
|
"scripts": {
|
|
5
8
|
"generate-feature": "ts-node ./scripts/generate-feature.ts",
|
|
6
9
|
"check-file-name": "ts-node ./scripts/check-file-name-style-guide.ts"
|
package/scripts/index.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import select from "@inquirer/select";
|
|
3
|
+
|
|
4
|
+
console.log("Welcome to DevRune CLI! Use this tool to generate features and check file name style guide.");
|
|
5
|
+
select(
|
|
6
|
+
{
|
|
7
|
+
message: 'What do you want to create?',
|
|
8
|
+
choices: [{name: 'Check Style Guide 🖌', value: 'check', description: 'Check project folders according style guide'},
|
|
9
|
+
{name: 'Create new feature', value: 'feature', description: 'Create new feature'}],
|
|
10
|
+
},
|
|
11
|
+
).then((answer) => {
|
|
12
|
+
if (answer === 'check') {
|
|
13
|
+
require('./check-file-name-style-guide');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (answer === 'feature') {
|
|
17
|
+
require('./generate-feature');
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
|
package/devrune-cli-1.0.0.tgz
DELETED
|
Binary file
|