django-hero-gen 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/index.js +48 -0
- package/package.json +16 -0
package/index.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
|
|
6
|
+
// Берем аргументы: 1-я команда, 2-е имя файла
|
|
7
|
+
const [, , command, name] = process.argv;
|
|
8
|
+
|
|
9
|
+
// Шаблоны
|
|
10
|
+
const templates = {
|
|
11
|
+
base: `<!DOCTYPE html>
|
|
12
|
+
<html>
|
|
13
|
+
<head>
|
|
14
|
+
<title>{% block title %}Django App{% endblock %}</title>
|
|
15
|
+
</head>
|
|
16
|
+
<body>
|
|
17
|
+
{% block content %}{% endblock %}
|
|
18
|
+
</body>
|
|
19
|
+
</html>`,
|
|
20
|
+
view: `from django.views.generic import TemplateView
|
|
21
|
+
|
|
22
|
+
class ${name}View(TemplateView):
|
|
23
|
+
template_name = "${name.toLowerCase()}.html"`,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
if (command === "page") {
|
|
27
|
+
const fileName = `${name}.html`;
|
|
28
|
+
const filePath = path.join(process.cwd(), fileName);
|
|
29
|
+
|
|
30
|
+
if (fs.existsSync(filePath)) {
|
|
31
|
+
console.log(`❌ Ошибка: Файл ${fileName} уже существует!`);
|
|
32
|
+
} else {
|
|
33
|
+
fs.writeFileSync(filePath, templates.base);
|
|
34
|
+
console.log(`✅ Создан HTML шаблон: ${fileName}`);
|
|
35
|
+
}
|
|
36
|
+
} else if (command === "view") {
|
|
37
|
+
const fileName = `${name.toLowerCase()}_view.py`;
|
|
38
|
+
const filePath = path.join(process.cwd(), fileName);
|
|
39
|
+
|
|
40
|
+
fs.writeFileSync(filePath, templates.view);
|
|
41
|
+
console.log(`✅ Создана View: ${fileName}`);
|
|
42
|
+
} else {
|
|
43
|
+
console.log(`
|
|
44
|
+
Использование:
|
|
45
|
+
dj-gen page <name> - Создать HTML шаблон
|
|
46
|
+
dj-gen view <name> - Создать Django View
|
|
47
|
+
`);
|
|
48
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "django-hero-gen",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Генератор шаблонов для Django",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"dj-gen": "./index.js"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"django",
|
|
11
|
+
"template",
|
|
12
|
+
"generate"
|
|
13
|
+
],
|
|
14
|
+
"author": "asappaholik",
|
|
15
|
+
"license": "MIT"
|
|
16
|
+
}
|