xgem-cli 2.0.0-alpha.1 → 2.0.0-alpha.12

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.
Files changed (49) hide show
  1. package/README.md +53 -31
  2. package/bin/xgem +21 -14
  3. package/bin/xgem.js +235 -0
  4. package/lib/create.sh +334 -0
  5. package/lib/doctor.sh +13 -2
  6. package/lib/flutter.sh +163 -18
  7. package/lib/git.sh +157 -23
  8. package/lib/ios.sh +126 -47
  9. package/lib/scaffold.sh +24 -5
  10. package/lib/version.sh +1 -1
  11. package/lib-win/doctor.js +44 -0
  12. package/lib-win/flutter.js +101 -0
  13. package/lib-win/git.js +279 -0
  14. package/lib-win/logger.js +35 -0
  15. package/lib-win/scaffold.js +102 -0
  16. package/lib-win/utils.js +67 -0
  17. package/package.json +8 -7
  18. package/templates/node/build.sh.tmpl +9 -1
  19. package/templates/node/hard-clean.sh.tmpl +34 -2
  20. package/templates/node/lint.sh.tmpl +10 -0
  21. package/templates/node/start.sh.tmpl +9 -1
  22. package/templates/node/test.sh.tmpl +10 -0
  23. package/templates/webframework/build.sh.tmpl +10 -1
  24. package/templates/webframework/dev.sh.tmpl +9 -1
  25. package/templates/webframework/hard-clean.sh.tmpl +35 -2
  26. package/templates/webframework/lint.sh.tmpl +10 -0
  27. package/templates/webframework/test.sh.tmpl +10 -0
  28. package/templates-win/docker/build-up.mjs.tmpl +3 -0
  29. package/templates-win/docker/hard-clean.mjs.tmpl +4 -0
  30. package/templates-win/flutter/build-runner.mjs.tmpl +4 -0
  31. package/templates-win/flutter/build.mjs.tmpl +4 -0
  32. package/templates-win/flutter/hard-clean.mjs.tmpl +6 -0
  33. package/templates-win/go/build.mjs.tmpl +3 -0
  34. package/templates-win/go/hard-clean.mjs.tmpl +4 -0
  35. package/templates-win/node/build.mjs.tmpl +10 -0
  36. package/templates-win/node/hard-clean.mjs.tmpl +28 -0
  37. package/templates-win/node/lint.mjs.tmpl +10 -0
  38. package/templates-win/node/start.mjs.tmpl +10 -0
  39. package/templates-win/node/test.mjs.tmpl +10 -0
  40. package/templates-win/python/hard-clean.mjs.tmpl +8 -0
  41. package/templates-win/python/install.mjs.tmpl +12 -0
  42. package/templates-win/rust/build.mjs.tmpl +3 -0
  43. package/templates-win/rust/hard-clean.mjs.tmpl +3 -0
  44. package/templates-win/webframework/build.mjs.tmpl +10 -0
  45. package/templates-win/webframework/dev.mjs.tmpl +10 -0
  46. package/templates-win/webframework/hard-clean.mjs.tmpl +32 -0
  47. package/templates-win/webframework/lint.mjs.tmpl +10 -0
  48. package/templates-win/webframework/test.mjs.tmpl +10 -0
  49. package/scripts/check-platform.js +0 -17
@@ -0,0 +1,10 @@
1
+ #!/bin/bash
2
+ if [ -f pnpm-lock.yaml ]; then
3
+ pnpm run lint
4
+ elif [ -f yarn.lock ]; then
5
+ yarn lint
6
+ elif [ -f bun.lockb ] || [ -f bun.lock ]; then
7
+ bun run lint
8
+ else
9
+ npm run lint
10
+ fi
@@ -1,2 +1,10 @@
1
1
  #!/bin/bash
