tss-stack 1.2.3 → 1.3.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/bin/cli.js +518 -510
- package/package.json +1 -1
- package/src/generators/backend.js +404 -358
- package/src/generators/database.js +52 -55
- package/src/generators/frontend.js +794 -542
- package/src/generators/utils.js +113 -60
|
@@ -1,55 +1,52 @@
|
|
|
1
|
-
const fs = require("fs-extra");
|
|
2
|
-
const path = require("path");
|
|
3
|
-
|
|
4
|
-
const { toPascal, escapeSqlIdentifier, inferSqlType } = require("./utils");
|
|
5
|
-
|
|
6
|
-
async function generateDatabase(config) {
|
|
7
|
-
const { dbName, tables, needsAuth, targetDir } = config;
|
|
8
|
-
|
|
9
|
-
let sql = `-- ======================================================
|
|
10
|
-
-- Database: ${dbName}
|
|
11
|
-
-- Generated automatically
|
|
12
|
-
-- ======================================================
|
|
13
|
-
|
|
14
|
-
CREATE DATABASE IF NOT EXISTS ${escapeSqlIdentifier(dbName)};
|
|
15
|
-
USE ${escapeSqlIdentifier(dbName)};
|
|
16
|
-
|
|
17
|
-
`;
|
|
18
|
-
|
|
19
|
-
if (needsAuth) {
|
|
20
|
-
sql += `CREATE TABLE IF NOT EXISTS users (
|
|
21
|
-
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
22
|
-
username VARCHAR(100) NOT NULL UNIQUE,
|
|
23
|
-
password VARCHAR(255) NOT NULL,
|
|
24
|
-
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
`;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
for (const table of tables) {
|
|
31
|
-
sql += `-- ${toPascal(table.name)} table
|
|
32
|
-
CREATE TABLE IF NOT EXISTS ${escapeSqlIdentifier(table.name)} (
|
|
33
|
-
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
34
|
-
`;
|
|
35
|
-
|
|
36
|
-
for (const field of table.fields) {
|
|
37
|
-
sql += ` ${escapeSqlIdentifier(field)} ${inferSqlType(field)} NOT NULL
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
module.exports = {
|
|
54
|
-
generateDatabase,
|
|
55
|
-
};
|
|
1
|
+
const fs = require("fs-extra");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
|
|
4
|
+
const { toPascal, escapeSqlIdentifier, inferSqlType } = require("./utils");
|
|
5
|
+
|
|
6
|
+
async function generateDatabase(config) {
|
|
7
|
+
const { dbName, tables, needsAuth, targetDir } = config;
|
|
8
|
+
|
|
9
|
+
let sql = `-- ======================================================
|
|
10
|
+
-- Database: ${dbName}
|
|
11
|
+
-- Generated automatically
|
|
12
|
+
-- ======================================================
|
|
13
|
+
|
|
14
|
+
CREATE DATABASE IF NOT EXISTS ${escapeSqlIdentifier(dbName)};
|
|
15
|
+
USE ${escapeSqlIdentifier(dbName)};
|
|
16
|
+
|
|
17
|
+
`;
|
|
18
|
+
|
|
19
|
+
if (needsAuth) {
|
|
20
|
+
sql += `CREATE TABLE IF NOT EXISTS users (
|
|
21
|
+
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
22
|
+
username VARCHAR(100) NOT NULL UNIQUE,
|
|
23
|
+
password VARCHAR(255) NOT NULL,
|
|
24
|
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
for (const table of tables) {
|
|
31
|
+
sql += `-- ${toPascal(table.name)} table
|
|
32
|
+
CREATE TABLE IF NOT EXISTS ${escapeSqlIdentifier(table.name)} (
|
|
33
|
+
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
34
|
+
`;
|
|
35
|
+
|
|
36
|
+
for (const field of table.fields) {
|
|
37
|
+
sql += ` ${escapeSqlIdentifier(field)} ${inferSqlType(field)} NOT NULL,\n`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
sql += ` created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
41
|
+
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const outputPath = path.join(targetDir, "backend-project", "config", "database.sql");
|
|
48
|
+
await fs.outputFile(outputPath, sql);
|
|
49
|
+
console.log(" [✓] database.sql");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
module.exports = { generateDatabase };
|