@vigajs/create 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +8 -2
- package/index.js +166 -0
- package/package.json +30 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Diego Monsalve
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @vigajs/create
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Creates a new [viga](https://vigajs.dev) project.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
pnpm create @vigajs my-app
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
It also works with `npm create @vigajs@latest my-app`, `yarn create @vigajs my-app` and `bunx @vigajs/create my-app`. Use `--schema valibot` or `--schema none` to change the validation library, which is Zod by default.
|
package/index.js
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { existsSync, mkdirSync, readdirSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { basename, dirname, join, resolve } from 'node:path';
|
|
4
|
+
import { parseArgs } from 'node:util';
|
|
5
|
+
|
|
6
|
+
const MIN_NODE = [24, 13];
|
|
7
|
+
const NAME_FORMAT = /^[a-z0-9][a-z0-9._-]{0,213}$/;
|
|
8
|
+
|
|
9
|
+
const VERSIONS = {
|
|
10
|
+
'@vigajs/core': '^0.1.1',
|
|
11
|
+
'@vigajs/validation': '^0.1.1',
|
|
12
|
+
express: '^5.1.0',
|
|
13
|
+
zod: '^4.0.0',
|
|
14
|
+
valibot: '^1.5.0',
|
|
15
|
+
typescript: '^7.0.0',
|
|
16
|
+
tsx: '^4.23.0',
|
|
17
|
+
'@types/express': '^5.0.0',
|
|
18
|
+
'@types/node': '^24.0.0',
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const SCHEMAS = ['zod', 'valibot', 'none'];
|
|
22
|
+
|
|
23
|
+
function fail(message) {
|
|
24
|
+
console.error(`error: ${message}`);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function packageManager() {
|
|
29
|
+
const agent = process.env.npm_config_user_agent ?? '';
|
|
30
|
+
const [name = 'npm', version = ''] = agent.split(' ')[0]?.split('/') ?? [];
|
|
31
|
+
return { name: ['pnpm', 'yarn', 'bun', 'npm'].includes(name) ? name : 'npm', major: Number(version.split('.')[0]) };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function pickVersions(names) {
|
|
35
|
+
return Object.fromEntries(names.sort().map((name) => [name, VERSIONS[name]]));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function projectFiles(name, schema, manager) {
|
|
39
|
+
const dependencies = ['@vigajs/core', 'express', ...(schema === 'none' ? [] : ['@vigajs/validation', schema])];
|
|
40
|
+
const packageJson = {
|
|
41
|
+
name,
|
|
42
|
+
version: '0.1.0',
|
|
43
|
+
private: true,
|
|
44
|
+
type: 'module',
|
|
45
|
+
scripts: {
|
|
46
|
+
dev: 'tsx watch src/main.ts',
|
|
47
|
+
build: 'tsc',
|
|
48
|
+
start: 'node dist/main.js',
|
|
49
|
+
},
|
|
50
|
+
dependencies: pickVersions(dependencies),
|
|
51
|
+
devDependencies: pickVersions(['typescript', 'tsx', '@types/express', '@types/node']),
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const files = {
|
|
55
|
+
'package.json': `${JSON.stringify(packageJson, null, 2)}\n`,
|
|
56
|
+
'tsconfig.json': `${JSON.stringify({ extends: '@vigajs/core/tsconfig.json', include: ['src'] }, null, 2)}\n`,
|
|
57
|
+
'.gitignore': 'node_modules\ndist\n.env\n',
|
|
58
|
+
'src/main.ts': `import { createApp } from '@vigajs/core';
|
|
59
|
+
import { AppModule } from './app.module.ts';
|
|
60
|
+
|
|
61
|
+
const app = createApp({ rootModule: AppModule }).enableShutdownHooks();
|
|
62
|
+
|
|
63
|
+
await app.listen();
|
|
64
|
+
`,
|
|
65
|
+
'src/app.module.ts': `import { Module } from '@vigajs/core';
|
|
66
|
+
import { HelloModule } from './hello/hello.module.ts';
|
|
67
|
+
|
|
68
|
+
@Module({
|
|
69
|
+
imports: [HelloModule],
|
|
70
|
+
})
|
|
71
|
+
export class AppModule {}
|
|
72
|
+
`,
|
|
73
|
+
'src/hello/hello.module.ts': `import { Module } from '@vigajs/core';
|
|
74
|
+
import { HelloController } from './hello.controller.ts';
|
|
75
|
+
import { HelloService } from './hello.service.ts';
|
|
76
|
+
|
|
77
|
+
@Module({
|
|
78
|
+
controllers: [HelloController],
|
|
79
|
+
providers: [HelloService],
|
|
80
|
+
})
|
|
81
|
+
export class HelloModule {}
|
|
82
|
+
`,
|
|
83
|
+
'src/hello/hello.controller.ts': `import { Controller, Get, Public, inject } from '@vigajs/core';
|
|
84
|
+
import { HelloService } from './hello.service.ts';
|
|
85
|
+
|
|
86
|
+
@Controller('/hello')
|
|
87
|
+
export class HelloController {
|
|
88
|
+
private readonly hello = inject(HelloService);
|
|
89
|
+
|
|
90
|
+
@Public()
|
|
91
|
+
@Get()
|
|
92
|
+
greet() {
|
|
93
|
+
return this.hello.greet();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
`,
|
|
97
|
+
'src/hello/hello.service.ts': `import { Injectable } from '@vigajs/core';
|
|
98
|
+
|
|
99
|
+
@Injectable()
|
|
100
|
+
export class HelloService {
|
|
101
|
+
greet() {
|
|
102
|
+
return { message: 'Hello from viga' };
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
`,
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
if (manager.name === 'pnpm') {
|
|
109
|
+
files['pnpm-workspace.yaml'] = 'allowBuilds:\n esbuild: true\n';
|
|
110
|
+
}
|
|
111
|
+
if (manager.name === 'yarn' && manager.major >= 2) {
|
|
112
|
+
files['.yarnrc.yml'] = 'nodeLinker: node-modules\n';
|
|
113
|
+
}
|
|
114
|
+
return files;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function nextSteps(directory, manager) {
|
|
118
|
+
const run = manager.name === 'npm' ? 'npm run dev' : `${manager.name} dev`;
|
|
119
|
+
return ['', 'Next steps:', '', ` cd ${directory}`, ` ${manager.name} install`, ` ${run}`, '', 'Then open http://localhost:3000/hello', ''].join('\n');
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function main() {
|
|
123
|
+
const [major = 0, minor = 0] = process.versions.node.split('.').map(Number);
|
|
124
|
+
if (major < MIN_NODE[0] || (major === MIN_NODE[0] && minor < MIN_NODE[1])) {
|
|
125
|
+
fail(`viga needs Node.js ${MIN_NODE.join('.')} or later, and this is ${process.versions.node}`);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
let parsed;
|
|
129
|
+
try {
|
|
130
|
+
parsed = parseArgs({
|
|
131
|
+
allowPositionals: true,
|
|
132
|
+
options: { schema: { type: 'string', default: 'zod' } },
|
|
133
|
+
});
|
|
134
|
+
} catch (error) {
|
|
135
|
+
fail(error.message);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const [directory] = parsed.positionals;
|
|
139
|
+
if (!directory || parsed.positionals.length > 1) {
|
|
140
|
+
fail('usage: pnpm create @vigajs <directory> [--schema zod|valibot|none]');
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const { schema } = parsed.values;
|
|
144
|
+
if (!SCHEMAS.includes(schema)) fail(`--schema must be one of ${SCHEMAS.join(', ')}, received ${schema}`);
|
|
145
|
+
|
|
146
|
+
const target = resolve(directory);
|
|
147
|
+
const name = basename(target);
|
|
148
|
+
if (!NAME_FORMAT.test(name)) {
|
|
149
|
+
fail(`"${name}" is not a valid package name: use lowercase letters, numbers, ".", "_" and "-"`);
|
|
150
|
+
}
|
|
151
|
+
if (existsSync(target) && readdirSync(target).length > 0) {
|
|
152
|
+
fail(`${directory} already exists and is not empty`);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const manager = packageManager();
|
|
156
|
+
for (const [path, content] of Object.entries(projectFiles(name, schema, manager))) {
|
|
157
|
+
const file = join(target, path);
|
|
158
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
159
|
+
writeFileSync(file, content);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
console.log(`Created ${name} in ${target}`);
|
|
163
|
+
console.log(nextSteps(directory, manager));
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
main();
|
package/package.json
CHANGED
|
@@ -1,6 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vigajs/create",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Create a new viga project",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "Diego Monsalve",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/dialmonsalve/viga.git",
|
|
11
|
+
"directory": "packages/create"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://vigajs.dev",
|
|
14
|
+
"keywords": [
|
|
15
|
+
"viga",
|
|
16
|
+
"create",
|
|
17
|
+
"scaffold",
|
|
18
|
+
"starter"
|
|
19
|
+
],
|
|
20
|
+
"bin": {
|
|
21
|
+
"create": "./index.js"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"index.js",
|
|
25
|
+
"README.md"
|
|
26
|
+
],
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=24.13.0"
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
}
|
|
6
33
|
}
|