create-harper 0.0.5 → 0.0.6

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/index.js CHANGED
@@ -4,6 +4,7 @@ import mri from 'mri';
4
4
  import { helpMessage } from './lib/constants/helpMessage.js';
5
5
  import { formatTargetDir } from './lib/fs/formatTargetDir.js';
6
6
  import { pkgFromUserAgent } from './lib/pkg/pkgFromUserAgent.js';
7
+ import { checkForUpdate } from './lib/steps/checkForUpdate.js';
7
8
  import { getEnvVars } from './lib/steps/getEnvVars.js';
8
9
  import { getExamples } from './lib/steps/getExamples.js';
9
10
  import { getImmediate } from './lib/steps/getImmediate.js';
@@ -38,6 +39,13 @@ async function init() {
38
39
  return;
39
40
  }
40
41
 
42
+ const currentVersion = await checkForUpdate();
43
+ const version = argv.version;
44
+ if (version) {
45
+ console.log(`Current version: ${currentVersion}`);
46
+ return;
47
+ }
48
+
41
49
  const interactive = argInteractive ?? process.stdin.isTTY;
42
50
 
43
51
  // Detect AI agent environment for better agent experience (AX)
@@ -16,6 +16,7 @@ Options:
16
16
  -t, --template NAME use a specific template
17
17
  -i, --immediate install dependencies and start dev
18
18
  --interactive / --no-interactive force interactive / non-interactive mode
19
+ --version print out the version of the create-harper templates
19
20
 
20
21
  Available templates:
21
22
  ${yellow('vanilla-ts vanilla')}
@@ -0,0 +1,14 @@
1
+ export async function getLatestVersion(packageName) {
2
+ try {
3
+ const response = await fetch(`https://registry.npmjs.org/${packageName}/latest`, {
4
+ signal: AbortSignal.timeout(1000), // 1 second timeout
5
+ });
6
+ if (!response.ok) {
7
+ return null;
8
+ }
9
+ const data = await response.json();
10
+ return data.version;
11
+ } catch (error) {
12
+ return null;
13
+ }
14
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Simple semver comparison for x.y.z
3
+ * @param {string} latest
4
+ * @param {string} current
5
+ * @returns {boolean}
6
+ */
7
+ export function isVersionNewer(latest, current) {
8
+ const l = latest.split('.').map(x => parseInt(x, 10));
9
+ const c = current.split('.').map(x => parseInt(x, 10));
10
+
11
+ for (let i = 0; i < 3; i++) {
12
+ if (isNaN(l[i]) || isNaN(c[i])) { break; }
13
+ if (l[i] > c[i]) { return true; }
14
+ if (l[i] < c[i]) { return false; }
15
+ }
16
+ return false;
17
+ }
@@ -0,0 +1,43 @@
1
+ import spawn from 'cross-spawn';
2
+ import fs from 'node:fs';
3
+ import pc from 'picocolors';
4
+ import { getLatestVersion } from '../pkg/getLatestVersion.js';
5
+ import { isVersionNewer } from '../pkg/isVersionNewer.js';
6
+
7
+ /**
8
+ * Checks if the current version of the package is the latest version on npm.
9
+ * If not, it tries to re-run the command using npx with the @latest tag.
10
+ */
11
+ export async function checkForUpdate() {
12
+ const pkg = JSON.parse(fs.readFileSync(new URL('../../package.json', import.meta.url), 'utf-8'));
13
+ const currentVersion = pkg.version;
14
+
15
+ if (process.env.CREATE_HARPER_SKIP_UPDATE) {
16
+ return currentVersion;
17
+ }
18
+
19
+ try {
20
+ const latestVersion = await getLatestVersion(pkg.name);
21
+
22
+ if (latestVersion && isVersionNewer(latestVersion, currentVersion)) {
23
+ console.log(
24
+ pc.yellow(
25
+ `\n A new version of ${pc.bold(pkg.name)} is available! (${pc.dim(currentVersion)} -> ${
26
+ pc.green(latestVersion)
27
+ })`,
28
+ ),
29
+ );
30
+ console.log(` Automatically updating to the latest version...\n`);
31
+
32
+ const result = spawn.sync('npx', [`${pkg.name}@latest`, ...process.argv.slice(2)], {
33
+ stdio: 'inherit',
34
+ });
35
+
36
+ process.exit(result.status ?? 0);
37
+ }
38
+ } catch {
39
+ // Ignore errors, we don't want to block the user if the check fails
40
+ }
41
+
42
+ return currentVersion;
43
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-harper",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "type": "module",
5
5
  "author": {
6
6
  "name": "HarperDB",