create-ej-app 2.3.0 → 2.4.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/README.md +1 -1
- package/cli.js +70 -83
- package/cli.ts +81 -0
- package/package.json +6 -1
- package/tsconfig.json +14 -0
package/README.md
CHANGED
package/cli.js
CHANGED
|
@@ -1,89 +1,76 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
type: 'select',
|
|
25
|
-
name: 'template',
|
|
26
|
-
message: 'Select a template:',
|
|
27
|
-
choices: [
|
|
2
|
+
"use strict";
|
|
3
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
const commander_1 = require("commander");
|
|
17
|
+
const enquirer_1 = require("enquirer");
|
|
18
|
+
const fs_1 = __importDefault(require("fs"));
|
|
19
|
+
const path_1 = __importDefault(require("path"));
|
|
20
|
+
//@ts-ignore
|
|
21
|
+
const copy_dir_1 = __importDefault(require("copy-dir"));
|
|
22
|
+
commander_1.program.action(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
+
const response = yield (0, enquirer_1.prompt)([
|
|
28
24
|
{
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
type: 'input',
|
|
26
|
+
name: 'projectName',
|
|
27
|
+
message: 'Enter the project name:',
|
|
28
|
+
initial: 'my-app'
|
|
31
29
|
},
|
|
32
30
|
{
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
'
|
|
31
|
+
type: 'input',
|
|
32
|
+
name: 'description',
|
|
33
|
+
message: 'Enter a description for the project:',
|
|
34
|
+
initial: 'A Legendary App'
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
type: 'select',
|
|
38
|
+
name: 'template',
|
|
39
|
+
message: 'Select a template:',
|
|
40
|
+
choices: [
|
|
41
|
+
{
|
|
42
|
+
name: 'base',
|
|
43
|
+
message: 'Base setup with ts, shadcn, prisma, auth, editor.js'
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: 'advanced',
|
|
47
|
+
message: 'Advanced setup with User Types and ACLs (roles & permissions)'
|
|
48
|
+
}
|
|
49
|
+
]
|
|
36
50
|
}
|
|
37
|
-
|
|
51
|
+
]);
|
|
52
|
+
const { projectName, description, template } = response;
|
|
53
|
+
const projectDir = path_1.default.join(process.cwd(), projectName);
|
|
54
|
+
if (fs_1.default.existsSync(projectDir)) {
|
|
55
|
+
console.error(`Error: Directory '${projectName}' already exists.`);
|
|
56
|
+
process.exit(1);
|
|
38
57
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const packageJsonFile = path.join(projectDir, 'package.json')
|
|
59
|
-
const packageJson = JSON.parse(fs.readFileSync(packageJsonFile, 'utf-8'))
|
|
60
|
-
packageJson.name = projectName
|
|
61
|
-
packageJson.description = description
|
|
62
|
-
fs.writeFileSync(packageJsonFile, JSON.stringify(packageJson, null, 2))
|
|
63
|
-
|
|
64
|
-
// Modify src/lib/siteConfig.ts in the new project directory to set the project name and description
|
|
65
|
-
const siteConfigFile = path.join(projectDir, 'src', 'lib', 'siteConfig.ts')
|
|
66
|
-
let siteConfig = fs.readFileSync(siteConfigFile, 'utf-8')
|
|
67
|
-
siteConfig = siteConfig.replace('Project Name', projectName)
|
|
68
|
-
siteConfig = siteConfig.replace('Project Description', description)
|
|
69
|
-
fs.writeFileSync(siteConfigFile, siteConfig)
|
|
70
|
-
|
|
71
|
-
// Copy .env.example to .env
|
|
72
|
-
const envExampleFile = path.join(projectDir, '.env.example')
|
|
73
|
-
const envExample = fs.readFileSync(envExampleFile, 'utf-8')
|
|
74
|
-
fs.writeFileSync(path.join(projectDir, '.env'), envExample)
|
|
75
|
-
|
|
76
|
-
console.log(`Created a new app called '${projectName}' 🎉
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
To get started, run the following commands:
|
|
80
|
-
|
|
81
|
-
cd ${projectName}
|
|
82
|
-
|
|
83
|
-
npm install
|
|
84
|
-
|
|
85
|
-
npm run dev
|
|
86
|
-
`)
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
program.parse(process.argv)
|
|
58
|
+
fs_1.default.mkdirSync(projectDir);
|
|
59
|
+
const templateDir = path_1.default.join(__dirname, 'template', template);
|
|
60
|
+
copy_dir_1.default.sync(templateDir, projectDir);
|
|
61
|
+
const packageJsonFile = path_1.default.join(projectDir, 'package.json');
|
|
62
|
+
const packageJson = JSON.parse(fs_1.default.readFileSync(packageJsonFile, 'utf-8'));
|
|
63
|
+
packageJson.name = projectName;
|
|
64
|
+
packageJson.description = description;
|
|
65
|
+
fs_1.default.writeFileSync(packageJsonFile, JSON.stringify(packageJson, null, 2));
|
|
66
|
+
const siteConfigFile = path_1.default.join(projectDir, 'src', 'lib', 'siteConfig.ts');
|
|
67
|
+
let siteConfig = fs_1.default.readFileSync(siteConfigFile, 'utf-8');
|
|
68
|
+
siteConfig = siteConfig.replace('Project Name', projectName);
|
|
69
|
+
siteConfig = siteConfig.replace('Project Description', description);
|
|
70
|
+
fs_1.default.writeFileSync(siteConfigFile, siteConfig);
|
|
71
|
+
const envExampleFile = path_1.default.join(projectDir, '.env.example');
|
|
72
|
+
const envExample = fs_1.default.readFileSync(envExampleFile, 'utf-8');
|
|
73
|
+
fs_1.default.writeFileSync(path_1.default.join(projectDir, '.env'), envExample);
|
|
74
|
+
console.log(`Created a new app called '${projectName}' 🎉\n\nTo get started, run the following commands:\n\ncd ${projectName}\nnpm install\nnpm run dev\n`);
|
|
75
|
+
}));
|
|
76
|
+
commander_1.program.parse(process.argv);
|
package/cli.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { program } from 'commander';
|
|
4
|
+
import { prompt } from 'enquirer';
|
|
5
|
+
import fs from 'fs';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
//@ts-ignore
|
|
8
|
+
import copydir from 'copy-dir';
|
|
9
|
+
|
|
10
|
+
interface Response {
|
|
11
|
+
projectName: string;
|
|
12
|
+
description: string;
|
|
13
|
+
template: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
program.action(async () => {
|
|
17
|
+
const response: Response = await prompt([
|
|
18
|
+
{
|
|
19
|
+
type: 'input',
|
|
20
|
+
name: 'projectName',
|
|
21
|
+
message: 'Enter the project name:',
|
|
22
|
+
initial: 'my-app'
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
type: 'input',
|
|
26
|
+
name: 'description',
|
|
27
|
+
message: 'Enter a description for the project:',
|
|
28
|
+
initial: 'A Legendary App'
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
type: 'select',
|
|
32
|
+
name: 'template',
|
|
33
|
+
message: 'Select a template:',
|
|
34
|
+
choices: [
|
|
35
|
+
{
|
|
36
|
+
name: 'base',
|
|
37
|
+
message: 'Base setup with ts, shadcn, prisma, auth, editor.js'
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: 'advanced',
|
|
41
|
+
message:
|
|
42
|
+
'Advanced setup with User Types and ACLs (roles & permissions)'
|
|
43
|
+
}
|
|
44
|
+
]
|
|
45
|
+
}
|
|
46
|
+
]);
|
|
47
|
+
|
|
48
|
+
const { projectName, description, template } = response;
|
|
49
|
+
|
|
50
|
+
const projectDir = path.join(process.cwd(), projectName);
|
|
51
|
+
|
|
52
|
+
if (fs.existsSync(projectDir)) {
|
|
53
|
+
console.error(`Error: Directory '${projectName}' already exists.`);
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
fs.mkdirSync(projectDir);
|
|
58
|
+
|
|
59
|
+
const templateDir = path.join(__dirname, 'template', template);
|
|
60
|
+
copydir.sync(templateDir, projectDir);
|
|
61
|
+
|
|
62
|
+
const packageJsonFile = path.join(projectDir, 'package.json');
|
|
63
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonFile, 'utf-8'));
|
|
64
|
+
packageJson.name = projectName;
|
|
65
|
+
packageJson.description = description;
|
|
66
|
+
fs.writeFileSync(packageJsonFile, JSON.stringify(packageJson, null, 2));
|
|
67
|
+
|
|
68
|
+
const siteConfigFile = path.join(projectDir, 'src', 'lib', 'siteConfig.ts');
|
|
69
|
+
let siteConfig = fs.readFileSync(siteConfigFile, 'utf-8');
|
|
70
|
+
siteConfig = siteConfig.replace('Project Name', projectName);
|
|
71
|
+
siteConfig = siteConfig.replace('Project Description', description);
|
|
72
|
+
fs.writeFileSync(siteConfigFile, siteConfig);
|
|
73
|
+
|
|
74
|
+
const envExampleFile = path.join(projectDir, '.env.example');
|
|
75
|
+
const envExample = fs.readFileSync(envExampleFile, 'utf-8');
|
|
76
|
+
fs.writeFileSync(path.join(projectDir, '.env'), envExample);
|
|
77
|
+
|
|
78
|
+
console.log(`Created a new app called '${projectName}' 🎉\n\nTo get started, run the following commands:\n\ncd ${projectName}\nnpm install\nnpm run dev\n`);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
program.parse(process.argv);
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-ej-app",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "Bootstrap a next.js app with my preferred setup",
|
|
5
5
|
"main": "cli.js",
|
|
6
6
|
"scripts": {
|
|
7
|
+
"build": "tsc",
|
|
7
8
|
"start": "node ."
|
|
8
9
|
},
|
|
9
10
|
"bin": {
|
|
@@ -32,5 +33,9 @@
|
|
|
32
33
|
"commander": "^11.0.0",
|
|
33
34
|
"copy-dir": "^1.3.0",
|
|
34
35
|
"enquirer": "^2.4.1"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/node": "^20.8.0",
|
|
39
|
+
"typescript": "^5.2.2"
|
|
35
40
|
}
|
|
36
41
|
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"outDir": "./",
|
|
4
|
+
"lib": ["ESNext", "DOM"],
|
|
5
|
+
"target": "es2016",
|
|
6
|
+
"module": "commonjs",
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"forceConsistentCasingInFileNames": true,
|
|
9
|
+
"strict": true,
|
|
10
|
+
"skipLibCheck": true
|
|
11
|
+
},
|
|
12
|
+
"include": ["**/*.ts"],
|
|
13
|
+
"exclude": ["node_modules", "template"]
|
|
14
|
+
}
|