create-bildr 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +20 -2
- package/dist/cli.d.ts +12 -0
- package/dist/cli.js +65 -0
- package/dist/create.d.ts +22 -0
- package/dist/create.js +61 -0
- package/package.json +31 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Nuxt UI Templates
|
|
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,21 @@
|
|
|
1
|
-
#
|
|
1
|
+
# create-bildr
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Creates a new [bildr](https://github.com/webbegg/bildr) project: a Nuxt 4 app from the bildr starter kit, with `@bildr/nuxt` (the visual editor, dev only) in its devDependencies.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
pnpm create bildr my-app
|
|
7
|
+
cd my-app
|
|
8
|
+
pnpm install
|
|
9
|
+
pnpm dev
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
`nuxt dev` prints the editor link (`/__bildr?token=…`). The app is a normal Nuxt project: it builds and runs without bildr.
|
|
13
|
+
|
|
14
|
+
Options:
|
|
15
|
+
|
|
16
|
+
- `--name "My App"`: the project name (default: from the directory name).
|
|
17
|
+
- `--module main`: the first feature module (a Nuxt layer under `layers/`).
|
|
18
|
+
- `--database sqlite|none`: the app database. `sqlite` (default) gives a `main` sqlite data source with Drizzle, libSQL and migrations. `none` gives an API-only project: data comes from REST data sources, with no database code or dependencies and no migrations. To add a database later, add a sqlite data source in the editor, plus `@libsql/client`, `drizzle-orm` and `drizzle-kit` in `package.json`.
|
|
19
|
+
- `--bildr <spec>`: where `@bildr/nuxt` comes from, as a package.json spec: a version range, `file:<tarball>` or `link:<path>`. Default: `^<create-bildr's version>`.
|
|
20
|
+
|
|
21
|
+
Requires Node 22.18 or newer.
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import type { StarterDatabase } from '@bildr/codegen/starter';
|
|
3
|
+
export interface CliArgs {
|
|
4
|
+
dir: string;
|
|
5
|
+
name: string;
|
|
6
|
+
module: string;
|
|
7
|
+
/** Dependency spec for @bildr/nuxt; the starter kit's default when absent. */
|
|
8
|
+
bildr?: string;
|
|
9
|
+
/** `sqlite` (the starter kit's default when absent) or `none`: an API-only project with no database. */
|
|
10
|
+
database?: StarterDatabase;
|
|
11
|
+
}
|
|
12
|
+
export declare const parseArgs: (argv: string[]) => CliArgs;
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { realpathSync } from 'node:fs';
|
|
3
|
+
import { basename, relative, resolve } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { STARTER_DATABASES } from '@bildr/codegen/starter';
|
|
6
|
+
import { createProject } from "./create.js";
|
|
7
|
+
const USAGE = 'Usage: pnpm create bildr <directory> [--name "Project name"] [--module main] [--database sqlite|none] [--bildr <@bildr/nuxt version or link:path>]';
|
|
8
|
+
const OPTIONS = ['name', 'module', 'database', 'bildr'];
|
|
9
|
+
const titleFromDir = (dir) => basename(resolve(dir)).split(/[-_\s]+/).filter(Boolean)
|
|
10
|
+
.map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(' ');
|
|
11
|
+
export const parseArgs = (argv) => {
|
|
12
|
+
const options = {};
|
|
13
|
+
const positional = [];
|
|
14
|
+
for (let i = 0; i < argv.length; i++) {
|
|
15
|
+
const arg = argv[i];
|
|
16
|
+
if (!arg.startsWith('--')) {
|
|
17
|
+
positional.push(arg);
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
const [key, inline] = arg.slice(2).split(/=(.*)/s, 2);
|
|
21
|
+
if (!OPTIONS.includes(key))
|
|
22
|
+
throw new Error(`Unknown option --${key}\n${USAGE}`);
|
|
23
|
+
const value = inline ?? argv[++i];
|
|
24
|
+
if (value === undefined || value.trim() === '')
|
|
25
|
+
throw new Error(`--${key} needs a value\n${USAGE}`);
|
|
26
|
+
options[key] = value;
|
|
27
|
+
}
|
|
28
|
+
const dir = positional[0];
|
|
29
|
+
if (!dir || positional.length > 1)
|
|
30
|
+
throw new Error(USAGE);
|
|
31
|
+
const database = options.database;
|
|
32
|
+
if (database !== undefined && !STARTER_DATABASES.includes(database))
|
|
33
|
+
throw new Error(`--database: use ${STARTER_DATABASES.join(' or ')}\n${USAGE}`);
|
|
34
|
+
return {
|
|
35
|
+
dir,
|
|
36
|
+
name: options.name ?? titleFromDir(dir),
|
|
37
|
+
module: options.module ?? 'main',
|
|
38
|
+
...(options.bildr ? { bildr: options.bildr } : {}),
|
|
39
|
+
...(database ? { database: database } : {})
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
const main = () => {
|
|
43
|
+
try {
|
|
44
|
+
const args = parseArgs(process.argv.slice(2));
|
|
45
|
+
const dir = resolve(args.dir);
|
|
46
|
+
const { files } = createProject(dir, { name: args.name, module: args.module, ...(args.bildr ? { bildrNuxt: args.bildr } : {}), ...(args.database ? { database: args.database } : {}) });
|
|
47
|
+
const cd = relative(process.cwd(), dir) || '.';
|
|
48
|
+
console.log(`Created ${args.name} (${files.length} files) in ${dir}\n\nNext:\n cd ${cd}\n pnpm install\n pnpm dev`);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
console.error(error.message);
|
|
52
|
+
process.exitCode = 1;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
/** Run as a program, also through the symlink a package manager installs as the bin. */
|
|
56
|
+
const isEntry = () => {
|
|
57
|
+
try {
|
|
58
|
+
return Boolean(process.argv[1]) && realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url));
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
if (isEntry())
|
|
65
|
+
main();
|
package/dist/create.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { StarterKitOptions } from '@bildr/codegen/starter';
|
|
2
|
+
/** `link:` to this checkout's `packages/nuxt`, when `moduleUrl` is a module of this checkout's `packages/create-bildr`. */
|
|
3
|
+
export declare const localBildrNuxt: (moduleUrl?: string) => string | undefined;
|
|
4
|
+
/**
|
|
5
|
+
* The `@bildr/nuxt` spec a created project gets unless one is given (`--bildr`).
|
|
6
|
+
* - From this checkout's sources (`src/*.ts`, as the tests and e2e run it): a link
|
|
7
|
+
* to the local package, so the project installs without the registry.
|
|
8
|
+
* - From the built package (`dist/*.js`, as `pnpm create bildr` runs it):
|
|
9
|
+
* `^<create-bildr's version>`; the packages are released together.
|
|
10
|
+
*/
|
|
11
|
+
export declare const defaultBildrNuxt: (moduleUrl?: string) => string;
|
|
12
|
+
export interface CreateResult {
|
|
13
|
+
/** Project-relative paths in the order they were written; the manifest is last. */
|
|
14
|
+
files: string[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Writes a new starter-kit project into `dir` (decision D9: new projects only).
|
|
18
|
+
* The directory must not exist or be empty. The model goes first, then the
|
|
19
|
+
* first sync, then the manifest, so an interrupted run never leaves a manifest
|
|
20
|
+
* that claims files it didn't write.
|
|
21
|
+
*/
|
|
22
|
+
export declare const createProject: (dir: string, options: StarterKitOptions) => CreateResult;
|
package/dist/create.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { MANIFEST_FILE, SCHEMA_URL, stringifyModelFile } from '@bildr/codegen/model';
|
|
6
|
+
import { GENERATOR_VERSION, starterKit } from '@bildr/codegen/starter';
|
|
7
|
+
import { planSync } from '@bildr/codegen/sync';
|
|
8
|
+
const sha256 = (content) => createHash('sha256').update(content).digest('hex');
|
|
9
|
+
/** `link:` to this checkout's `packages/nuxt`, when `moduleUrl` is a module of this checkout's `packages/create-bildr`. */
|
|
10
|
+
export const localBildrNuxt = (moduleUrl = import.meta.url) => {
|
|
11
|
+
const dir = fileURLToPath(new URL('../../nuxt/', moduleUrl)).replace(/\/$/, '');
|
|
12
|
+
const manifest = join(dir, 'package.json');
|
|
13
|
+
if (!existsSync(manifest))
|
|
14
|
+
return undefined;
|
|
15
|
+
const pkg = JSON.parse(readFileSync(manifest, 'utf8'));
|
|
16
|
+
return pkg.name === '@bildr/nuxt' ? `link:${dir}` : undefined;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* The `@bildr/nuxt` spec a created project gets unless one is given (`--bildr`).
|
|
20
|
+
* - From this checkout's sources (`src/*.ts`, as the tests and e2e run it): a link
|
|
21
|
+
* to the local package, so the project installs without the registry.
|
|
22
|
+
* - From the built package (`dist/*.js`, as `pnpm create bildr` runs it):
|
|
23
|
+
* `^<create-bildr's version>`; the packages are released together.
|
|
24
|
+
*/
|
|
25
|
+
export const defaultBildrNuxt = (moduleUrl = import.meta.url) => {
|
|
26
|
+
const local = moduleUrl.endsWith('.ts') ? localBildrNuxt(moduleUrl) : undefined;
|
|
27
|
+
if (local)
|
|
28
|
+
return local;
|
|
29
|
+
// package.json is one level up from both src/ and dist/.
|
|
30
|
+
const own = JSON.parse(readFileSync(new URL('../package.json', moduleUrl), 'utf8'));
|
|
31
|
+
return `^${own.version}`;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Writes a new starter-kit project into `dir` (decision D9: new projects only).
|
|
35
|
+
* The directory must not exist or be empty. The model goes first, then the
|
|
36
|
+
* first sync, then the manifest, so an interrupted run never leaves a manifest
|
|
37
|
+
* that claims files it didn't write.
|
|
38
|
+
*/
|
|
39
|
+
export const createProject = (dir, options) => {
|
|
40
|
+
if (existsSync(dir)) {
|
|
41
|
+
if (!statSync(dir).isDirectory())
|
|
42
|
+
throw new Error(`${dir} exists and is not a directory`);
|
|
43
|
+
if (readdirSync(dir).length > 0)
|
|
44
|
+
throw new Error(`${dir} is not empty: bildr creates new projects only`);
|
|
45
|
+
}
|
|
46
|
+
const kit = starterKit({ ...options, bildrNuxt: options.bildrNuxt ?? defaultBildrNuxt() });
|
|
47
|
+
const plan = planSync({ generated: kit.files, manifest: {}, disk: {}, hash: sha256 });
|
|
48
|
+
const written = [];
|
|
49
|
+
const write = (path, content) => {
|
|
50
|
+
const target = join(dir, path);
|
|
51
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
52
|
+
writeFileSync(target, content, { flag: 'wx' });
|
|
53
|
+
written.push(path);
|
|
54
|
+
};
|
|
55
|
+
for (const [path, content] of Object.entries(kit.model))
|
|
56
|
+
write(path, content);
|
|
57
|
+
for (const file of plan.writes)
|
|
58
|
+
write(file.path, file.content);
|
|
59
|
+
write(MANIFEST_FILE, stringifyModelFile({ $schema: `${SCHEMA_URL}/manifest.v1.json`, generatorVersion: GENERATOR_VERSION, files: plan.manifest }));
|
|
60
|
+
return { files: written };
|
|
61
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-bildr",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Create a new bildr project from the starter kit: pnpm create bildr <directory>",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/webbegg/bildr.git",
|
|
9
|
+
"directory": "packages/create-bildr"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"bin": {
|
|
13
|
+
"create-bildr": "./dist/cli.js"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=22.18.0"
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@bildr/codegen": "0.1.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/node": "^26.6.6"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "node -e \"fs.rmSync('dist', { recursive: true, force: true })\" && tsc -p tsconfig.build.json",
|
|
32
|
+
"typecheck": "tsc -p tsconfig.json"
|
|
33
|
+
}
|
|
6
34
|
}
|