@esimplicity/create-stack-tests 0.1.0 → 0.1.1

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.
@@ -0,0 +1,183 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const { execSync, spawnSync } = require('child_process');
5
+ const fs = require('fs');
6
+ const path = require('path');
7
+
8
+ const PACKAGE_NAME = '@esimplicityinc/stack-tests';
9
+ const NPM_PACKAGE_NAME = '@esimplicity/stack-tests';
10
+
11
+ function log(msg) {
12
+ console.log(`[upgrade-stack-tests] ${msg}`);
13
+ }
14
+
15
+ function error(msg) {
16
+ console.error(`[upgrade-stack-tests] ERROR: ${msg}`);
17
+ }
18
+
19
+ function detectPackageManager(startDir) {
20
+ let dir = startDir;
21
+ while (true) {
22
+ if (fs.existsSync(path.join(dir, 'bun.lockb'))) return 'bun';
23
+ if (fs.existsSync(path.join(dir, 'bun.lock'))) return 'bun';
24
+ if (fs.existsSync(path.join(dir, 'pnpm-lock.yaml'))) return 'pnpm';
25
+ if (fs.existsSync(path.join(dir, 'yarn.lock'))) return 'yarn';
26
+ if (fs.existsSync(path.join(dir, 'package-lock.json'))) return 'npm';
27
+ const parent = path.dirname(dir);
28
+ if (parent === dir) break;
29
+ dir = parent;
30
+ }
31
+ return 'npm';
32
+ }
33
+
34
+ function getInstalledVersion(cwd) {
35
+ const pkgPath = path.join(cwd, 'node_modules', PACKAGE_NAME, 'package.json');
36
+ if (!fs.existsSync(pkgPath)) {
37
+ // Try npm scoped name
38
+ const npmPkgPath = path.join(cwd, 'node_modules', NPM_PACKAGE_NAME, 'package.json');
39
+ if (fs.existsSync(npmPkgPath)) {
40
+ const pkg = JSON.parse(fs.readFileSync(npmPkgPath, 'utf8'));
41
+ return { version: pkg.version, name: NPM_PACKAGE_NAME };
42
+ }
43
+ return null;
44
+ }
45
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
46
+ return { version: pkg.version, name: PACKAGE_NAME };
47
+ }
48
+
49
+ function getLatestVersion(packageName) {
50
+ try {
51
+ const result = execSync(`npm view ${packageName} version`, {
52
+ encoding: 'utf8',
53
+ stdio: ['pipe', 'pipe', 'pipe'],
54
+ });
55
+ return result.trim();
56
+ } catch {
57
+ return null;
58
+ }
59
+ }
60
+
61
+ function runUpgrade(pm, packageName, targetVersion) {
62
+ const versionSpec = targetVersion ? `${packageName}@${targetVersion}` : packageName;
63
+
64
+ const commands = {
65
+ npm: ['npm', 'install', versionSpec],
66
+ bun: ['bun', 'add', versionSpec],
67
+ pnpm: ['pnpm', 'add', versionSpec],
68
+ yarn: ['yarn', 'add', versionSpec],
69
+ };
70
+
71
+ const [cmd, ...args] = commands[pm] || commands.npm;
72
+
73
+ log(`Running: ${cmd} ${args.join(' ')}`);
74
+ const result = spawnSync(cmd, args, { stdio: 'inherit', shell: true });
75
+
76
+ return result.status === 0;
77
+ }
78
+
79
+ function parseArgs(args) {
80
+ const options = {
81
+ check: false,
82
+ version: null,
83
+ help: false,
84
+ };
85
+
86
+ for (let i = 0; i < args.length; i++) {
87
+ const arg = args[i];
88
+ if (arg === '--check' || arg === '-c') {
89
+ options.check = true;
90
+ } else if (arg === '--version' || arg === '-v') {
91
+ options.version = args[++i];
92
+ } else if (arg === '--help' || arg === '-h') {
93
+ options.help = true;
94
+ }
95
+ }
96
+
97
+ return options;
98
+ }
99
+
100
+ function showHelp() {
101
+ console.log(`
102
+ Usage: npx upgrade-stack-tests [options]
103
+
104
+ Upgrade @esimplicityinc/stack-tests to the latest version.
105
+
106
+ Options:
107
+ -c, --check Check for updates without installing
108
+ -v, --version VER Install a specific version
109
+ -h, --help Show this help message
110
+
111
+ Examples:
112
+ npx upgrade-stack-tests # Upgrade to latest
113
+ npx upgrade-stack-tests --check # Check for updates only
114
+ npx upgrade-stack-tests -v 0.1.1 # Install specific version
115
+ `);
116
+ }
117
+
118
+ async function main() {
119
+ const args = process.argv.slice(2);
120
+ const options = parseArgs(args);
121
+
122
+ if (options.help) {
123
+ showHelp();
124
+ process.exit(0);
125
+ }
126
+
127
+ const cwd = process.cwd();
128
+ const pm = detectPackageManager(cwd);
129
+
130
+ log(`Detected package manager: ${pm}`);
131
+
132
+ // Check installed version
133
+ const installed = getInstalledVersion(cwd);
134
+ if (!installed) {
135
+ error(`${PACKAGE_NAME} is not installed in this project.`);
136
+ log(`Run: ${pm === 'npm' ? 'npm install' : pm + ' add'} ${PACKAGE_NAME}`);
137
+ process.exit(1);
138
+ }
139
+
140
+ log(`Installed: ${installed.name}@${installed.version}`);
141
+
142
+ // Get latest version
143
+ const latest = getLatestVersion(installed.name);
144
+ if (!latest) {
145
+ error(`Could not fetch latest version from registry.`);
146
+ process.exit(1);
147
+ }
148
+
149
+ const targetVersion = options.version || latest;
150
+ log(`Latest available: ${latest}`);
151
+
152
+ if (options.version) {
153
+ log(`Target version: ${options.version}`);
154
+ }
155
+
156
+ // Compare versions
157
+ if (installed.version === targetVersion) {
158
+ log(`Already up to date!`);
159
+ process.exit(0);
160
+ }
161
+
162
+ if (options.check) {
163
+ log(`Update available: ${installed.version} -> ${targetVersion}`);
164
+ log(`Run without --check to upgrade.`);
165
+ process.exit(0);
166
+ }
167
+
168
+ // Perform upgrade
169
+ log(`Upgrading: ${installed.version} -> ${targetVersion}`);
170
+ const success = runUpgrade(pm, installed.name, targetVersion);
171
+
172
+ if (success) {
173
+ log(`Successfully upgraded to ${targetVersion}!`);
174
+ } else {
175
+ error(`Upgrade failed.`);
176
+ process.exit(1);
177
+ }
178
+ }
179
+
180
+ main().catch((err) => {
181
+ error(err.message);
182
+ process.exit(1);
183
+ });
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@esimplicity/create-stack-tests",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "private": false,
5
5
  "type": "commonjs",
6
6
  "bin": {
7
- "create-stack-tests": "bin/create-stack-tests.js"
7
+ "create-stack-tests": "bin/create-stack-tests.js",
8
+ "upgrade-stack-tests": "bin/upgrade-stack-tests.js"
8
9
  },
9
- "description": "Scaffold a Playwright-BDD stack-tests project",
10
+ "description": "Scaffold and manage Playwright-BDD stack-tests projects",
10
11
  "scripts": {
11
12
  "build": "echo 'No build required'"
12
13
  },