create-harper 0.2.1 → 0.4.0

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
@@ -7,9 +7,9 @@ import { pkgFromUserAgent } from './lib/pkg/pkgFromUserAgent.js';
7
7
  import { checkForUpdate } from './lib/steps/checkForUpdate.js';
8
8
  import { getEnvVars } from './lib/steps/getEnvVars.js';
9
9
  import { getExamples } from './lib/steps/getExamples.js';
10
- import { getImmediate } from './lib/steps/getImmediate.js';
11
10
  import { getPackageName } from './lib/steps/getPackageName.js';
12
11
  import { getProjectName } from './lib/steps/getProjectName.js';
12
+ import { getRunAppImmediately } from './lib/steps/getRunAppImmediately.js';
13
13
  import { getTemplate } from './lib/steps/getTemplate.js';
14
14
  import { handleExistingDir } from './lib/steps/handleExistingDir.js';
15
15
  import { helpAgents } from './lib/steps/helpAgents.js';
@@ -85,7 +85,7 @@ async function init() {
85
85
  // Should we do a package manager installation?
86
86
  const pkgInfo = pkgFromUserAgent(process.env.npm_config_user_agent);
87
87
  const pkgManager = pkgInfo ? pkgInfo.name : 'npm';
88
- const immediateResult = await getImmediate(argImmediate, interactive, pkgManager);
88
+ const immediateResult = await getRunAppImmediately(argImmediate, interactive, pkgManager);
89
89
  if (immediateResult.cancelled) { return cancel(); }
90
90
  const { immediate } = immediateResult;
91
91
 
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Gets the global install command for a given package manager agent.
3
+ *
4
+ * @param {string} agent - The package manager agent (e.g., 'npm', 'pnpm', 'yarn', 'bun').
5
+ * @param {string} packageName - The name of the package to install globally.
6
+ * @returns {string[]} - An array containing the command and its arguments.
7
+ */
8
+ export function getGlobalInstallCommand(agent, packageName) {
9
+ switch (agent) {
10
+ case 'pnpm':
11
+ return [agent, 'add', '-g', packageName];
12
+ case 'yarn':
13
+ return [agent, 'global', 'add', packageName];
14
+ case 'bun':
15
+ return [agent, 'add', '-g', packageName];
16
+ default:
17
+ return [agent, 'install', '-g', packageName];
18
+ }
19
+ }
@@ -0,0 +1,59 @@
1
+ import * as prompts from '@clack/prompts';
2
+ import spawn from 'cross-spawn';
3
+ import { getGlobalInstallCommand } from '../pkg/getGlobalInstallCommand.js';
4
+
5
+ /**
6
+ * Step 5 (Optional): Ask the user if they want to immediately install dependencies and start the dev server.
7
+ *
8
+ * @param {boolean | undefined} argImmediate - The immediate flag provided via CLI arguments.
9
+ * @param {boolean} interactive - Whether the CLI is running in interactive mode.
10
+ * @param {string} pkgManager - The detected package manager.
11
+ * @returns {Promise<{immediate: boolean, cancelled: boolean}>} - The immediate flag and cancellation status.
12
+ */
13
+ export async function getRunAppImmediately(argImmediate, interactive, pkgManager) {
14
+ if (interactive) {
15
+ const harperInstalled = spawn.sync('harper', ['--version'], { stdio: 'ignore' }).status === 0;
16
+ if (!harperInstalled) {
17
+ const shouldInstallHarper = await prompts.confirm({
18
+ message: 'Harper CLI not found. Would you like to install it?',
19
+ initialValue: true,
20
+ });
21
+
22
+ if (prompts.isCancel(shouldInstallHarper)) {
23
+ return { immediate: false, cancelled: true };
24
+ }
25
+
26
+ if (shouldInstallHarper) {
27
+ const installCommand = getGlobalInstallCommand(pkgManager, 'harperdb');
28
+ prompts.log.step(`Installing Harper CLI with ${pkgManager}...`);
29
+ const installResult = spawn.sync(installCommand[0], installCommand.slice(1), { stdio: 'inherit' });
30
+ if (installResult.status === 0) {
31
+ prompts.log.success('Harper CLI installed successfully.');
32
+ prompts.log.step('Checking Harper status...');
33
+ spawn.sync('harper', ['status'], { stdio: 'inherit' });
34
+ } else {
35
+ prompts.log.error('Failed to install Harper CLI.');
36
+ }
37
+ }
38
+ }
39
+ }
40
+
41
+ let immediate = argImmediate;
42
+
43
+ if (immediate === undefined) {
44
+ if (interactive) {
45
+ const immediateResult = await prompts.confirm({
46
+ message: `Install with ${pkgManager} and start now?`,
47
+ });
48
+
49
+ if (prompts.isCancel(immediateResult)) {
50
+ return { immediate: false, cancelled: true };
51
+ }
52
+ immediate = immediateResult;
53
+ } else {
54
+ immediate = false;
55
+ }
56
+ }
57
+
58
+ return { immediate, cancelled: false };
59
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-harper",
3
- "version": "0.2.1",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "author": {
6
6
  "name": "HarperDB",
@@ -25,9 +25,10 @@
25
25
  "commitlint": "commitlint --edit",
26
26
  "format:check": "dprint check",
27
27
  "format:fix": "dprint fmt",
28
- "format:staged": "dprint check --staged",
28
+ "format:staged": "dprint check --staged --allow-no-files",
29
29
  "lint:check": "oxlint .",
30
30
  "lint:fix": "oxlint . --fix",
31
+ "prepare": "husky",
31
32
  "test": "vitest run",
32
33
  "test:coverage": "vitest run --coverage",
33
34
  "test:watch": "vitest"
@@ -58,6 +59,7 @@
58
59
  "@vitest/coverage-v8": "^4.0.17",
59
60
  "conventional-changelog-conventionalcommits": "^9.1.0",
60
61
  "dprint": "^0.51.1",
62
+ "husky": "^9.1.7",
61
63
  "oxlint": "^1.38.0",
62
64
  "semantic-release": "^25.0.2",
63
65
  "vitest": "^4.0.17"
@@ -1,30 +0,0 @@
1
- import * as prompts from '@clack/prompts';
2
-
3
- /**
4
- * Step 5 (Optional): Ask the user if they want to immediately install dependencies and start the dev server.
5
- *
6
- * @param {boolean | undefined} argImmediate - The immediate flag provided via CLI arguments.
7
- * @param {boolean} interactive - Whether the CLI is running in interactive mode.
8
- * @param {string} pkgManager - The detected package manager.
9
- * @returns {Promise<{immediate: boolean, cancelled: boolean}>} - The immediate flag and cancellation status.
10
- */
11
- export async function getImmediate(argImmediate, interactive, pkgManager) {
12
- let immediate = argImmediate;
13
-
14
- if (immediate === undefined) {
15
- if (interactive) {
16
- const immediateResult = await prompts.confirm({
17
- message: `Install with ${pkgManager} and start now?`,
18
- });
19
-
20
- if (prompts.isCancel(immediateResult)) {
21
- return { immediate: false, cancelled: true };
22
- }
23
- immediate = immediateResult;
24
- } else {
25
- immediate = false;
26
- }
27
- }
28
-
29
- return { immediate, cancelled: false };
30
- }