create-harper 1.12.8 → 1.12.9

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.
@@ -1,12 +1,38 @@
1
+ import dotenv from 'dotenv';
1
2
  import fs from 'node:fs';
2
3
  import colors from 'picocolors';
3
- import { writeFile } from './writeFile.js';
4
+ import { defaultTarget } from '../constants/defaultEnv.js';
5
+ import { applySubstitutions, writeFile } from './writeFile.js';
4
6
 
5
7
  const {
6
8
  gray,
7
9
  green,
8
10
  } = colors;
9
11
 
12
+ const TARGET_KEYS = ['HARPER_CLI_TARGET', 'CLI_TARGET'];
13
+ const DEFAULT_TARGETS = new Set([defaultTarget, 'your-fabric.harper.fast-cluster-url-here']);
14
+ const TARGET_ASSIGNMENT = /^[ \t]*(?:export[ \t]+)?(?:HARPER_CLI_TARGET|CLI_TARGET)[ \t]*=/;
15
+
16
+ /**
17
+ * @param {string} existingEnv - The existing `.env` content.
18
+ * @param {string} templateEnv - The template's `.env` content, after substitution.
19
+ * @returns {string} The template content to append. The last assignment wins, so a default
20
+ * target appended after a configured one would replace it.
21
+ */
22
+ function harperEnvToAppend(existingEnv, templateEnv) {
23
+ const existing = dotenv.parse(existingEnv);
24
+ const template = dotenv.parse(templateEnv);
25
+ const keepsConfiguredTarget = TARGET_KEYS.some((key) => existing[key])
26
+ && TARGET_KEYS.some((key) => DEFAULT_TARGETS.has(template[key]));
27
+ if (!keepsConfiguredTarget) {
28
+ return templateEnv;
29
+ }
30
+ return templateEnv
31
+ .split('\n')
32
+ .filter((line) => !TARGET_ASSIGNMENT.test(line))
33
+ .join('\n');
34
+ }
35
+
10
36
  /**
11
37
  * Reads a template file, applies string substitutions, and writes the result to a target path.
12
38
  *
@@ -15,15 +41,16 @@ const {
15
41
  * @param {Record<string, string> | ((content: string, targetPath: string) => string)} [substitutions] - A mapping of strings to replace or a function that returns the updated content.
16
42
  */
