@baseplate-dev/create-project 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 ADDED
@@ -0,0 +1,390 @@
1
+ Copyright (c) 2025 Half Dome Labs LLC (https://halfdomelabs.com) and individual contributors.
2
+
3
+ ## License
4
+
5
+ This project is licensed under the Mozilla Public License 2.0 (MPL-2.0) with the following exception:
6
+
7
+ **Generated Code Exception**: All code generated by Baseplate generators and templates belongs entirely to the user who generated it. Half Dome Labs LLC disclaims any copyright interest in generated code. Users may use, modify, distribute, and license generated code under any terms they choose, including proprietary licenses, with no restrictions or attribution requirements.
8
+
9
+ # Mozilla Public License Version 2.0
10
+
11
+ 1. Definitions
12
+
13
+ ---
14
+
15
+ 1.1. "Contributor"
16
+ means each individual or legal entity that creates, contributes to
17
+ the creation of, or owns Covered Software.
18
+
19
+ 1.2. "Contributor Version"
20
+ means the combination of the Contributions of others (if any) used
21
+ by a Contributor and that particular Contributor's Contribution.
22
+
23
+ 1.3. "Contribution"
24
+ means Covered Software of a particular Contributor.
25
+
26
+ 1.4. "Covered Software"
27
+ means Source Code Form to which the initial Contributor has attached
28
+ the notice in Exhibit A, the Executable Form of such Source Code
29
+ Form, and Modifications of such Source Code Form, in each case
30
+ including portions thereof.
31
+
32
+ 1.5. "Incompatible With Secondary Licenses"
33
+ means
34
+
35
+ (a) that the initial Contributor has attached the notice described
36
+ in Exhibit B to the Covered Software; or
37
+
38
+ (b) that the Covered Software was made available under the terms of
39
+ version 1.1 or earlier of the License, but not also under the
40
+ terms of a Secondary License.
41
+
42
+ 1.6. "Executable Form"
43
+ means any form of the work other than Source Code Form.
44
+
45
+ 1.7. "Larger Work"
46
+ means a work that combines Covered Software with other material, in
47
+ a separate file or files, that is not Covered Software.
48
+
49
+ 1.8. "License"
50
+ means this document.
51
+
52
+ 1.9. "Licensable"
53
+ means having the right to grant, to the maximum extent possible,
54
+ whether at the time of the initial grant or subsequently, any and
55
+ all of the rights conveyed by this License.
56
+
57
+ 1.10. "Modifications"
58
+ means any of the following:
59
+
60
+ (a) any file in Source Code Form that results from an addition to,
61
+ deletion from, or modification of the contents of Covered
62
+ Software; or
63
+
64
+ (b) any new file in Source Code Form that contains any Covered
65
+ Software.
66
+
67
+ 1.11. "Patent Claims" of a Contributor
68
+ means any patent claim(s), including without limitation, method,
69
+ process, and apparatus claims, in any patent Licensable by such
70
+ Contributor that would be infringed, but for the grant of the
71
+ License, by the making, using, selling, offering for sale, having
72
+ made, import, or transfer of either its Contributions or its
73
+ Contributor Version.
74
+
75
+ 1.12. "Secondary License"
76
+ means either the GNU General Public License, Version 2.0, the GNU
77
+ Lesser General Public License, Version 2.1, the GNU Affero General
78
+ Public License, Version 3.0, or any later versions of those
79
+ licenses.
80
+
81
+ 1.13. "Source Code Form"
82
+ means the form of the work preferred for making modifications.
83
+
84
+ 1.14. "You" (or "Your")
85
+ means an individual or a legal entity exercising rights under this
86
+ License. For legal entities, "You" includes any entity that
87
+ controls, is controlled by, or is under common control with You. For
88
+ purposes of this definition, "control" means (a) the power, direct
89
+ or indirect, to cause the direction or management of such entity,
90
+ whether by contract or otherwise, or (b) ownership of more than
91
+ fifty percent (50%) of the outstanding shares or beneficial
92
+ ownership of such entity.
93
+
94
+ 2. License Grants and Conditions
95
+
96
+ ---
97
+
98
+ 2.1. Grants
99
+
100
+ Each Contributor hereby grants You a world-wide, royalty-free,
101
+ non-exclusive license:
102
+
103
+ (a) under intellectual property rights (other than patent or trademark)
104
+ Licensable by such Contributor to use, reproduce, make available,
105
+ modify, display, perform, distribute, and otherwise exploit its
106
+ Contributions, either on an unmodified basis, with Modifications, or
107
+ as part of a Larger Work; and
108
+
109
+ (b) under Patent Claims of such Contributor to make, use, sell, offer
110
+ for sale, have made, import, and otherwise transfer either its
111
+ Contributions or its Contributor Version.
112
+
113
+ 2.2. Effective Date
114
+
115
+ The licenses granted in Section 2.1 with respect to any Contribution
116
+ become effective for each Contribution on the date the Contributor first
117
+ distributes such Contribution.
118
+
119
+ 2.3. Limitations on Grant Scope
120
+
121
+ The licenses granted in this Section 2 are the only rights granted under
122
+ this License. No additional rights or licenses will be implied from the
123
+ distribution or licensing of Covered Software under this License.
124
+ Notwithstanding Section 2.1(b) above, no patent license is granted by a
125
+ Contributor:
126
+
127
+ (a) for any code that a Contributor has removed from Covered Software;
128
+ or
129
+
130
+ (b) for infringements caused by: (i) Your and any other third party's
131
+ modifications of Covered Software, or (ii) the combination of its
132
+ Contributions with other software (except as part of its Contributor
133
+ Version); or
134
+
135
+ (c) under Patent Claims infringed by Covered Software in the absence of
136
+ its Contributions.
137
+
138
+ This License does not grant any rights in the trademarks, service marks,
139
+ or logos of any Contributor (except as may be necessary to comply with
140
+ the notice requirements in Section 3.4).
141
+
142
+ 2.4. Subsequent Licenses
143
+
144
+ No Contributor makes additional grants as a result of Your choice to
145
+ distribute the Covered Software under a subsequent version of this
146
+ License (see Section 10.2) or under the terms of a Secondary License (if
147
+ permitted under the terms of Section 3.3).
148
+
149
+ 2.5. Representation
150
+
151
+ Each Contributor represents that the Contributor believes its
152
+ Contributions are its original creation(s) or it has sufficient rights
153
+ to grant the rights to its Contributions conveyed by this License.
154
+
155
+ 2.6. Fair Use
156
+
157
+ This License is not intended to limit any rights You have under
158
+ applicable copyright doctrines of fair use, fair dealing, or other
159
+ equivalents.
160
+
161
+ 2.7. Conditions
162
+
163
+ Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
164
+ in Section 2.1.
165
+
166
+ 3. Responsibilities
167
+
168
+ ---
169
+
170
+ 3.1. Distribution of Source Form
171
+
172
+ All distribution of Covered Software in Source Code Form, including any
173
+ Modifications that You create or to which You contribute, must be under
174
+ the terms of this License. You must inform recipients that the Source
175
+ Code Form of the Covered Software is governed by the terms of this
176
+ License, and how they can obtain a copy of this License. You may not
177
+ attempt to alter or restrict the recipients' rights in the Source Code
178
+ Form.
179
+
180
+ 3.2. Distribution of Executable Form
181
+
182
+ If You distribute Covered Software in Executable Form then:
183
+
184
+ (a) such Covered Software must also be made available in Source Code
185
+ Form, as described in Section 3.1, and You must inform recipients of
186
+ the Executable Form how they can obtain a copy of such Source Code
187
+ Form by reasonable means in a timely manner, at a charge no more
188
+ than the cost of distribution to the recipient; and
189
+
190
+ (b) You may distribute such Executable Form under the terms of this
191
+ License, or sublicense it under different terms, provided that the
192
+ license for the Executable Form does not attempt to limit or alter
193
+ the recipients' rights in the Source Code Form under this License.
194
+
195
+ 3.3. Distribution of a Larger Work
196
+
197
+ You may create and distribute a Larger Work under terms of Your choice,
198
+ provided that You also comply with the requirements of this License for
199
+ the Covered Software. If the Larger Work is a combination of Covered
200
+ Software with a work governed by one or more Secondary Licenses, and the
201
+ Covered Software is not Incompatible With Secondary Licenses, this
202
+ License permits You to additionally distribute such Covered Software
203
+ under the terms of such Secondary License(s), so that the recipient of
204
+ the Larger Work may, at their option, further distribute the Covered
205
+ Software under the terms of either this License or such Secondary
206
+ License(s).
207
+
208
+ 3.4. Notices
209
+
210
+ You may not remove or alter the substance of any license notices
211
+ (including copyright notices, patent notices, disclaimers of warranty,
212
+ or limitations of liability) contained within the Source Code Form of
213
+ the Covered Software, except that You may alter any license notices to
214
+ the extent required to remedy known factual inaccuracies.
215
+
216
+ 3.5. Application of Additional Terms
217
+
218
+ You may choose to offer, and to charge a fee for, warranty, support,
219
+ indemnity or liability obligations to one or more recipients of Covered
220
+ Software. However, You may do so only on Your own behalf, and not on
221
+ behalf of any Contributor. You must make it absolutely clear that any
222
+ such warranty, support, indemnity, or liability obligation is offered by
223
+ You alone, and You hereby agree to indemnify every Contributor for any
224
+ liability incurred by such Contributor as a result of warranty, support,
225
+ indemnity or liability terms You offer. You may include additional
226
+ disclaimers of warranty and limitations of liability specific to any
227
+ jurisdiction.
228
+
229
+ 4. Inability to Comply Due to Statute or Regulation
230
+
231
+ ---
232
+
233
+ If it is impossible for You to comply with any of the terms of this
234
+ License with respect to some or all of the Covered Software due to
235
+ statute, judicial order, or regulation then You must: (a) comply with
236
+ the terms of this License to the maximum extent possible; and (b)
237
+ describe the limitations and the code they affect. Such description must
238
+ be placed in a text file included with all distributions of the Covered
239
+ Software under this License. Except to the extent prohibited by statute
240
+ or regulation, such description must be sufficiently detailed for a
241
+ recipient of ordinary skill to be able to understand it.
242
+
243
+ 5. Termination
244
+
245
+ ---
246
+
247
+ 5.1. The rights granted under this License will terminate automatically
248
+ if You fail to comply with any of its terms. However, if You become
249
+ compliant, then the rights granted under this License from a particular
250
+ Contributor are reinstated (a) provisionally, unless and until such
251
+ Contributor explicitly and finally terminates Your grants, and (b) on an
252
+ ongoing basis, if such Contributor fails to notify You of the
253
+ non-compliance by some reasonable means prior to 60 days after You have
254
+ come back into compliance. Moreover, Your grants from a particular
255
+ Contributor are reinstated on an ongoing basis if such Contributor
256
+ notifies You of the non-compliance by some reasonable means, this is the
257
+ first time You have received notice of non-compliance with this License
258
+ from such Contributor, and You become compliant prior to 30 days after
259
+ Your receipt of the notice.
260
+
261
+ 5.2. If You initiate litigation against any entity by asserting a patent
262
+ infringement claim (excluding declaratory judgment actions,
263
+ counter-claims, and cross-claims) alleging that a Contributor Version
264
+ directly or indirectly infringes any patent, then the rights granted to
265
+ You by any and all Contributors for the Covered Software under Section
266
+ 2.1 of this License shall terminate.
267
+
268
+ 5.3. In the event of termination under Sections 5.1 or 5.2 above, all
269
+ end user license agreements (excluding distributors and resellers) which
270
+ have been validly granted by You or Your distributors under this License
271
+ prior to termination shall survive termination.
272
+
273
+ ---
274
+
275
+ - *
276
+ - 6. Disclaimer of Warranty \*
277
+ - ------------------------- \*
278
+ - *
279
+ - Covered Software is provided under this License on an "as is" \*
280
+ - basis, without warranty of any kind, either expressed, implied, or \*
281
+ - statutory, including, without limitation, warranties that the \*
282
+ - Covered Software is free of defects, merchantable, fit for a \*
283
+ - particular purpose or non-infringing. The entire risk as to the \*
284
+ - quality and performance of the Covered Software is with You. \*
285
+ - Should any Covered Software prove defective in any respect, You \*
286
+ - (not any Contributor) assume the cost of any necessary servicing, \*
287
+ - repair, or correction. This disclaimer of warranty constitutes an \*
288
+ - essential part of this License. No use of any Covered Software is \*
289
+ - authorized under this License except under this disclaimer. \*
290
+ - *
291
+
292
+ ---
293
+
294
+ ---
295
+
296
+ - *
297
+ - 7. Limitation of Liability \*
298
+ - -------------------------- \*
299
+ - *
300
+ - Under no circumstances and under no legal theory, whether tort \*
301
+ - (including negligence), contract, or otherwise, shall any \*
302
+ - Contributor, or anyone who distributes Covered Software as \*
303
+ - permitted above, be liable to You for any direct, indirect, \*
304
+ - special, incidental, or consequential damages of any character \*
305
+ - including, without limitation, damages for lost profits, loss of \*
306
+ - goodwill, work stoppage, computer failure or malfunction, or any \*
307
+ - and all other commercial damages or losses, even if such party \*
308
+ - shall have been informed of the possibility of such damages. This \*
309
+ - limitation of liability shall not apply to liability for death or \*
310
+ - personal injury resulting from such party's negligence to the \*
311
+ - extent applicable law prohibits such limitation. Some \*
312
+ - jurisdictions do not allow the exclusion or limitation of \*
313
+ - incidental or consequential damages, so this exclusion and \*
314
+ - limitation may not apply to You. \*
315
+ - *
316
+
317
+ ---
318
+
319
+ 8. Litigation
320
+
321
+ ---
322
+
323
+ Any litigation relating to this License may be brought only in the
324
+ courts of a jurisdiction where the defendant maintains its principal
325
+ place of business and such litigation shall be governed by laws of that
326
+ jurisdiction, without reference to its conflict-of-law provisions.
327
+ Nothing in this Section shall prevent a party's ability to bring
328
+ cross-claims or counter-claims.
329
+
330
+ 9. Miscellaneous
331
+
332
+ ---
333
+
334
+ This License represents the complete agreement concerning the subject
335
+ matter hereof. If any provision of this License is held to be
336
+ unenforceable, such provision shall be reformed only to the extent
337
+ necessary to make it enforceable. Any law or regulation which provides
338
+ that the language of a contract shall be construed against the drafter
339
+ shall not be used to construe this License against a Contributor.
340
+
341
+ 10. Versions of the License
342
+
343
+ ---
344
+
345
+ 10.1. New Versions
346
+
347
+ Mozilla Foundation is the license steward. Except as provided in Section
348
+ 10.3, no one other than the license steward has the right to modify or
349
+ publish new versions of this License. Each version will be given a
350
+ distinguishing version number.
351
+
352
+ 10.2. Effect of New Versions
353
+
354
+ You may distribute the Covered Software under the terms of the version
355
+ of the License under which You originally received the Covered Software,
356
+ or under the terms of any subsequent version published by the license
357
+ steward.
358
+
359
+ 10.3. Modified Versions
360
+
361
+ If you create software not governed by this License, and you want to
362
+ create a new license for such software, you may create and use a
363
+ modified version of this License if you rename the license and remove
364
+ any references to the name of the license steward (except to note that
365
+ such modified license differs from this License).
366
+
367
+ 10.4. Distributing Source Code Form that is Incompatible With Secondary
368
+ Licenses
369
+
370
+ If You choose to distribute Source Code Form that is Incompatible With
371
+ Secondary Licenses under the terms of this version of the License, the
372
+ notice described in Exhibit B of this License must be attached.
373
+
374
+ ## Exhibit A - Source Code Form License Notice
375
+
376
+ This Source Code Form is subject to the terms of the Mozilla Public
377
+ License, v. 2.0. If a copy of the MPL was not distributed with this
378
+ file, You can obtain one at http://mozilla.org/MPL/2.0/.
379
+
380
+ If it is not possible or desirable to put the notice in a particular
381
+ file, then You may include the notice in a location (such as a LICENSE
382
+ file in a relevant directory) where a recipient would be likely to look
383
+ for such a notice.
384
+
385
+ You may add additional accurate notices of copyright ownership.
386
+
387
+ ## Exhibit B - "Incompatible With Secondary Licenses" Notice
388
+
389
+ This Source Code Form is "Incompatible With Secondary Licenses", as
390
+ defined by the Mozilla Public License, v. 2.0.
package/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # Create Baseplate Project
2
+
3
+ The Create Baseplate package provides a straightforward method for initiating a new Baseplate project, automatically generating all necessary files within your project directory. Baseplate is a full-stack application generator, laying the groundwork for scalable and maintainable development.
4
+
5
+ ## Private Beta Notice
6
+
7
+ **Important**: The Baseplate project is currently undergoing a private beta phase and is not yet available to the public. Access is available to authorized beta testers and internal team members. If you're interested in participating in the beta program, please reach out to us at [Half Dome Labs](https://halfdomelabs.com/contact) for more details.
8
+
9
+ ## Creating a Project
10
+
11
+ To start a new Baseplate project, execute the following command in your terminal:
12
+
13
+ ```bash
14
+ pnpm dlx @baseplate-dev/create-project [directory]
15
+ ```
16
+
17
+ This command will set up a new Baseplate project in the specified directory. If no directory name is provided, the project will be established in the current directory. After the project setup is complete, navigate to the project directory to begin development on your new Baseplate application using `pnpm baseplate serve`.
18
+
19
+ ## Development
20
+
21
+ To run the project in development mode, execute the following command in your terminal:
22
+
23
+ ```bash
24
+ pnpm dev:start [directory]
25
+ ```
26
+
27
+ Note: The `directory` argument is optional and will default to the current directory if not provided.
28
+
29
+ You should use a directory outside the Baseplate folder to run the full install process otherwise it will create the directory within the create-project directory, e.g.
30
+
31
+ ```bash
32
+ pnpm dev:start ~/projects/test-app
33
+ ```
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env node
2
+ import chalk from 'chalk';
3
+ import { program } from 'commander';
4
+ import fs from 'node:fs/promises';
5
+ import path from 'node:path';
6
+ import { getNpmTokenAndVersion } from './npm.service.js';
7
+ import { generateBaseplateProject } from './project-creator.js';
8
+ import { getPackageVersion } from './version.js';
9
+ // check if directory contains a package.json file
10
+ async function checkForPackageJson(directory) {
11
+ try {
12
+ const packageJsonPath = path.join(directory, 'package.json');
13
+ await fs.access(packageJsonPath);
14
+ return true;
15
+ }
16
+ catch {
17
+ return false;
18
+ }
19
+ }
20
+ async function runMain() {
21
+ const version = await getPackageVersion();
22
+ if (!version) {
23
+ throw new Error('Could not determine package version');
24
+ }
25
+ program
26
+ .description('Create a new Baseplate project')
27
+ .version(version)
28
+ .argument('[directory]', 'The directory to initialize the project in', '.');
29
+ program.parse(process.argv);
30
+ const directory = program.processedArgs[0];
31
+ const resolvedDirectory = path.resolve(directory);
32
+ const packageName = path
33
+ .basename(resolvedDirectory)
34
+ .toLowerCase()
35
+ .replaceAll(/[^a-z0-9]+/g, '-');
36
+ if (packageName === '-' || !packageName) {
37
+ throw new Error('Directory must have at least one Latin alphanumeric character.');
38
+ }
39
+ const relativeDirectory = path.relative(process.cwd(), resolvedDirectory);
40
+ console.info(`Creating a new Baseplate project (${packageName})...`);
41
+ console.info(`Directory: ${relativeDirectory || '.'}`);
42
+ console.info();
43
+ const hasPackageJson = await checkForPackageJson(resolvedDirectory);
44
+ if (hasPackageJson) {
45
+ throw new Error(`The directory ${directory} already contains a package.json file.`);
46
+ }
47
+ console.info(chalk.yellow('Please enter your NPM token for Baseplate. While Baseplate is in private beta, an NPM token is required to access the Baseplate package. This will be stored in the .env file in your project directory.\n'));
48
+ const { npmToken, cliVersion } = await getNpmTokenAndVersion();
49
+ await generateBaseplateProject({
50
+ packageName,
51
+ directory: resolvedDirectory,
52
+ npmToken,
53
+ cliVersion,
54
+ });
55
+ }
56
+ await runMain().catch((err) => {
57
+ if (err instanceof Error && err.name === 'ExitPromptError') {
58
+ return;
59
+ }
60
+ console.error(chalk.red(`An error occurred while creating the project:\n\n${err instanceof Error ? err.message : String(err)}\n`));
61
+ process.exit(1);
62
+ });
@@ -0,0 +1,4 @@
1
+ export declare function getNpmTokenAndVersion(): Promise<{
2
+ npmToken: string;
3
+ cliVersion: string;
4
+ }>;
@@ -0,0 +1,66 @@
1
+ import { input } from '@inquirer/prompts';
2
+ import axios, { AxiosError } from 'axios';
3
+ import ora from 'ora';
4
+ class InvalidTokenError extends Error {
5
+ constructor() {
6
+ super('API token appears invalid');
7
+ }
8
+ }
9
+ async function fetchNpmPackageVersion(token) {
10
+ const spinner = ora({
11
+ text: 'Checking for the latest version of Baseplate CLI...',
12
+ }).start();
13
+ try {
14
+ const url = `https://registry.npmjs.org/@baseplate-dev/project-builder-cli`;
15
+ const headers = {
16
+ Authorization: `Bearer ${token}`,
17
+ };
18
+ const response = await axios.get(url, { headers });
19
+ if (!response.data.name) {
20
+ throw new Error('Invalid response from NPM registry');
21
+ }
22
+ spinner.succeed();
23
+ return response.data['dist-tags'].latest;
24
+ }
25
+ catch (err) {
26
+ if (err instanceof AxiosError && err.response?.status === 404) {
27
+ spinner.fail('Your NPM token appears invalid. Please try again with a valid token.\n');
28
+ throw new InvalidTokenError();
29
+ }
30
+ }
31
+ finally {
32
+ if (spinner.isSpinning) {
33
+ spinner.fail();
34
+ }
35
+ }
36
+ }
37
+ export async function getNpmTokenAndVersion() {
38
+ const NPM_TOKEN_REGEX = /^npm_[\w-]{10,100}$/;
39
+ let latestVersion;
40
+ let npmToken;
41
+ while (true) {
42
+ npmToken = await input({
43
+ message: 'NPM Token',
44
+ validate: (input) => {
45
+ if (!NPM_TOKEN_REGEX.test(input)) {
46
+ return 'Please enter a valid NPM token';
47
+ }
48
+ return true;
49
+ },
50
+ });
51
+ try {
52
+ console.info('');
53
+ latestVersion = await fetchNpmPackageVersion(npmToken);
54
+ break;
55
+ }
56
+ catch (error) {
57
+ if (!(error instanceof InvalidTokenError)) {
58
+ throw error;
59
+ }
60
+ }
61
+ }
62
+ if (!latestVersion) {
63
+ throw new Error('Could not determine the latest version of Baseplate CLI');
64
+ }
65
+ return { npmToken, cliVersion: latestVersion };
66
+ }
@@ -0,0 +1,6 @@
1
+ export declare function generateBaseplateProject({ packageName, directory, npmToken, cliVersion, }: {
2
+ packageName: string;
3
+ directory: string;
4
+ npmToken: string;
5
+ cliVersion: string;
6
+ }): Promise<void>;
@@ -0,0 +1,80 @@
1
+ import chalk from 'chalk';
2
+ import { execa } from 'execa';
3
+ import fs from 'node:fs/promises';
4
+ import path from 'node:path';
5
+ import ora from 'ora';
6
+ export async function generateBaseplateProject({ packageName, directory, npmToken, cliVersion, }) {
7
+ let spinner = ora({
8
+ text: 'Creating project files...',
9
+ }).start();
10
+ try {
11
+ await fs.mkdir(directory, {
12
+ recursive: true,
13
+ });
14
+ const writeFile = async (destination, content) => {
15
+ const destinationPath = path.join(directory, destination);
16
+ await fs.mkdir(path.dirname(destinationPath), {
17
+ recursive: true,
18
+ });
19
+ await fs.writeFile(destinationPath, content);
20
+ };
21
+ const copyFile = async (templateSrc, destination) => {
22
+ // template files are stored at ../templates
23
+ const source = new URL(`../templates/${templateSrc}`, import.meta.url);
24
+ const sourceFile = await fs.readFile(source);
25
+ await writeFile(destination, sourceFile);
26
+ };
27
+ // write package.json
28
+ await writeFile('package.json', JSON.stringify({
29
+ name: packageName,
30
+ version: '0.1.0',
31
+ private: true,
32
+ description: 'A Baseplate project',
33
+ license: 'UNLICENSED',
34
+ author: '<AUTHOR>',
35
+ scripts: {
36
+ 'baseplate:serve': 'baseplate serve',
37
+ 'baseplate:generate': 'baseplate generate',
38
+ preinstall: 'npx only-allow pnpm',
39
+ },
40
+ devDependencies: {
41
+ '@baseplate-dev/project-builder-cli': cliVersion,
42
+ },
43
+ packageManager: 'pnpm@10.6.5',
44
+ engines: {
45
+ node: '^22.0.0',
46
+ pnpm: '^10.6.0',
47
+ },
48
+ volta: {
49
+ node: '22.14.0',
50
+ },
51
+ }, null, 2));
52
+ await copyFile('.gitignore', '.gitignore');
53
+ await copyFile('.pnpmfile.cjs', '.pnpmfile.cjs');
54
+ await copyFile('.template.npmrc', '.template.npmrc');
55
+ await copyFile('scripts/setup-npmrc.cjs', 'scripts/setup-npmrc.cjs');
56
+ await copyFile('README.md', 'README.md');
57
+ await writeFile('.env', `NPM_TOKEN=${npmToken}\n`);
58
+ spinner.succeed();
59
+ spinner = ora({
60
+ text: 'Installing dependencies...',
61
+ }).start();
62
+ await execa({ cwd: directory }) `node .pnpmfile.cjs --silent`;
63
+ await execa({ cwd: directory }) `pnpm install`;
64
+ spinner.succeed();
65
+ const relativePath = path.relative(process.cwd(), directory);
66
+ console.info('');
67
+ console.info(`
68
+ 🎉 Congratulations! Your Baseplate project has been created. To get started, run the following command${relativePath === '' ? '' : 's'}:
69
+ ${relativePath === '' ? '' : chalk.bold(`\ncd ${relativePath}`)}
70
+ ${chalk.bold('pnpm baseplate serve')}
71
+
72
+ For more information, read the included README.md file.
73
+ `.trim());
74
+ }
75
+ finally {
76
+ if (spinner.isSpinning) {
77
+ spinner.fail();
78
+ }
79
+ }
80
+ }
@@ -0,0 +1 @@
1
+ export declare function getPackageVersion(): Promise<string | null>;
@@ -0,0 +1,23 @@
1
+ import { findNearestPackageJson } from '@baseplate-dev/utils/node';
2
+ import { promises as fs } from 'node:fs';
3
+ import { fileURLToPath } from 'node:url';
4
+ let cachedVersion;
5
+ export async function getPackageVersion() {
6
+ if (cachedVersion === undefined) {
7
+ // Construct the path to the package.json file.
8
+ const packageJsonPath = await findNearestPackageJson({
9
+ cwd: fileURLToPath(import.meta.url),
10
+ });
11
+ if (packageJsonPath) {
12
+ // Read the package.json file.
13
+ const fileContent = await fs.readFile(packageJsonPath, 'utf8');
14
+ const packageJson = JSON.parse(fileContent);
15
+ // Return the version.
16
+ cachedVersion = packageJson.version || null;
17
+ }
18
+ else {
19
+ cachedVersion = null;
20
+ }
21
+ }
22
+ return cachedVersion;
23
+ }
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@baseplate-dev/create-project",
3
+ "version": "0.1.1",
4
+ "description": "CLI starter kit for creating a new Baseplate project",
5
+ "repository": "https://github.com/halfdomelabs/baseplate",
6
+ "license": "SEE LICENSE IN LICENSE",
7
+ "author": "Half Dome Labs LLC",
8
+ "type": "module",
9
+ "imports": {
10
+ "#src/*": {
11
+ "development": "./src/*",
12
+ "default": "./dist/*"
13
+ }
14
+ },
15
+ "bin": "./dist/create-baseplate-project.js",
16
+ "files": [
17
+ "LICENSE",
18
+ "CHANGELOG",
19
+ "dist/**/*",
20
+ "scripts/**/*",
21
+ "templates/**/*",
22
+ "!dist/**/*.tsbuildinfo",
23
+ "README.md"
24
+ ],
25
+ "dependencies": {
26
+ "@inquirer/prompts": "7.2.1",
27
+ "axios": "^1.8.3",
28
+ "chalk": "5.3.0",
29
+ "commander": "^12.1.0",
30
+ "execa": "9.3.0",
31
+ "ora": "^8.0.1",
32
+ "@baseplate-dev/utils": "0.1.1"
33
+ },
34
+ "devDependencies": {
35
+ "@types/node": "^22.0.0",
36
+ "eslint": "9.26.0",
37
+ "prettier": "3.5.3",
38
+ "tsx": "4.19.3",
39
+ "typescript": "5.7.3",
40
+ "@baseplate-dev/tools": "0.1.1"
41
+ },
42
+ "engines": {
43
+ "node": "^22.0.0"
44
+ },
45
+ "volta": {
46
+ "extends": "../../package.json"
47
+ },
48
+ "publishConfig": {
49
+ "access": "public",
50
+ "provenance": true
51
+ },
52
+ "scripts": {
53
+ "build": "tsc -p tsconfig.build.json",
54
+ "clean": "rm -rf ./dist",
55
+ "dev:start": "tsx -C development ./src/create-baseplate-project.ts",
56
+ "lint": "eslint .",
57
+ "prettier:check": "prettier --check .",
58
+ "prettier:write": "prettier -w .",
59
+ "start": "node ./dist/create-baseplate-project.js",
60
+ "typecheck": "tsc --noEmit"
61
+ }
62
+ }
@@ -0,0 +1,141 @@
1
+ # Logs
2
+ logs
3
+ *.log
4
+ npm-debug.log*
5
+ yarn-debug.log*
6
+ yarn-error.log*
7
+ lerna-debug.log*
8
+ .pnpm-debug.log*
9
+
10
+ # Diagnostic reports (https://nodejs.org/api/report.html)
11
+ report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
12
+
13
+ # Runtime data
14
+ pids
15
+ *.pid
16
+ *.seed
17
+ *.pid.lock
18
+
19
+ # Directory for instrumented libs generated by jscoverage/JSCover
20
+ lib-cov
21
+
22
+ # Coverage directory used by tools like istanbul
23
+ coverage
24
+ *.lcov
25
+
26
+ # nyc test coverage
27
+ .nyc_output
28
+
29
+ # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
30
+ .grunt
31
+
32
+ # Bower dependency directory (https://bower.io/)
33
+ bower_components
34
+
35
+ # node-waf configuration
36
+ .lock-wscript
37
+
38
+ # Compiled binary addons (https://nodejs.org/api/addons.html)
39
+ build/Release
40
+
41
+ # Dependency directories
42
+ node_modules/
43
+ jspm_packages/
44
+
45
+ # Snowpack dependency directory (https://snowpack.dev/)
46
+ web_modules/
47
+
48
+ # TypeScript cache
49
+ *.tsbuildinfo
50
+
51
+ # Optional npm cache directory
52
+ .npm
53
+
54
+ # Optional eslint cache
55
+ .eslintcache
56
+
57
+ # Optional stylelint cache
58
+ .stylelintcache
59
+
60
+ # Microbundle cache
61
+ .rpt2_cache/
62
+ .rts2_cache_cjs/
63
+ .rts2_cache_es/
64
+ .rts2_cache_umd/
65
+
66
+ # Optional REPL history
67
+ .node_repl_history
68
+
69
+ # Output of 'npm pack'
70
+ *.tgz
71
+
72
+ # Yarn Integrity file
73
+ .yarn-integrity
74
+
75
+ # dotenv environment variable files
76
+ .env
77
+ .env.development.local
78
+ .env.test.local
79
+ .env.production.local
80
+ .env.local
81
+
82
+ # parcel-bundler cache (https://parceljs.org/)
83
+ .cache
84
+ .parcel-cache
85
+
86
+ # Next.js build output
87
+ .next
88
+ out
89
+
90
+ # Nuxt.js build / generate output
91
+ .nuxt
92
+ dist
93
+
94
+ # Gatsby files
95
+ .cache/
96
+ # Comment in the public line in if your project uses Gatsby and not Next.js
97
+ # https://nextjs.org/blog/next-9-1#public-directory-support
98
+ # public
99
+
100
+ # vuepress build output
101
+ .vuepress/dist
102
+
103
+ # vuepress v2.x temp and cache directory
104
+ .temp
105
+ .cache
106
+
107
+ # Docusaurus cache and generated files
108
+ .docusaurus
109
+
110
+ # Serverless directories
111
+ .serverless/
112
+
113
+ # FuseBox cache
114
+ .fusebox/
115
+
116
+ # DynamoDB Local files
117
+ .dynamodb/
118
+
119
+ # TernJS port file
120
+ .tern-port
121
+
122
+ # Stores VSCode versions used for testing VSCode extensions
123
+ .vscode-test
124
+
125
+ # yarn v2
126
+ .yarn/cache
127
+ .yarn/unplugged
128
+ .yarn/build-state.yml
129
+ .yarn/install-state.gz
130
+ .pnp.*
131
+
132
+ playground
133
+
134
+ .DS_Store
135
+ .vercel
136
+
137
+ .npmrc
138
+ .turbo
139
+
140
+ # Baseplate build artifacts
141
+ baseplate/.build
@@ -0,0 +1,2 @@
1
+ // sets up .npmrc file for pnpm
2
+ require('./scripts/setup-npmrc.cjs')(__dirname);
@@ -0,0 +1,10 @@
1
+ //registry.npmjs.org/:_authToken=${NPM_TOKEN}
2
+
3
+ # Prevents publish from any branch other than main
4
+ publish-branch=main
5
+ # Saves exact versions of dependencies by default
6
+ save-prefix=""
7
+ # Ensures we use locally linked packages when available
8
+ link-workspace-packages=true
9
+ # Defaults to saving as workspace:*
10
+ save-workspace-protocol=rolling
@@ -0,0 +1,48 @@
1
+ # Baseplate Project
2
+
3
+ Welcome to your new Baseplate project! This README provides essential information on how to get started with your project, including setting up the generator UI and beginning your development process.
4
+
5
+ ## Getting Started
6
+
7
+ To begin using the project, you will need to set up your local environment. Follow these instructions to get everything up and running.
8
+
9
+ ### Prerequisites
10
+
11
+ Before you start, ensure you have `pnpm` installed on your system. If you do not have `pnpm` installed, you can learn how to install it by visiting [pnpm installation guide](https://pnpm.io/installation).
12
+
13
+ ### Environment Setup
14
+
15
+ For this project, you will need to set up environment variables that the application requires to function properly. One essential variable is `NPM_TOKEN`, which is used for accessing private npm packages. If you set this project up with the project creator, you should have already been asked for this token. Otherwise, to set this up:
16
+
17
+ 1. Create a `.env` file in the root directory of your project.
18
+ 2. Add the following line to the `.env` file:
19
+
20
+ ```bash
21
+ NPM_TOKEN=<your-npm-token>
22
+ ```
23
+
24
+ You can obtain the NPM token from your engineering manager.
25
+
26
+ ### Installation
27
+
28
+ To install the necessary dependencies for your project, run the following command in the root directory of your project:
29
+
30
+ ```bash
31
+ pnpm install
32
+ ```
33
+
34
+ ### Launching the Generator UI
35
+
36
+ To start the generator UI, which allows you to configure and initiate the code generation process, execute the following command:
37
+
38
+ ```bash
39
+ pnpm baseplate serve
40
+ ```
41
+
42
+ This command will start the server and open the corresponding web interface where you can customize your project’s specifications and features and generate the code.
43
+
44
+ ## Configuration
45
+
46
+ To configure your project settings, use the web interface launched by the above command. Here you can specify data models, authentication mechanisms, and other project-specific settings.
47
+
48
+ Thank you for choosing Baseplate for your project’s foundation!
@@ -0,0 +1,74 @@
1
+ /*
2
+ * Generates .npmrc from a .npmrc.template file using a .env file if present
3
+ *
4
+ * This allows us to use .env files to store secrets and use them in .npmrc
5
+ * since it is not natively supported by pnpm.
6
+ */
7
+ const fs = require('node:fs');
8
+ const path = require('node:path');
9
+
10
+ module.exports = function generateNpmRc(dirname) {
11
+ const templatePath = path.join(dirname, '.template.npmrc');
12
+ const npmrcPath = path.join(dirname, '.npmrc');
13
+ const envPath = path.join(dirname, '.env');
14
+
15
+ if (!fs.existsSync(templatePath)) {
16
+ return;
17
+ }
18
+
19
+ // read .env file if present
20
+ const envVars = { ...process.env };
21
+ if (fs.existsSync(envPath)) {
22
+ const env = fs.readFileSync(envPath, 'utf8');
23
+ const lines = env
24
+ .split('\n')
25
+ .filter((line) => line && !line.startsWith('#'));
26
+ for (const line of lines) {
27
+ const [key, ...values] = line.split('=');
28
+ if (values.length > 0) {
29
+ envVars[key] = values.join('=');
30
+ }
31
+ }
32
+ }
33
+
34
+ const template = fs.readFileSync(templatePath, 'utf8');
35
+
36
+ // replace all ${VARIABLE} with process.env.VARIABLE
37
+ const npmrc = template
38
+ .replaceAll(/\${([A-Z_]+)}/g, (_, key) => {
39
+ if (!envVars[key]) {
40
+ throw new Error(`Missing environment variable ${key}`);
41
+ }
42
+ return envVars[key];
43
+ })
44
+ .replaceAll(/\${([A-Z_:a-z\-]+)}/g, (_, key) =>
45
+ envVars[key] ? envVars[key] : key,
46
+ );
47
+
48
+ const npmrcContents = `
49
+ # This file has been auto-generated from .npmrc.template
50
+ # Do not edit this file directly
51
+ # Edit .npmrc.template instead and run \`pnpm install\` to regenerate this file
52
+
53
+ ${npmrc}`.trimStart();
54
+
55
+ if (fs.existsSync(npmrcPath)) {
56
+ const existingNpmrc = fs.readFileSync(npmrcPath, 'utf8');
57
+
58
+ if (existingNpmrc === npmrcContents) {
59
+ return;
60
+ }
61
+ }
62
+
63
+ fs.writeFileSync(npmrcPath, npmrcContents);
64
+
65
+ if (!process.argv.includes('--silent')) {
66
+ console.log(`
67
+ Generated .npmrc file from .template.npmrc!
68
+
69
+ Please run your command again so it can use the latest .npmrc.
70
+ `);
71
+
72
+ process.exit(1);
73
+ }
74
+ };