vite-wp 0.1.2 → 0.1.5

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/README.md CHANGED
@@ -25,12 +25,13 @@ ViteWP is bring-your-own database. It does not start MySQL for you.
25
25
  mkdir my-site
26
26
  cd my-site
27
27
  npm init -y
28
- npm install vite-wp astro typescript @astrojs/check
29
28
  npx vite-wp init
30
29
  cp .env.example .env
31
30
  npm run dev
32
31
  ```
33
32
 
33
+ `vite-wp init` creates the starter files, adds the needed package dependencies, and runs install.
34
+
34
35
  Edit `.env` with your database credentials, then open:
35
36
 
36
37
  ```txt
package/dist/cli.js CHANGED
@@ -36,5 +36,8 @@ function printHelp() {
36
36
  vite-wp dev Start the local WordPress + Astro development runtime
37
37
  vite-wp doctor Check the current project setup
38
38
  vite-wp types Generate TypeScript types from WordPress metadata
39
- vite-wp smoke Verify the running ViteWP dev runtime\n`);
39
+ vite-wp smoke Verify the running ViteWP dev runtime
40
+
41
+ Options:
42
+ vite-wp init --no-install Create files without running package install\n`);
40
43
  }
@@ -1,10 +1,13 @@
1
+ import { spawnSync } from 'node:child_process';
1
2
  import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from 'node:fs';
2
3
  import { dirname, join, relative, resolve } from 'node:path';
3
4
  import { fileURLToPath } from 'node:url';
4
5
  export function runInit() {
5
6
  const target = resolve(process.cwd(), getTargetDirectory());
6
7
  const force = process.argv.includes('--force');
7
- const starter = resolve(dirname(fileURLToPath(import.meta.url)), '../../starter');
8
+ const shouldInstall = !process.argv.includes('--no-install');
9
+ const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), '../..');
10
+ const starter = resolve(packageRoot, 'starter');
8
11
  if (!existsSync(starter)) {
9
12
  console.error('Could not find the ViteWP starter files in this package.');
10
13
  process.exitCode = 1;
@@ -12,13 +15,15 @@ export function runInit() {
12
15
  }
13
16
  mkdirSync(target, { recursive: true });
14
17
  copyDirectory(starter, target, force);
15
- updatePackageJson(target);
18
+ updatePackageJson(target, packageRoot);
16
19
  console.log(`ViteWP project files initialized in ${relative(process.cwd(), target) || '.'}.`);
20
+ if (shouldInstall) {
21
+ installDependencies(target);
22
+ }
17
23
  console.log('');
18
24
  console.log('Next steps:');
19
25
  console.log(' 1. Copy .env.example to .env and set database credentials.');
20
- console.log(' 2. Run npm install if dependencies are not installed yet.');
21
- console.log(' 3. Run npm run dev.');
26
+ console.log(' 2. Run npm run dev.');
22
27
  }
23
28
  function getTargetDirectory() {
24
29
  const positional = process.argv.slice(3).find((arg) => !arg.startsWith('-'));
@@ -40,16 +45,53 @@ function copyDirectory(from, to, force) {
40
45
  cpSync(source, destination, { force: true });
41
46
  }
42
47
  }
43
- function updatePackageJson(root) {
48
+ function updatePackageJson(root, packageRoot) {
44
49
  const file = join(root, 'package.json');
45
50
  const packageJson = existsSync(file)
46
51
  ? JSON.parse(readFileSync(file, 'utf8'))
47
52
  : { private: true, type: 'module' };
53
+ const viteWp = readOwnPackage(packageRoot);
48
54
  packageJson.type ??= 'module';
49
55
  packageJson.scripts ??= {};
56
+ packageJson.dependencies ??= {};
57
+ packageJson.devDependencies ??= {};
50
58
  packageJson.scripts.dev ??= 'vite-wp dev';
51
59
  packageJson.scripts.doctor ??= 'vite-wp doctor';
52
60
  packageJson.scripts.types ??= 'vite-wp types';
53
61
  packageJson.scripts.check ??= 'astro check';
62
+ packageJson.dependencies['vite-wp'] ??= `^${viteWp.version}`;
63
+ packageJson.dependencies.astro ??= '^7.0.6';
64
+ packageJson.devDependencies.typescript ??= '~6.0.2';
65
+ packageJson.devDependencies['@astrojs/check'] ??= '^0.9.9';
54
66
  writeFileSync(file, `${JSON.stringify(packageJson, null, 2)}\n`, 'utf8');
55
67
  }
68
+ function readOwnPackage(packageRoot) {
69
+ const file = join(packageRoot, 'package.json');
70
+ const packageJson = JSON.parse(readFileSync(file, 'utf8'));
71
+ return { version: packageJson.version ?? '0.1.0' };
72
+ }
73
+ function installDependencies(root) {
74
+ const packageManager = detectPackageManager();
75
+ const args = packageManager === 'yarn' ? [] : ['install'];
76
+ console.log('');
77
+ console.log(`Installing dependencies with ${packageManager}...`);
78
+ const result = spawnSync(packageManager, args, {
79
+ cwd: root,
80
+ stdio: 'inherit',
81
+ shell: process.platform === 'win32',
82
+ });
83
+ if (result.status !== 0) {
84
+ console.log('');
85
+ console.log(`Dependency install did not complete. Run ${packageManager} ${args.join(' ')} manually.`.trim());
86
+ }
87
+ }
88
+ function detectPackageManager() {
89
+ const userAgent = process.env.npm_config_user_agent ?? '';
90
+ if (userAgent.startsWith('pnpm'))
91
+ return 'pnpm';
92
+ if (userAgent.startsWith('yarn'))
93
+ return 'yarn';
94
+ if (userAgent.startsWith('bun'))
95
+ return 'bun';
96
+ return 'npm';
97
+ }
package/dist/config.js CHANGED
@@ -17,7 +17,7 @@ export async function loadViteWpConfig(root = process.cwd()) {
17
17
  .find((file) => existsSync(file));
18
18
  let userConfig = {};
19
19
  if (configFile) {
20
- const loaded = await loadConfigFromFile({ command: 'serve', mode: 'development' }, configFile, root);
20
+ const loaded = await loadConfigFromFile({ command: 'serve', mode: 'development' }, configFile, root, undefined, undefined, 'runner');
21
21
  userConfig = (loaded?.config ?? {});
22
22
  }
23
23
  return {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vite-wp",
3
3
  "private": false,
4
- "version": "0.1.2",
4
+ "version": "0.1.5",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "vite-wp": "dist/cli.js"