17
43
  export function copyFile(sourcePath, targetPath, substitutions) {
18
- let updatedContent = fs.readFileSync(sourcePath, 'utf-8');
44
+ let updatedContent = applySubstitutions(fs.readFileSync(sourcePath, 'utf-8'), targetPath, substitutions);
19
45
  if (targetPath.endsWith('.env') && fs.existsSync(targetPath)) {
46
+ const existingContent = fs.readFileSync(targetPath, 'utf-8');
20
47
  updatedContent = `# Your .env file contents:
21
- ${fs.readFileSync(targetPath, 'utf-8')}
48
+ ${existingContent}
22
49
 
23
50
  # Harper .env contents:
24
- ${updatedContent}`;
51
+ ${harperEnvToAppend(existingContent, updatedContent)}`;
25
52
  }
26
- writeFile(targetPath, updatedContent, substitutions);
53
+ writeFile(targetPath, updatedContent);
27
54
 
28
55
  console.log(' + ' + green(targetPath) + gray(' from ' + sourcePath));
29
56
  }
@@ -1,13 +1,14 @@
1
1
  import fs from 'node:fs';
2
2
 
3
3
  /**
4
- * Applies string substitutions and writes the result to a target path.
4
+ * Applies string substitutions to content.
5
5
  *
6
- * @param {string} targetPath - The path where the processed file will be written.
7
- * @param {string} content - The raw content to write, before optional substitutions.
6
+ * @param {string} content - The raw content, before substitutions.
7
+ * @param {string} targetPath - The path the content is written to, passed to a substitution function.
8
8
  * @param {Record<string, string> | ((content: string, targetPath: string) => string)} [substitutions] - A mapping of strings to replace or a function that returns the updated content.
9
+ * @returns {string} The content with substitutions applied.
9
10
  */
10
- export function writeFile(targetPath, content, substitutions) {
11
+ export function applySubstitutions(content, targetPath, substitutions) {
11
12
  let updatedContent = content;
12
13
  if (typeof substitutions === 'function') {
13
14
  updatedContent = substitutions(updatedContent, targetPath);
@@ -16,5 +17,16 @@ export function writeFile(targetPath, content, substitutions) {
16
17
  updatedContent = updatedContent.replaceAll(variableName, substitutions[variableName]);
17
18
  }
18
19
  }
19
- fs.writeFileSync(targetPath, updatedContent);
20
+ return updatedContent;
21
+ }
22
+
23
+ /**
24
+ * Applies string substitutions and writes the result to a target path.
25
+ *
26
+ * @param {string} targetPath - The path where the processed file will be written.
27
+ * @param {string} content - The raw content to write, before optional substitutions.
28
+ * @param {Record<string, string> | ((content: string, targetPath: string) => string)} [substitutions] - A mapping of strings to replace or a function that returns the updated content.
29
+ */
30
+ export function writeFile(targetPath, content, substitutions) {
31
+ fs.writeFileSync(targetPath, applySubstitutions(content, targetPath, substitutions));
20
32
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "create-harper",
3
3
  "description": "Scaffold a new Harper project in JavaScript or TypeScript.",
4
- "version": "1.12.8",
4
+ "version": "1.12.9",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "exports": {
@@ -62,6 +62,7 @@
62
62
  "@clack/prompts": "^1.0.0-alpha.9",
63
63
  "@vercel/detect-agent": "^1.0.0",
64
64
  "cross-spawn": "^7.0.6",
65
+ "dotenv": "^16.6.1",
65
66
  "mri": "^1.2.0",
66
67
  "picocolors": "^1.1.1"
67
68
  },
@@ -1 +1 @@
1
- CLI_TARGET='your-fabric.harper.fast-cluster-url-here'
1
+ HARPER_CLI_TARGET='your-fabric.harper.fast-cluster-url-here'
@@ -1 +1 @@
1
- CLI_TARGET='YOUR_FABRIC.HARPER.FAST_CLUSTER_URL_HERE'
1
+ HARPER_CLI_TARGET='YOUR_FABRIC.HARPER.FAST_CLUSTER_URL_HERE'
@@ -1 +1 @@
1
- CLI_TARGET='your-fabric.harper.fast-cluster-url-here'
1
+ HARPER_CLI_TARGET='your-fabric.harper.fast-cluster-url-here'
@@ -1 +1 @@
1
- CLI_TARGET='YOUR_FABRIC.HARPER.FAST_CLUSTER_URL_HERE'
1
+ HARPER_CLI_TARGET='YOUR_FABRIC.HARPER.FAST_CLUSTER_URL_HERE'
@@ -1 +1 @@
1
- CLI_TARGET='your-fabric.harper.fast-cluster-url-here'
1
+ HARPER_CLI_TARGET='your-fabric.harper.fast-cluster-url-here'
@@ -1 +1 @@
1
- CLI_TARGET='YOUR_FABRIC.HARPER.FAST_CLUSTER_URL_HERE'
1
+ HARPER_CLI_TARGET='YOUR_FABRIC.HARPER.FAST_CLUSTER_URL_HERE'
@@ -1 +1 @@
1
- CLI_TARGET='your-fabric.harper.fast-cluster-url-here'
1
+ HARPER_CLI_TARGET='your-fabric.harper.fast-cluster-url-here'
@@ -1 +1 @@
1
- CLI_TARGET='YOUR_FABRIC.HARPER.FAST_CLUSTER_URL_HERE'
1
+ HARPER_CLI_TARGET='YOUR_FABRIC.HARPER.FAST_CLUSTER_URL_HERE'
@@ -1 +1 @@
1
- CLI_TARGET='your-fabric.harper.fast-cluster-url-here'
1
+ HARPER_CLI_TARGET='your-fabric.harper.fast-cluster-url-here'
@@ -1 +1 @@
1
- CLI_TARGET='YOUR_FABRIC.HARPER.FAST_CLUSTER_URL_HERE'
1
+ HARPER_CLI_TARGET='YOUR_FABRIC.HARPER.FAST_CLUSTER_URL_HERE'
@@ -1 +1 @@
1
- CLI_TARGET='your-fabric.harper.fast-cluster-url-here'
1
+ HARPER_CLI_TARGET='your-fabric.harper.fast-cluster-url-here'
@@ -1 +1 @@
1
- CLI_TARGET='YOUR_FABRIC.HARPER.FAST_CLUSTER_URL_HERE'
1
+ HARPER_CLI_TARGET='YOUR_FABRIC.HARPER.FAST_CLUSTER_URL_HERE'
@@ -1 +1 @@
1
- CLI_TARGET='your-fabric.harper.fast-cluster-url-here'
1
+ HARPER_CLI_TARGET='your-fabric.harper.fast-cluster-url-here'
@@ -1 +1 @@
1
- CLI_TARGET='YOUR_FABRIC.HARPER.FAST_CLUSTER_URL_HERE'
1
+ HARPER_CLI_TARGET='YOUR_FABRIC.HARPER.FAST_CLUSTER_URL_HERE'
@@ -1 +1 @@
1
- CLI_TARGET='your-fabric.harper.fast-cluster-url-here'
1
+ HARPER_CLI_TARGET='your-fabric.harper.fast-cluster-url-here'
@@ -1 +1 @@
1
- CLI_TARGET='YOUR_FABRIC.HARPER.FAST_CLUSTER_URL_HERE'
1
+ HARPER_CLI_TARGET='YOUR_FABRIC.HARPER.FAST_CLUSTER_URL_HERE'
package/template-vue/_env CHANGED
@@ -1 +1 @@
1
- CLI_TARGET='your-fabric.harper.fast-cluster-url-here'
1
+ HARPER_CLI_TARGET='your-fabric.harper.fast-cluster-url-here'
@@ -1 +1 @@
1
- CLI_TARGET='YOUR_FABRIC.HARPER.FAST_CLUSTER_URL_HERE'
1
+ HARPER_CLI_TARGET='YOUR_FABRIC.HARPER.FAST_CLUSTER_URL_HERE'
@@ -1 +1 @@
1
- CLI_TARGET='your-fabric.harper.fast-cluster-url-here'
1
+ HARPER_CLI_TARGET='your-fabric.harper.fast-cluster-url-here'
@@ -1 +1 @@
1
- CLI_TARGET='YOUR_FABRIC.HARPER.FAST_CLUSTER_URL_HERE'
1
+ HARPER_CLI_TARGET='YOUR_FABRIC.HARPER.FAST_CLUSTER_URL_HERE'
@@ -1 +1 @@
1
- CLI_TARGET='your-fabric.harper.fast-cluster-url-here'
1
+ HARPER_CLI_TARGET='your-fabric.harper.fast-cluster-url-here'
@@ -1 +1 @@
1
- CLI_TARGET='YOUR_FABRIC.HARPER.FAST_CLUSTER_URL_HERE'
1
+ HARPER_CLI_TARGET='YOUR_FABRIC.HARPER.FAST_CLUSTER_URL_HERE'
@@ -1 +1 @@
1
- CLI_TARGET='your-fabric.harper.fast-cluster-url-here'
1
+ HARPER_CLI_TARGET='your-fabric.harper.fast-cluster-url-here'
@@ -1 +1 @@
1
- CLI_TARGET='YOUR_FABRIC.HARPER.FAST_CLUSTER_URL_HERE'
1
+ HARPER_CLI_TARGET='YOUR_FABRIC.HARPER.FAST_CLUSTER_URL_HERE'