2
- npm run start
2
+ if [ -f pnpm-lock.yaml ]; then
3
+ pnpm run start
4
+ elif [ -f yarn.lock ]; then
5
+ yarn start
6
+ elif [ -f bun.lockb ] || [ -f bun.lock ]; then
7
+ bun run start
8
+ else
9
+ npm run start
10
+ fi
@@ -0,0 +1,10 @@
1
+ #!/bin/bash
2
+ if [ -f pnpm-lock.yaml ]; then
3
+ pnpm run test
4
+ elif [ -f yarn.lock ]; then
5
+ yarn test
6
+ elif [ -f bun.lockb ] || [ -f bun.lock ]; then
7
+ bun run test
8
+ else
9
+ npm run test
10
+ fi
@@ -1,2 +1,11 @@
1
1
  #!/bin/bash
2
- npm run build
2
+ # Use whatever package manager this project actually uses.
3
+ if [ -f pnpm-lock.yaml ]; then
4
+ pnpm run build
5
+ elif [ -f yarn.lock ]; then
6
+ yarn build
7
+ elif [ -f bun.lockb ] || [ -f bun.lock ]; then
8
+ bun run build
9
+ else
10
+ npm run build
11
+ fi
@@ -1,2 +1,10 @@
1
1
  #!/bin/bash
2
- npm run dev
2
+ if [ -f pnpm-lock.yaml ]; then
3
+ pnpm run dev
4
+ elif [ -f yarn.lock ]; then
5
+ yarn dev
6
+ elif [ -f bun.lockb ] || [ -f bun.lock ]; then
7
+ bun run dev
8
+ else
9
+ npm run dev
10
+ fi
@@ -1,3 +1,36 @@
1
1
  #!/bin/bash
