@stravigor/create 0.1.0 → 0.1.2
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/CHANGELOG.md +7 -0
- package/package.json +2 -2
- package/src/index.ts +7 -5
- package/src/prompts.ts +2 -2
- package/src/templates/api.ts +23 -29
- package/src/templates/shared.ts +53 -41
- package/src/templates/web.ts +26 -34
package/CHANGELOG.md
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stravigor/create",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Scaffold a new Strav application",
|
|
6
6
|
"license": "MIT",
|
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
"bin": {
|
|
9
9
|
"@stravigor/create": "./src/index.ts"
|
|
10
10
|
},
|
|
11
|
-
"files": ["src/", "package.json", "README.md"]
|
|
11
|
+
"files": ["src/", "package.json", "README.md", "CHANGELOG.md"]
|
|
12
12
|
}
|
package/src/index.ts
CHANGED
|
@@ -99,22 +99,24 @@ async function main(): Promise<void> {
|
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
if (!/^[a-zA-Z0-9_-]+$/.test(projectName)) {
|
|
102
|
-
console.error(
|
|
102
|
+
console.error(
|
|
103
|
+
red(` Invalid project name. Use only letters, numbers, hyphens, and underscores.`)
|
|
104
|
+
)
|
|
103
105
|
process.exit(1)
|
|
104
106
|
}
|
|
105
107
|
|
|
106
108
|
// Template
|
|
107
109
|
let template = args.template
|
|
108
110
|
if (!template) {
|
|
109
|
-
template = await select('Which template?', [
|
|
111
|
+
template = (await select('Which template?', [
|
|
110
112
|
{ label: 'api', value: 'api', description: 'Headless REST API' },
|
|
111
113
|
{ label: 'web', value: 'web', description: 'Full-stack with views and static files' },
|
|
112
|
-
]) as 'api' | 'web'
|
|
114
|
+
])) as 'api' | 'web'
|
|
113
115
|
}
|
|
114
116
|
|
|
115
117
|
// Database name
|
|
116
118
|
const defaultDb = toSnakeCase(projectName)
|
|
117
|
-
const dbName = args.db ?? await input('Database name:', defaultDb)
|
|
119
|
+
const dbName = args.db ?? (await input('Database name:', defaultDb))
|
|
118
120
|
|
|
119
121
|
console.log()
|
|
120
122
|
|
|
@@ -150,7 +152,7 @@ async function main(): Promise<void> {
|
|
|
150
152
|
console.log()
|
|
151
153
|
}
|
|
152
154
|
|
|
153
|
-
main().catch(
|
|
155
|
+
main().catch(err => {
|
|
154
156
|
console.error(red(` Error: ${err instanceof Error ? err.message : err}`))
|
|
155
157
|
process.exit(1)
|
|
156
158
|
})
|
package/src/prompts.ts
CHANGED
|
@@ -30,7 +30,7 @@ export async function select(message: string, choices: Choice[]): Promise<string
|
|
|
30
30
|
}
|
|
31
31
|
render()
|
|
32
32
|
|
|
33
|
-
return new Promise(
|
|
33
|
+
return new Promise(resolve => {
|
|
34
34
|
const stdin = process.stdin
|
|
35
35
|
stdin.setRawMode(true)
|
|
36
36
|
stdin.resume()
|
|
@@ -84,7 +84,7 @@ export async function select(message: string, choices: Choice[]): Promise<string
|
|
|
84
84
|
export async function input(message: string, defaultValue: string): Promise<string> {
|
|
85
85
|
process.stdout.write(` \x1b[1m${message}\x1b[0m \x1b[2m(${defaultValue})\x1b[0m `)
|
|
86
86
|
|
|
87
|
-
return new Promise(
|
|
87
|
+
return new Promise(resolve => {
|
|
88
88
|
const stdin = process.stdin
|
|
89
89
|
stdin.setRawMode(true)
|
|
90
90
|
stdin.resume()
|
package/src/templates/api.ts
CHANGED
|
@@ -11,44 +11,38 @@ export function getApiFiles(opts: ScaffoldOptions): TemplateFile[] {
|
|
|
11
11
|
function indexTs(opts: ScaffoldOptions): string {
|
|
12
12
|
return `import 'reflect-metadata'
|
|
13
13
|
import { app } from '@stravigor/core/core'
|
|
14
|
-
import
|
|
15
|
-
import
|
|
14
|
+
import { router } from '@stravigor/core/http'
|
|
15
|
+
import {
|
|
16
|
+
ConfigProvider, DatabaseProvider, EncryptionProvider,
|
|
17
|
+
} from '@stravigor/core/providers'
|
|
16
18
|
import BaseModel from '@stravigor/core/orm/base_model'
|
|
17
|
-
import
|
|
19
|
+
import Database from '@stravigor/core/database/database'
|
|
18
20
|
import Server from '@stravigor/core/http/server'
|
|
19
21
|
import { ExceptionHandler } from '@stravigor/core/exceptions'
|
|
20
|
-
import EncryptionManager from '@stravigor/core/encryption/encryption_manager'
|
|
21
|
-
|
|
22
|
-
async function boot() {
|
|
23
|
-
const config = new Configuration('./config')
|
|
24
|
-
await config.load()
|
|
25
|
-
app.singleton(Configuration, () => config)
|
|
26
22
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
new
|
|
23
|
+
// Register service providers
|
|
24
|
+
app
|
|
25
|
+
.use(new ConfigProvider())
|
|
26
|
+
.use(new DatabaseProvider())
|
|
27
|
+
.use(new EncryptionProvider())
|
|
30
28
|
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
// Boot services (loads config, connects database, derives encryption keys)
|
|
30
|
+
await app.start()
|
|
33
31
|
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
// Initialize ORM
|
|
33
|
+
new BaseModel(app.resolve(Database))
|
|
36
34
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
// Configure router
|
|
36
|
+
router.useExceptionHandler(new ExceptionHandler(true))
|
|
37
|
+
router.cors()
|
|
40
38
|
|
|
41
|
-
|
|
39
|
+
// Load routes
|
|
40
|
+
await import('./start/routes')
|
|
42
41
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
boot().catch((err) => {
|
|
49
|
-
console.error('Failed to boot:', err)
|
|
50
|
-
process.exit(1)
|
|
51
|
-
})
|
|
42
|
+
// Start HTTP server
|
|
43
|
+
app.singleton(Server)
|
|
44
|
+
const server = app.resolve(Server)
|
|
45
|
+
server.start(router)
|
|
52
46
|
`
|
|
53
47
|
}
|
|
54
48
|
|
package/src/templates/shared.ts
CHANGED
|
@@ -27,50 +27,62 @@ export function getSharedFiles(opts: ScaffoldOptions): TemplateFile[] {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
function packageJson(opts: ScaffoldOptions): string {
|
|
30
|
-
return
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
30
|
+
return (
|
|
31
|
+
JSON.stringify(
|
|
32
|
+
{
|
|
33
|
+
name: opts.projectName,
|
|
34
|
+
version: '0.0.1',
|
|
35
|
+
type: 'module',
|
|
36
|
+
private: true,
|
|
37
|
+
scripts: {
|
|
38
|
+
dev: 'bun --hot index.ts',
|
|
39
|
+
start: 'bun index.ts',
|
|
40
|
+
test: 'bun test tests/',
|
|
41
|
+
},
|
|
42
|
+
dependencies: {
|
|
43
|
+
'@stravigor/core': '^0.1.0',
|
|
44
|
+
luxon: '^3.7.2',
|
|
45
|
+
'reflect-metadata': '^0.2.2',
|
|
46
|
+
},
|
|
47
|
+
devDependencies: {
|
|
48
|
+
'@types/bun': 'latest',
|
|
49
|
+
'@types/luxon': '^3.7.1',
|
|
50
|
+
'@stravigor/testing': '^0.1.0',
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
null,
|
|
54
|
+
2
|
|
55
|
+
) + '\n'
|
|
56
|
+
)
|
|
51
57
|
}
|
|
52
58
|
|
|
53
59
|
function tsconfig(): string {
|
|
54
|
-
return
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
60
|
+
return (
|
|
61
|
+
JSON.stringify(
|
|
62
|
+
{
|
|
63
|
+
compilerOptions: {
|
|
64
|
+
lib: ['ESNext'],
|
|
65
|
+
target: 'ESNext',
|
|
66
|
+
module: 'ESNext',
|
|
67
|
+
moduleDetection: 'force',
|
|
68
|
+
allowJs: true,
|
|
69
|
+
moduleResolution: 'bundler',
|
|
70
|
+
allowImportingTsExtensions: true,
|
|
71
|
+
noEmit: true,
|
|
72
|
+
experimentalDecorators: true,
|
|
73
|
+
emitDecoratorMetadata: true,
|
|
74
|
+
strict: true,
|
|
75
|
+
skipLibCheck: true,
|
|
76
|
+
noFallthroughCasesInSwitch: true,
|
|
77
|
+
noUnusedLocals: false,
|
|
78
|
+
noUnusedParameters: false,
|
|
79
|
+
},
|
|
80
|
+
include: ['**/*.ts'],
|
|
81
|
+
},
|
|
82
|
+
null,
|
|
83
|
+
2
|
|
84
|
+
) + '\n'
|
|
85
|
+
)
|
|
74
86
|
}
|
|
75
87
|
|
|
76
88
|
function dotEnv(opts: ScaffoldOptions, appKey: string): string {
|
package/src/templates/web.ts
CHANGED
|
@@ -15,51 +15,43 @@ export function getWebFiles(opts: ScaffoldOptions): TemplateFile[] {
|
|
|
15
15
|
function indexTs(opts: ScaffoldOptions): string {
|
|
16
16
|
return `import 'reflect-metadata'
|
|
17
17
|
import { app } from '@stravigor/core/core'
|
|
18
|
-
import
|
|
19
|
-
import
|
|
18
|
+
import { router } from '@stravigor/core/http'
|
|
19
|
+
import {
|
|
20
|
+
ConfigProvider, DatabaseProvider, EncryptionProvider, SessionProvider,
|
|
21
|
+
} from '@stravigor/core/providers'
|
|
20
22
|
import BaseModel from '@stravigor/core/orm/base_model'
|
|
21
|
-
import
|
|
23
|
+
import Database from '@stravigor/core/database/database'
|
|
22
24
|
import Server from '@stravigor/core/http/server'
|
|
23
25
|
import { ExceptionHandler } from '@stravigor/core/exceptions'
|
|
24
|
-
import EncryptionManager from '@stravigor/core/encryption/encryption_manager'
|
|
25
|
-
import SessionManager from '@stravigor/core/session/session_manager'
|
|
26
26
|
import { ViewEngine } from '@stravigor/core/view'
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const db = app.resolve(Database)
|
|
35
|
-
new BaseModel(db)
|
|
36
|
-
|
|
37
|
-
app.singleton(EncryptionManager)
|
|
38
|
-
app.resolve(EncryptionManager)
|
|
28
|
+
// Register service providers
|
|
29
|
+
app
|
|
30
|
+
.use(new ConfigProvider())
|
|
31
|
+
.use(new DatabaseProvider())
|
|
32
|
+
.use(new EncryptionProvider())
|
|
33
|
+
.use(new SessionProvider())
|
|
39
34
|
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
// Boot services (loads config, connects database, derives encryption keys, starts sessions)
|
|
36
|
+
await app.start()
|
|
42
37
|
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
// Initialize ORM
|
|
39
|
+
new BaseModel(app.resolve(Database))
|
|
45
40
|
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
// Initialize view engine
|
|
42
|
+
app.singleton(ViewEngine)
|
|
43
|
+
app.resolve(ViewEngine)
|
|
48
44
|
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
// Configure router
|
|
46
|
+
router.useExceptionHandler(new ExceptionHandler(true))
|
|
51
47
|
|
|
52
|
-
|
|
48
|
+
// Load routes
|
|
49
|
+
await import('./start/routes')
|
|
53
50
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
boot().catch((err) => {
|
|
60
|
-
console.error('Failed to boot:', err)
|
|
61
|
-
process.exit(1)
|
|
62
|
-
})
|
|
51
|
+
// Start HTTP server
|
|
52
|
+
app.singleton(Server)
|
|
53
|
+
const server = app.resolve(Server)
|
|
54
|
+
server.start(router)
|
|
63
55
|
`
|
|
64
56
|
}
|
|
65
57
|
|