@create-node-app/core 0.5.7 → 0.6.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/README.md ADDED
@@ -0,0 +1,148 @@
1
+ <div align="center">
2
+
3
+ <h1>⚙️ <code>@create-node-app/core</code></h1>
4
+
5
+ <p><strong>Programmatic engine behind Create Awesome Node App.</strong><br/>
6
+ Import the scaffolding pipeline — composable, headless, and CI-ready.</p>
7
+
8
+ [![npm][npmversion]][npmurl]
9
+ [![Downloads][npmdownloads]][npmurl]
10
+ [![License: MIT][licensebadge]][licenseurl]
11
+
12
+ </div>
13
+
14
+ ---
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ npm install @create-node-app/core
20
+ ```
21
+
22
+ Requires **Node.js >= 22**.
23
+
24
+ > This is the _engine_ package. For the interactive CLI, use [`create-awesome-node-app`](https://www.npmjs.com/package/create-awesome-node-app) instead.
25
+
26
+ ---
27
+
28
+ ## Usage
29
+
30
+ ### Scaffold a project programmatically
31
+
32
+ ```ts
33
+ import { createNodeApp, getTemplateDirPath } from "@create-node-app/core";
34
+
35
+ await createNodeApp(
36
+ "my-app",
37
+ {
38
+ projectName: "my-app",
39
+ template: "react-vite-boilerplate",
40
+ },
41
+ (options) => Promise.resolve(options),
42
+ );
43
+ ```
44
+
45
+ ### Check environment info
46
+
47
+ ```ts
48
+ import { printEnvInfo } from "@create-node-app/core";
49
+
50
+ await printEnvInfo();
51
+ // Prints OS, CPU, Node, npm, browsers, etc. Then exits.
52
+ ```
53
+
54
+ ### Validate the Node.js version
55
+
56
+ ```ts
57
+ import { checkNodeVersion } from "@create-node-app/core";
58
+
59
+ checkNodeVersion(">=22", "my-tool");
60
+ // Exits with a red error message if the version doesn't match.
61
+ ```
62
+
63
+ ---
64
+
65
+ ## API Reference
66
+
67
+ All exports from `@create-node-app/core`:
68
+
69
+ ### Functions
70
+
71
+ | Signature | Description |
72
+ |-----------|-------------|
73
+ | `createNodeApp(programName, options, transformOptions)` | Main scaffolding orchestrator. Resolves the template, copies files, merges configs, installs deps, and initializes git. |
74
+ | `checkNodeVersion(requiredVersion, packageName)` | Compares `process.version` against a semver range. Exits with code 1 if too old. |
75
+ | `checkForLatestVersion(packageName)` | Fetches the latest version from the npm registry. Falls back to `npm view`. Returns `null` if both fail. |
76
+ | `printEnvInfo()` | Prints OS, CPU, binaries, and browser info to stdout, then exits. |
77
+ | `getPackagePath(templateOrExtension, name?, ignorePackage?)` | Resolves a file path inside a template/extension directory (usually `package.json`). Handles GitHub URLs, `file://` URLs, and legacy slugs. |
78
+ | `getTemplateDirPath(templateOrExtensionUrl)` | Resolves the template directory. Looks for a `template/` subdirectory first, falls back to the resolved root. |
79
+ | `getTemplateBaseDirPath(templateOrExtensionUrl)` | Returns the parent of the `template/` directory (where `cna.config.json` lives). |
80
+ | `downloadRepository(options)` | Clones or pulls a Git repo into a cache dir, then copies files to the target. Supports offline mode, deduplication, and error formatting. |
81
+ | `loadTemplateCnaConfig(templateUrl)` | Loads the optional `cna.config.json` from a template's base directory. |
82
+
83
+ ### Types
84
+
85
+ | Type | Shape |
86
+ |------|-------|
87
+ | `CnaOptions` | `{ projectName, info?, verbose?, packageManager?, install?, template?, templatesOrExtensions?, ... }` |
88
+ | `CnaOptionsTransform` | `(options: CnaOptions) => Promise<CnaOptions>` |
89
+ | `CnaConfig` | `{ customOptions?: CnaCustomOption[] }` |
90
+ | `CnaCustomOption` | `{ name, type, message?, initial?, ... }` |
91
+ | `TemplateOrExtension` | `{ url: string; ignorePackage?: boolean }` |
92
+
93
+ ---
94
+
95
+ ## How It Works
96
+
97
+ ```
98
+ createNodeApp()
99
+ ├── checkNodeVersion()
100
+ ├── printEnvInfo() if info flag
101
+ ├── resolve templates/extensions via getTemplateDirPath()
102
+ ├── download Git repos via downloadRepository()
103
+ ├── load cna.config.json via loadTemplateCnaConfig()
104
+ ├── merge package.json files via lodash.merge
105
+ ├── copy/process template files (Lodash interpolation, .if-npm, .append, etc.)
106
+ ├── install dependencies (npm/yarn/pnpm/bun)
107
+ ├── git init
108
+ └── format + lint:fix post-install
109
+ ```
110
+
111
+ ---
112
+
113
+ ## Architecture
114
+
115
+ The package is organized into these modules:
116
+
117
+ | Module | Responsibility |
118
+ |--------|---------------|
119
+ | `index.ts` | Barrel export and main `createNodeApp` orchestration |
120
+ | `installer.ts` | Project directory creation, dep installation, git init, post-install scripts |
121
+ | `loaders.ts` | File discovery, classification (`.template`, `.append`, conditional prefixes), and processing |
122
+ | `package.ts` | Deep-merges `package.json` from multiple templates/extensions |
123
+ | `paths.ts` | URL resolution — GitHub branches, `file://`, legacy slugs, cache at `~/.cna/` |
124
+ | `git.ts` | Clone/pull with deduplication, offline support, error formatting |
125
+ | `config.ts` | Reads optional `cna.config.json` for custom CLI prompts |
126
+ | `helpers.ts` | Package manager detection, online check, path/naming utilities |
127
+
128
+ ---
129
+
130
+ ## Related
131
+
132
+ - [`create-awesome-node-app`](https://www.npmjs.com/package/create-awesome-node-app) — Interactive CLI built on this core
133
+ - [Create Node App](https://github.com/Create-Node-App/create-node-app) — Monorepo
134
+ - [Templates catalog](https://github.com/Create-Node-App/cna-templates)
135
+
136
+ ---
137
+
138
+ ## License
139
+
140
+ MIT &copy; [Create Node App Contributors](https://github.com/Create-Node-App/create-node-app/graphs/contributors)
141
+
142
+ <!-- Reference links -->
143
+
144
+ [npmversion]: https://img.shields.io/npm/v/@create-node-app/core.svg?style=flat-square&color=cb3837
145
+ [npmdownloads]: https://img.shields.io/npm/dm/@create-node-app/core.svg?style=flat-square&color=cb3837
146
+ [licensebadge]: https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square
147
+ [npmurl]: https://www.npmjs.com/package/@create-node-app/core
148
+ [licenseurl]: https://github.com/Create-Node-App/create-node-app/blob/main/LICENSE