create-vergekit 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 +42 -0
- package/bin/create-vergekit.js +9 -0
- package/package.json +45 -0
- package/src/cli.js +67 -0
- package/src/create-project.js +43 -0
- package/src/project.js +68 -0
- package/src/template.js +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 J Youngblood
|
|
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
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# create-vergekit
|
|
2
|
+
|
|
3
|
+
Create a new [VergeKit](https://github.com/jyoungblood/vergekit) app.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm create vergekit@latest my-app
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Use the current directory:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm create vergekit@latest .
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## What It Does
|
|
16
|
+
|
|
17
|
+
- Downloads the current `jyoungblood/vergekit` template from GitHub.
|
|
18
|
+
- Copies the template into the target directory.
|
|
19
|
+
- Updates the generated app's `package.json` name from the target folder.
|
|
20
|
+
- Prints the next setup commands.
|
|
21
|
+
|
|
22
|
+
The target directory must be empty, except for common metadata files such as
|
|
23
|
+
`.git`, `.gitkeep`, `.DS_Store`, and `Thumbs.db`.
|
|
24
|
+
|
|
25
|
+
## Development
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install
|
|
29
|
+
npm test
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Run the CLI locally:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
node ./bin/create-vergekit.js my-app
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Check the npm package contents before publishing:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npm pack --dry-run
|
|
42
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-vergekit",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Create a new VergeKit app.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"create-vergekit": "./bin/create-vergekit.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin",
|
|
11
|
+
"src/cli.js",
|
|
12
|
+
"src/create-project.js",
|
|
13
|
+
"src/project.js",
|
|
14
|
+
"src/template.js",
|
|
15
|
+
"README.md",
|
|
16
|
+
"LICENSE"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"test": "node --test",
|
|
20
|
+
"prepack": "npm test"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"astro",
|
|
24
|
+
"cloudflare",
|
|
25
|
+
"d1",
|
|
26
|
+
"vergekit",
|
|
27
|
+
"create"
|
|
28
|
+
],
|
|
29
|
+
"author": "J Youngblood",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=18.17"
|
|
33
|
+
},
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "git+https://github.com/jyoungblood/create-vergekit.git"
|
|
37
|
+
},
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/jyoungblood/create-vergekit/issues"
|
|
40
|
+
},
|
|
41
|
+
"homepage": "https://github.com/jyoungblood/create-vergekit#readme",
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"tar": "^7.4.3"
|
|
44
|
+
}
|
|
45
|
+
}
|
package/src/cli.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { basename } from 'node:path';
|
|
2
|
+
|
|
3
|
+
import { createProject } from './create-project.js';
|
|
4
|
+
import { resolveTargetDirectory } from './project.js';
|
|
5
|
+
|
|
6
|
+
export async function runCli(
|
|
7
|
+
argv,
|
|
8
|
+
{
|
|
9
|
+
cwd = process.cwd(),
|
|
10
|
+
stdout = process.stdout,
|
|
11
|
+
createProjectImpl = createProject,
|
|
12
|
+
} = {},
|
|
13
|
+
) {
|
|
14
|
+
if (argv.includes('--help') || argv.includes('-h')) {
|
|
15
|
+
stdout.write(helpText());
|
|
16
|
+
return 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const positionalArgs = argv.filter((arg) => !arg.startsWith('-'));
|
|
20
|
+
const unknownOptions = argv.filter((arg) => arg.startsWith('-'));
|
|
21
|
+
|
|
22
|
+
if (unknownOptions.length > 0) {
|
|
23
|
+
throw new Error(`Unknown option: ${unknownOptions[0]}`);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (positionalArgs.length > 1) {
|
|
27
|
+
throw new Error('Expected at most one target directory.');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const targetArg = positionalArgs[0] ?? '.';
|
|
31
|
+
const target = resolveTargetDirectory(targetArg, cwd);
|
|
32
|
+
|
|
33
|
+
await createProjectImpl({
|
|
34
|
+
targetPath: target.path,
|
|
35
|
+
packageName: target.packageName,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
stdout.write(successText(targetArg, target.path));
|
|
39
|
+
return 0;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function helpText() {
|
|
43
|
+
return `create-vergekit
|
|
44
|
+
|
|
45
|
+
Usage: npm create vergekit@latest [directory]
|
|
46
|
+
|
|
47
|
+
Examples:
|
|
48
|
+
npm create vergekit@latest
|
|
49
|
+
npm create vergekit@latest my-app
|
|
50
|
+
npm create vergekit@latest .
|
|
51
|
+
`;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function successText(targetArg, targetPath) {
|
|
55
|
+
const projectLabel = targetArg === '.' ? basename(targetPath) : targetArg;
|
|
56
|
+
const cdStep = targetArg === '.' ? '' : ` cd ${targetArg}\n`;
|
|
57
|
+
|
|
58
|
+
return `
|
|
59
|
+
Created VergeKit app in ${projectLabel}.
|
|
60
|
+
|
|
61
|
+
Next steps:
|
|
62
|
+
${cdStep} npm install
|
|
63
|
+
cp .dev.vars.example .dev.vars
|
|
64
|
+
npm run db:migrate:local
|
|
65
|
+
npm run dev
|
|
66
|
+
`;
|
|
67
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { cp, mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
|
|
5
|
+
import { assertTargetDirectoryIsUsable } from './project.js';
|
|
6
|
+
|
|
7
|
+
export async function createProject({
|
|
8
|
+
targetPath,
|
|
9
|
+
packageName,
|
|
10
|
+
downloadAndExtractTemplate,
|
|
11
|
+
}) {
|
|
12
|
+
await assertTargetDirectoryIsUsable(targetPath);
|
|
13
|
+
|
|
14
|
+
const stagingPath = await mkdtemp(join(tmpdir(), 'create-vergekit-template-'));
|
|
15
|
+
const extractTemplate =
|
|
16
|
+
downloadAndExtractTemplate ?? (await loadDefaultTemplateExtractor());
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
await mkdir(stagingPath, { recursive: true });
|
|
20
|
+
await mkdir(targetPath, { recursive: true });
|
|
21
|
+
await extractTemplate(stagingPath);
|
|
22
|
+
await cp(stagingPath, targetPath, {
|
|
23
|
+
recursive: true,
|
|
24
|
+
force: true,
|
|
25
|
+
errorOnExist: false,
|
|
26
|
+
});
|
|
27
|
+
await updateGeneratedPackageName(targetPath, packageName);
|
|
28
|
+
} finally {
|
|
29
|
+
await rm(stagingPath, { recursive: true, force: true });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function loadDefaultTemplateExtractor() {
|
|
34
|
+
const { downloadAndExtractTemplate } = await import('./template.js');
|
|
35
|
+
return downloadAndExtractTemplate;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function updateGeneratedPackageName(targetPath, packageName) {
|
|
39
|
+
const packageJsonPath = join(targetPath, 'package.json');
|
|
40
|
+
const packageJson = JSON.parse(await readFile(packageJsonPath, 'utf8'));
|
|
41
|
+
packageJson.name = packageName;
|
|
42
|
+
await writeFile(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}\n`);
|
|
43
|
+
}
|
package/src/project.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { constants as fsConstants } from 'node:fs';
|
|
2
|
+
import { access, readdir, stat } from 'node:fs/promises';
|
|
3
|
+
import { basename, resolve } from 'node:path';
|
|
4
|
+
|
|
5
|
+
const IGNORED_TARGET_ENTRIES = new Set([
|
|
6
|
+
'.DS_Store',
|
|
7
|
+
'.git',
|
|
8
|
+
'.gitkeep',
|
|
9
|
+
'Thumbs.db',
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
export function normalizePackageName(value) {
|
|
13
|
+
const normalized = value
|
|
14
|
+
.trim()
|
|
15
|
+
.toLowerCase()
|
|
16
|
+
.replace(/[^a-z0-9._~-]+/g, '-')
|
|
17
|
+
.replace(/^[._-]+/, '')
|
|
18
|
+
.replace(/[._-]+$/, '');
|
|
19
|
+
|
|
20
|
+
return normalized || 'vergekit-app';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function resolveTargetDirectory(target, cwd = process.cwd()) {
|
|
24
|
+
const requestedTarget = target || '.';
|
|
25
|
+
const path = resolve(cwd, requestedTarget);
|
|
26
|
+
const folderName = requestedTarget === '.' ? basename(cwd) : basename(path);
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
path,
|
|
30
|
+
packageName: normalizePackageName(folderName),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export async function getBlockingDirectoryEntries(targetPath) {
|
|
35
|
+
try {
|
|
36
|
+
await access(targetPath, fsConstants.F_OK);
|
|
37
|
+
} catch {
|
|
38
|
+
return [];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const targetStat = await stat(targetPath);
|
|
42
|
+
if (!targetStat.isDirectory()) {
|
|
43
|
+
return [basename(targetPath)];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const entries = await readdir(targetPath);
|
|
47
|
+
return entries.filter((entry) => !IGNORED_TARGET_ENTRIES.has(entry));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export async function assertTargetDirectoryIsUsable(targetPath) {
|
|
51
|
+
try {
|
|
52
|
+
await access(targetPath, fsConstants.F_OK);
|
|
53
|
+
} catch {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const targetStat = await stat(targetPath);
|
|
58
|
+
if (!targetStat.isDirectory()) {
|
|
59
|
+
throw new Error(`Target path exists and is not a directory: ${targetPath}`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const blockingEntries = await getBlockingDirectoryEntries(targetPath);
|
|
63
|
+
if (blockingEntries.length > 0) {
|
|
64
|
+
throw new Error(
|
|
65
|
+
`Target directory is not empty: ${blockingEntries.join(', ')}`,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
}
|
package/src/template.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { mkdtemp, rm, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
|
|
5
|
+
export const TEMPLATE_TARBALL_URL =
|
|
6
|
+
'https://codeload.github.com/jyoungblood/vergekit/tar.gz/main';
|
|
7
|
+
|
|
8
|
+
export async function downloadAndExtractTemplate(
|
|
9
|
+
destinationPath,
|
|
10
|
+
{
|
|
11
|
+
fetchImpl = globalThis.fetch,
|
|
12
|
+
extractTarball = extractTarballToDirectory,
|
|
13
|
+
} = {},
|
|
14
|
+
) {
|
|
15
|
+
if (!fetchImpl) {
|
|
16
|
+
throw new Error('This package requires Node.js fetch support.');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let response;
|
|
20
|
+
try {
|
|
21
|
+
response = await fetchImpl(TEMPLATE_TARBALL_URL);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
24
|
+
throw new Error(
|
|
25
|
+
`Failed to download VergeKit template from ${TEMPLATE_TARBALL_URL}: ${reason}`,
|
|
26
|
+
{ cause: error },
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
if (!response.ok) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
`Failed to download VergeKit template: ${response.status} ${response.statusText}`,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const tempPath = await mkdtemp(join(tmpdir(), 'create-vergekit-download-'));
|
|
36
|
+
const tarballPath = join(tempPath, 'template.tar.gz');
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
await writeFile(tarballPath, Buffer.from(await response.arrayBuffer()));
|
|
40
|
+
await extractTarball(tarballPath, destinationPath);
|
|
41
|
+
} finally {
|
|
42
|
+
await rm(tempPath, { recursive: true, force: true });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function extractTarballToDirectory(tarballPath, destinationPath) {
|
|
47
|
+
const tar = await import('tar');
|
|
48
|
+
await tar.x({
|
|
49
|
+
file: tarballPath,
|
|
50
|
+
cwd: destinationPath,
|
|
51
|
+
strip: 1,
|
|
52
|
+
});
|
|
53
|
+
}
|