@baseplate-dev/create-project 0.3.3 → 0.3.4
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.
|
@@ -3,9 +3,8 @@ import chalk from 'chalk';
|
|
|
3
3
|
import { program } from 'commander';
|
|
4
4
|
import fs from 'node:fs/promises';
|
|
5
5
|
import path from 'node:path';
|
|
6
|
-
import { getLatestCliVersion } from './npm.service.js';
|
|
7
6
|
import { generateBaseplateProject } from './project-creator.js';
|
|
8
|
-
import { getPackageVersion } from './version.js';
|
|
7
|
+
import { getCliVersion, getPackageVersion } from './version.js';
|
|
9
8
|
// check if directory contains a package.json file
|
|
10
9
|
async function checkForPackageJson(directory) {
|
|
11
10
|
try {
|
|
@@ -44,7 +43,7 @@ async function runMain() {
|
|
|
44
43
|
if (hasPackageJson) {
|
|
45
44
|
throw new Error(`The directory ${directory} already contains a package.json file.`);
|
|
46
45
|
}
|
|
47
|
-
const cliVersion = await
|
|
46
|
+
const cliVersion = await getCliVersion();
|
|
48
47
|
await generateBaseplateProject({
|
|
49
48
|
packageName,
|
|
50
49
|
directory: resolvedDirectory,
|
package/dist/project-creator.js
CHANGED
|
@@ -40,13 +40,13 @@ export async function generateBaseplateProject({ packageName, directory, cliVers
|
|
|
40
40
|
devDependencies: {
|
|
41
41
|
'@baseplate-dev/project-builder-cli': cliVersion,
|
|
42
42
|
},
|
|
43
|
-
packageManager: 'pnpm@10.
|
|
43
|
+
packageManager: 'pnpm@10.15.0',
|
|
44
44
|
engines: {
|
|
45
45
|
node: '^22.0.0',
|
|
46
|
-
pnpm: '^10.
|
|
46
|
+
pnpm: '^10.15.0',
|
|
47
47
|
},
|
|
48
48
|
volta: {
|
|
49
|
-
node: '22.
|
|
49
|
+
node: '22.18.0',
|
|
50
50
|
},
|
|
51
51
|
}, null, 2));
|
|
52
52
|
await copyFile('.gitignore', '.gitignore');
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { findNearestPackageJson } from '@baseplate-dev/utils/node';
|
|
2
2
|
import { promises as fs } from 'node:fs';
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
3
4
|
import { fileURLToPath } from 'node:url';
|
|
4
5
|
let cachedVersion;
|
|
5
6
|
export async function getPackageVersion() {
|
|
@@ -21,3 +22,25 @@ export async function getPackageVersion() {
|
|
|
21
22
|
}
|
|
22
23
|
return cachedVersion;
|
|
23
24
|
}
|
|
25
|
+
let cachedCliVersion;
|
|
26
|
+
export async function getCliVersion() {
|
|
27
|
+
if (cachedCliVersion === undefined) {
|
|
28
|
+
// Use require.resolve to find the package.json for project-builder-cli
|
|
29
|
+
const require = createRequire(import.meta.url);
|
|
30
|
+
const cliPackagePath = require.resolve('@baseplate-dev/project-builder-cli');
|
|
31
|
+
const packageJsonPath = await findNearestPackageJson({
|
|
32
|
+
cwd: cliPackagePath,
|
|
33
|
+
});
|
|
34
|
+
if (!packageJsonPath) {
|
|
35
|
+
throw new Error(`Could not find package.json for @baseplate-dev/project-builder-cli in ${cliPackagePath}`);
|
|
36
|
+
}
|
|
37
|
+
// Read the package.json file
|
|
38
|
+
const fileContent = await fs.readFile(packageJsonPath, 'utf8');
|
|
39
|
+
const packageJson = JSON.parse(fileContent);
|
|
40
|
+
if (!packageJson.version) {
|
|
41
|
+
throw new Error(`Unable to find version in package.json for @baseplate-dev/project-builder-cli in ${packageJsonPath}`);
|
|
42
|
+
}
|
|
43
|
+
cachedCliVersion = packageJson.version;
|
|
44
|
+
}
|
|
45
|
+
return cachedCliVersion;
|
|
46
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@baseplate-dev/create-project",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"description": "CLI starter kit for creating a new Baseplate project",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -35,22 +35,22 @@
|
|
|
35
35
|
"bin/**/*"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"axios": "^1.8.3",
|
|
39
38
|
"chalk": "5.3.0",
|
|
40
39
|
"commander": "^12.1.0",
|
|
41
40
|
"execa": "9.3.0",
|
|
42
41
|
"ora": "^8.0.1",
|
|
43
|
-
"@baseplate-dev/
|
|
42
|
+
"@baseplate-dev/project-builder-cli": "0.3.4",
|
|
43
|
+
"@baseplate-dev/utils": "0.3.4"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@types/node": "^22.
|
|
46
|
+
"@types/node": "^22.17.2",
|
|
47
47
|
"eslint": "9.32.0",
|
|
48
48
|
"memfs": "4.15.1",
|
|
49
49
|
"prettier": "3.6.2",
|
|
50
50
|
"tsx": "4.19.3",
|
|
51
|
-
"typescript": "5.
|
|
51
|
+
"typescript": "5.8.3",
|
|
52
52
|
"vitest": "3.2.4",
|
|
53
|
-
"@baseplate-dev/tools": "0.3.
|
|
53
|
+
"@baseplate-dev/tools": "0.3.4"
|
|
54
54
|
},
|
|
55
55
|
"engines": {
|
|
56
56
|
"node": "^22.0.0"
|
package/dist/npm.service.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getLatestCliVersion(): Promise<string>;
|
package/dist/npm.service.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import ora from 'ora';
|
|
3
|
-
export async function getLatestCliVersion() {
|
|
4
|
-
const spinner = ora({
|
|
5
|
-
text: 'Checking for the latest version of Baseplate CLI...',
|
|
6
|
-
}).start();
|
|
7
|
-
try {
|
|
8
|
-
const url = `https://registry.npmjs.org/@baseplate-dev/project-builder-cli`;
|
|
9
|
-
const response = await axios.get(url);
|
|
10
|
-
if (!response.data.name) {
|
|
11
|
-
throw new Error('Invalid response from NPM registry');
|
|
12
|
-
}
|
|
13
|
-
spinner.succeed();
|
|
14
|
-
return response.data['dist-tags'].latest;
|
|
15
|
-
}
|
|
16
|
-
catch {
|
|
17
|
-
spinner.fail('Failed to fetch the latest CLI version');
|
|
18
|
-
throw new Error('Could not determine the latest version of Baseplate CLI');
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
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
|
-
};
|