create-astro-modular 1.0.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 David V. Kimball
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,32 @@
1
+ # create-astro-modular
2
+
3
+ Scaffold an [Astro Modular](https://github.com/davidvkimball/astro-modular) blog in seconds.
4
+
5
+ ## Usage
6
+
7
+ ```bash
8
+ # pnpm
9
+ pnpm create astro-modular my-blog
10
+
11
+ # npm
12
+ npm create astro-modular my-blog
13
+
14
+ # Interactive (prompts for project name)
15
+ pnpm create astro-modular
16
+ ```
17
+
18
+ ## What it does
19
+
20
+ 1. Downloads the latest Astro Modular template from GitHub
21
+ 2. Removes dev-only files (`cli/`, `.github/`, `.ref/`, `AGENTS.md`)
22
+ 3. Installs dependencies
23
+ 4. Prints next steps
24
+
25
+ ## Requirements
26
+
27
+ - Node.js 18+
28
+ - pnpm, npm, yarn, or bun
29
+
30
+ ## License
31
+
32
+ [MIT](LICENSE)
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import { main } from '../src/index.mjs';
3
+ main();
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "create-astro-modular",
3
+ "version": "1.0.0",
4
+ "description": "Scaffold an Astro Modular blog in seconds",
5
+ "type": "module",
6
+ "bin": {
7
+ "create-astro-modular": "bin/create-astro-modular.mjs"
8
+ },
9
+ "files": [
10
+ "bin",
11
+ "src",
12
+ "LICENSE"
13
+ ],
14
+ "keywords": [
15
+ "astro",
16
+ "blog",
17
+ "theme",
18
+ "obsidian",
19
+ "create",
20
+ "scaffold",
21
+ "template"
22
+ ],
23
+ "author": "David V. Kimball",
24
+ "license": "MIT",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "https://github.com/davidvkimball/astro-modular",
28
+ "directory": "cli"
29
+ },
30
+ "homepage": "https://github.com/davidvkimball/astro-modular",
31
+ "dependencies": {
32
+ "giget": "^2.0.0"
33
+ },
34
+ "engines": {
35
+ "node": ">=18.0.0"
36
+ }
37
+ }
package/src/index.mjs ADDED
@@ -0,0 +1,120 @@
1
+ import { downloadTemplate } from 'giget';
2
+ import { existsSync, readdirSync, rmSync } from 'node:fs';
3
+ import { resolve, basename } from 'node:path';
4
+ import { createInterface } from 'node:readline/promises';
5
+ import { execSync } from 'node:child_process';
6
+
7
+ // ANSI color helpers
8
+ const bold = (s) => `\x1b[1m${s}\x1b[22m`;
9
+ const green = (s) => `\x1b[32m${s}\x1b[39m`;
10
+ const cyan = (s) => `\x1b[36m${s}\x1b[39m`;
11
+ const red = (s) => `\x1b[31m${s}\x1b[39m`;
12
+ const dim = (s) => `\x1b[2m${s}\x1b[22m`;
13
+
14
+ const TEMPLATE = 'gh:davidvkimball/astro-modular#master';
15
+
16
+ const CLEANUP = [
17
+ 'cli',
18
+ '.github',
19
+ '.ref',
20
+ 'AGENTS.md',
21
+ ];
22
+
23
+ function detectPackageManager() {
24
+ const ua = process.env.npm_config_user_agent || '';
25
+ if (ua.startsWith('pnpm')) return 'pnpm';
26
+ if (ua.startsWith('yarn')) return 'yarn';
27
+ if (ua.startsWith('bun')) return 'bun';
28
+ return 'npm';
29
+ }
30
+
31
+ function isEmpty(dir) {
32
+ if (!existsSync(dir)) return true;
33
+ const entries = readdirSync(dir);
34
+ return entries.length === 0;
35
+ }
36
+
37
+ export async function main() {
38
+ console.log();
39
+ console.log(bold(cyan(' create-astro-modular')) + dim(' - Scaffold an Astro Modular blog'));
40
+ console.log();
41
+
42
+ let projectName = process.argv[2];
43
+
44
+ // Prompt for project name if not provided
45
+ if (!projectName) {
46
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
47
+ try {
48
+ projectName = await rl.question(cyan('? ') + bold('Project name: '));
49
+ projectName = projectName.trim();
50
+ } finally {
51
+ rl.close();
52
+ }
53
+ }
54
+
55
+ if (!projectName) {
56
+ console.log(red('Error: Project name is required.'));
57
+ process.exit(1);
58
+ }
59
+
60
+ const targetDir = resolve(process.cwd(), projectName);
61
+
62
+ // Validate target directory
63
+ if (!isEmpty(targetDir)) {
64
+ console.log(red(`Error: Directory "${projectName}" already exists and is not empty.`));
65
+ process.exit(1);
66
+ }
67
+
68
+ // Download template
69
+ console.log();
70
+ console.log(` ${dim('Downloading template...')}`);
71
+
72
+ try {
73
+ await downloadTemplate(TEMPLATE, {
74
+ dir: targetDir,
75
+ force: true,
76
+ });
77
+ } catch (err) {
78
+ console.log(red(`Error downloading template: ${err.message}`));
79
+ process.exit(1);
80
+ }
81
+
82
+ // Clean up dev-only files and directories
83
+ for (const name of CLEANUP) {
84
+ const target = resolve(targetDir, name);
85
+ if (existsSync(target)) {
86
+ rmSync(target, { recursive: true, force: true });
87
+ }
88
+ }
89
+
90
+ console.log(green(' Template downloaded and cleaned up.'));
91
+
92
+ // Detect package manager and install
93
+ const pm = detectPackageManager();
94
+ console.log(` ${dim(`Installing dependencies with ${pm}...`)}`);
95
+
96
+ try {
97
+ execSync(`${pm} install`, {
98
+ cwd: targetDir,
99
+ stdio: 'inherit',
100
+ });
101
+ console.log(green(' Dependencies installed.'));
102
+ } catch {
103
+ console.log(dim(' Could not install dependencies. Run install manually.'));
104
+ }
105
+
106
+ // Success message
107
+ const cdPath = basename(targetDir) === basename(process.cwd())
108
+ ? '.'
109
+ : projectName;
110
+
111
+ console.log();
112
+ console.log(green(bold(' Done!')) + ' Your Astro Modular blog is ready.');
113
+ console.log();
114
+ console.log(' Next steps:');
115
+ console.log(` ${cyan('cd')} ${cdPath}`);
116
+ console.log(` ${cyan(`${pm} dev`)}`);
117
+ console.log();
118
+ console.log(dim(' Docs: https://github.com/davidvkimball/astro-modular'));
119
+ console.log();
120
+ }