2
- echo -e "\033[1;33mResetting __FRAMEWORK__ dependencies...\033[0m"
3
- rm -rf node_modules package-lock.json yarn.lock && npm install
2
+ # Detect the package manager actually in use instead of assuming npm —
3
+ # blindly deleting yarn.lock/pnpm-lock.yaml on a project that uses them
4
+ # and running `npm install` instead corrupts the project by introducing a
5
+ # conflicting lockfile.
6
+ PKG_MANAGER=npm
7
+ if [ -f pnpm-lock.yaml ]; then
8
+ PKG_MANAGER=pnpm
9
+ elif [ -f yarn.lock ]; then
10
+ PKG_MANAGER=yarn
11
+ elif [ -f bun.lockb ] || [ -f bun.lock ]; then
12
+ PKG_MANAGER=bun
13
+ elif [ -f package.json ]; then
14
+ declared=$(grep -o '"packageManager"[[:space:]]*:[[:space:]]*"[a-z]*' package.json 2>/dev/null | grep -oE '[a-z]+$')
15
+ case "$declared" in npm|yarn|pnpm|bun) PKG_MANAGER=$declared ;; esac
16
+ fi
17
+
18
+ # Warn (don't block) on a Node version mismatch against .nvmrc, if present.
19
+ if [ -f .nvmrc ] && command -v node >/dev/null 2>&1; then
20
+ wanted=$(tr -d 'v[:space:]' < .nvmrc)
21
+ have=$(node -v | tr -d 'v')
22
+ case "$have" in
23
+ "$wanted"*) ;;
24
+ *) echo -e "\033[33mWarning: .nvmrc wants Node $wanted, but 'node -v' reports $have.\033[0m" ;;
25
+ esac
26
+ fi
27
+
28
+ echo -e "\033[1;33mResetting __FRAMEWORK__ dependencies (package manager: $PKG_MANAGER)...\033[0m"
29
+ rm -rf node_modules
30
+
31
+ case "$PKG_MANAGER" in
32
+ yarn) rm -f yarn.lock; yarn install ;;
33
+ pnpm) rm -f pnpm-lock.yaml; pnpm install ;;
34
+ bun) rm -f bun.lockb bun.lock; bun install ;;
35
+ *) rm -f package-lock.json; npm install ;;
36
+ esac
@@ -0,0 +1,10 @@
1
+ #!/bin/bash
2
+ if [ -f pnpm-lock.yaml ]; then
3
+ pnpm run lint
4
+ elif [ -f yarn.lock ]; then
5
+ yarn lint
6
+ elif [ -f bun.lockb ] || [ -f bun.lock ]; then
7
+ bun run lint
8
+ else
9
+ npm run lint
10
+ fi
@@ -0,0 +1,10 @@
1
+ #!/bin/bash
2
+ if [ -f pnpm-lock.yaml ]; then
3
+ pnpm run test
4
+ elif [ -f yarn.lock ]; then
5
+ yarn test
6
+ elif [ -f bun.lockb ] || [ -f bun.lock ]; then
7
+ bun run test
8
+ else
9
+ npm run test
10
+ fi
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import { execSync } from 'node:child_process';
3
+ execSync('docker-compose up --build -d', { stdio: 'inherit' });
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import { execSync } from 'node:child_process';
3
+ console.log('Pruning unused Docker assets and volumes...');
4
+ execSync('docker system prune -a --volumes -f', { stdio: 'inherit' });
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import { spawnSync } from 'node:child_process';
3
+ const r = spawnSync('xgem', ['run', 'flutter', 'build-runner'], { stdio: 'inherit', shell: true });
4
+ process.exit(r.status ?? 0);
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import { spawnSync } from 'node:child_process';
3
+ const r = spawnSync('xgem', ['run', 'flutter', 'build'], { stdio: 'inherit', shell: true });
4
+ process.exit(r.status ?? 0);
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ // Delegates to xgem's native Windows flutter engine — single source of
3
+ // truth instead of a second copy of the logic.
4
+ import { spawnSync } from 'node:child_process';
5
+ const r = spawnSync('xgem', ['run', 'flutter', 'hard-clean'], { stdio: 'inherit', shell: true });
6
+ process.exit(r.status ?? 0);
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import { execSync } from 'node:child_process';
3
+ execSync('go build -o bin\\main.exe main.go', { stdio: 'inherit' });
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import { execSync } from 'node:child_process';
3
+ console.log('Cleaning Go module cache...');
4
+ execSync('go clean -modcache', { stdio: 'inherit' });
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ import { execSync } from 'node:child_process';
3
+ import { existsSync } from 'node:fs';
4
+
5
+ let cmd = 'npm run build';
6
+ if (existsSync('pnpm-lock.yaml')) cmd = 'pnpm run build';
7
+ else if (existsSync('yarn.lock')) cmd = 'yarn build';
8
+ else if (existsSync('bun.lockb') || existsSync('bun.lock')) cmd = 'bun run build';
9
+
10
+ execSync(cmd, { stdio: 'inherit' });
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env node
2
+ import { execSync } from 'node:child_process';
3
+ import { existsSync, rmSync, readFileSync } from 'node:fs';
4
+
5
+ function detectPkgManager() {
6
+ if (existsSync('pnpm-lock.yaml')) return 'pnpm';
7
+ if (existsSync('yarn.lock')) return 'yarn';
8
+ if (existsSync('bun.lockb') || existsSync('bun.lock')) return 'bun';
9
+ if (existsSync('package.json')) {
10
+ try {
11
+ const pkg = JSON.parse(readFileSync('package.json', 'utf8'));
12
+ if (['npm', 'yarn', 'pnpm', 'bun'].includes(pkg.packageManager?.split('@')[0])) {
13
+ return pkg.packageManager.split('@')[0];
14
+ }
15
+ } catch { /* ignore malformed package.json */ }
16
+ }
17
+ return 'npm';
18
+ }
19
+
20
+ const pm = detectPkgManager();
21
+ console.log(`Nuking node_modules and resetting package locks (package manager: ${pm})...`);
22
+ rmSync('node_modules', { recursive: true, force: true });
23
+
24
+ const lockfiles = { npm: ['package-lock.json'], yarn: ['yarn.lock'], pnpm: ['pnpm-lock.yaml'], bun: ['bun.lockb', 'bun.lock'] };
25
+ for (const f of lockfiles[pm]) rmSync(f, { force: true });
26
+
27
+ const installCmd = { npm: 'npm install', yarn: 'yarn', pnpm: 'pnpm install', bun: 'bun install' };
28
+ execSync(installCmd[pm], { stdio: 'inherit' });
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ import { execSync } from 'node:child_process';
3
+ import { existsSync } from 'node:fs';
4
+
5
+ let cmd = 'npm run lint';
6
+ if (existsSync('pnpm-lock.yaml')) cmd = 'pnpm run lint';
7
+ else if (existsSync('yarn.lock')) cmd = 'yarn lint';
8
+ else if (existsSync('bun.lockb') || existsSync('bun.lock')) cmd = 'bun run lint';
9
+
10
+ execSync(cmd, { stdio: 'inherit' });
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ import { execSync } from 'node:child_process';
3
+ import { existsSync } from 'node:fs';
4
+
5
+ let cmd = 'npm run start';
6
+ if (existsSync('pnpm-lock.yaml')) cmd = 'pnpm run start';
7
+ else if (existsSync('yarn.lock')) cmd = 'yarn start';
8
+ else if (existsSync('bun.lockb') || existsSync('bun.lock')) cmd = 'bun run start';
9
+
10
+ execSync(cmd, { stdio: 'inherit' });
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ import { execSync } from 'node:child_process';
3
+ import { existsSync } from 'node:fs';
4
+
5
+ let cmd = 'npm run test';
6
+ if (existsSync('pnpm-lock.yaml')) cmd = 'pnpm run test';
7
+ else if (existsSync('yarn.lock')) cmd = 'yarn test';
8
+ else if (existsSync('bun.lockb') || existsSync('bun.lock')) cmd = 'bun run test';
9
+
10
+ execSync(cmd, { stdio: 'inherit' });
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ import { execSync } from 'node:child_process';
3
+ import { rmSync } from 'node:fs';
4
+
5
+ console.log('Cleaning Python cache and rebuilding environment...');
6
+ rmSync('__pycache__', { recursive: true, force: true });
7
+ rmSync('.venv', { recursive: true, force: true });
8
+ execSync('python -m venv .venv', { stdio: 'inherit' });
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env node
2
+ import { execSync } from 'node:child_process';
3
+ import { existsSync } from 'node:fs';
4
+
5
+ // Windows venvs don't have an "activate && run" equivalent worth using in
6
+ // a spawned process — call the venv's own pip.exe directly instead.
7
+ if (existsSync('.venv\\Scripts\\pip.exe')) {
8
+ execSync('.venv\\Scripts\\pip.exe install -r requirements.txt', { stdio: 'inherit' });
9
+ } else {
10
+ console.error('Error: Virtual environment (.venv) not found.');
11
+ process.exit(1);
12
+ }
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import { execSync } from 'node:child_process';
3
+ execSync('cargo build --release', { stdio: 'inherit' });
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import { execSync } from 'node:child_process';
3
+ execSync('cargo clean', { stdio: 'inherit' });
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ import { execSync } from 'node:child_process';
3
+ import { existsSync } from 'node:fs';
4
+
5
+ let cmd = 'npm run build';
6
+ if (existsSync('pnpm-lock.yaml')) cmd = 'pnpm run build';
7
+ else if (existsSync('yarn.lock')) cmd = 'yarn build';
8
+ else if (existsSync('bun.lockb') || existsSync('bun.lock')) cmd = 'bun run build';
9
+
10
+ execSync(cmd, { stdio: 'inherit' });
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ import { execSync } from 'node:child_process';
3
+ import { existsSync } from 'node:fs';
4
+
5
+ let cmd = 'npm run dev';
6
+ if (existsSync('pnpm-lock.yaml')) cmd = 'pnpm run dev';
7
+ else if (existsSync('yarn.lock')) cmd = 'yarn dev';
8
+ else if (existsSync('bun.lockb') || existsSync('bun.lock')) cmd = 'bun run dev';
9
+
10
+ execSync(cmd, { stdio: 'inherit' });
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env node
2
+ import { execSync } from 'node:child_process';
3
+ import { existsSync, rmSync, readFileSync } from 'node:fs';
4
+
5
+ // Detect the package manager actually in use instead of assuming npm —
6
+ // blindly deleting yarn.lock/pnpm-lock.yaml on a project that uses them
7
+ // and running `npm install` instead corrupts the project by introducing a
8
+ // conflicting lockfile.
9
+ function detectPkgManager() {
10
+ if (existsSync('pnpm-lock.yaml')) return 'pnpm';
11
+ if (existsSync('yarn.lock')) return 'yarn';
12
+ if (existsSync('bun.lockb') || existsSync('bun.lock')) return 'bun';
13
+ if (existsSync('package.json')) {
14
+ try {
15
+ const pkg = JSON.parse(readFileSync('package.json', 'utf8'));
16
+ if (['npm', 'yarn', 'pnpm', 'bun'].includes(pkg.packageManager?.split('@')[0])) {
17
+ return pkg.packageManager.split('@')[0];
18
+ }
19
+ } catch { /* ignore malformed package.json */ }
20
+ }
21
+ return 'npm';
22
+ }
23
+
24
+ const pm = detectPkgManager();
25
+ console.log(`Resetting __FRAMEWORK__ dependencies (package manager: ${pm})...`);
26
+ rmSync('node_modules', { recursive: true, force: true });
27
+
28
+ const lockfiles = { npm: ['package-lock.json'], yarn: ['yarn.lock'], pnpm: ['pnpm-lock.yaml'], bun: ['bun.lockb', 'bun.lock'] };
29
+ for (const f of lockfiles[pm]) rmSync(f, { force: true });
30
+
31
+ const installCmd = { npm: 'npm install', yarn: 'yarn', pnpm: 'pnpm install', bun: 'bun install' };
32
+ execSync(installCmd[pm], { stdio: 'inherit' });
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ import { execSync } from 'node:child_process';
3
+ import { existsSync } from 'node:fs';
4
+
5
+ let cmd = 'npm run lint';
6
+ if (existsSync('pnpm-lock.yaml')) cmd = 'pnpm run lint';
7
+ else if (existsSync('yarn.lock')) cmd = 'yarn lint';
8
+ else if (existsSync('bun.lockb') || existsSync('bun.lock')) cmd = 'bun run lint';
9
+
10
+ execSync(cmd, { stdio: 'inherit' });
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ import { execSync } from 'node:child_process';
3
+ import { existsSync } from 'node:fs';
4
+
5
+ let cmd = 'npm run test';
6
+ if (existsSync('pnpm-lock.yaml')) cmd = 'pnpm run test';
7
+ else if (existsSync('yarn.lock')) cmd = 'yarn test';
8
+ else if (existsSync('bun.lockb') || existsSync('bun.lock')) cmd = 'bun run test';
9
+
10
+ execSync(cmd, { stdio: 'inherit' });
@@ -1,17 +0,0 @@
1
- #!/usr/bin/env node
2
- // Runs as npm's preinstall step. xgem is a bash CLI (osascript/xcodebuild
3
- // for the iOS engine, sh-isms throughout) with no Windows-native equivalent,
4
- // so this exists purely to fail with an actionable message instead of npm's
5
- // generic EBADPLATFORM error.
6
-
7
- if (process.platform !== 'darwin' && process.platform !== 'linux') {
8
- console.error('');
9
- console.error('\x1b[31mxgem does not run natively on Windows.\x1b[0m');
10
- console.error("It's a bash CLI, and its Flutter iOS build engine shells out to Xcode tools that only exist on macOS.");
11
- console.error('');
12
- console.error('\x1b[36mTo use xgem on Windows, install WSL2 first:\x1b[0m');
13
- console.error(' https://learn.microsoft.com/windows/wsl/install');
14
- console.error('Then run this same install command again from inside your WSL terminal (it reports itself as Linux).');
15
- console.error('');
16
- process.exit(1);
17
- }