create-pw-core 0.0.2 → 0.0.4
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/dist/index.js +42 -60
- package/dist/templates/package.json +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -125,44 +125,41 @@ async function main() {
|
|
|
125
125
|
}
|
|
126
126
|
catch (e) { }
|
|
127
127
|
}
|
|
128
|
-
//
|
|
129
|
-
|
|
130
|
-
if (!isDevRepo) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
128
|
+
// Check for latest version on registry to bypass npx cache issues
|
|
129
|
+
const pkgJsonPath = path.join(__dirname, '../package.json');
|
|
130
|
+
if (fs.existsSync(pkgJsonPath) && !isDevRepo) {
|
|
131
|
+
try {
|
|
132
|
+
const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'));
|
|
133
|
+
const currentVersion = pkg.version;
|
|
134
|
+
const latestVersion = (0, child_process_1.execSync)('npm view create-pw-core version', {
|
|
135
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
136
|
+
timeout: 3000
|
|
137
|
+
}).toString().trim();
|
|
138
|
+
if (latestVersion && currentVersion !== latestVersion) {
|
|
139
|
+
console.log(`\n\x1b[33mNewer version of create-pw-core found (${latestVersion}). Current: ${currentVersion}\x1b[0m`);
|
|
140
|
+
console.log('\x1b[36mRunning create-pw-core@latest to ensure you have the latest features...\n\x1b[0m');
|
|
141
|
+
const args = process.argv.slice(2);
|
|
142
|
+
const child = (0, child_process_1.spawn)('npx', ['create-pw-core@latest', ...args], {
|
|
143
|
+
stdio: 'inherit',
|
|
144
|
+
shell: true
|
|
145
|
+
});
|
|
146
|
+
await new Promise((resolve) => {
|
|
147
|
+
child.on('close', (code) => {
|
|
148
|
+
rl.close();
|
|
149
|
+
process.exit(code ?? 0);
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
return;
|
|
146
153
|
}
|
|
147
|
-
current = parent;
|
|
148
154
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
'z:/QECore/pw-core/examples',
|
|
152
|
-
'Z:/QECore/pw-core/examples'
|
|
153
|
-
];
|
|
154
|
-
for (const p of hardcodedPaths) {
|
|
155
|
-
if (fs.existsSync(p) && fs.statSync(p).isDirectory()) {
|
|
156
|
-
localExamplesDir = p;
|
|
157
|
-
break;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
155
|
+
catch (err) {
|
|
156
|
+
// Offline or network error: continue with the cached version
|
|
160
157
|
}
|
|
161
158
|
}
|
|
162
159
|
let templatesDir = path.join(__dirname, 'templates');
|
|
163
160
|
let templatePkgPath = path.join(templatesDir, 'package.json');
|
|
164
|
-
if (isDevRepo
|
|
165
|
-
const srcDir =
|
|
161
|
+
if (isDevRepo) {
|
|
162
|
+
const srcDir = path.join(devRepoPath, 'examples');
|
|
166
163
|
templatePkgPath = path.join(srcDir, 'package.json');
|
|
167
164
|
}
|
|
168
165
|
let templatePkg = {};
|
|
@@ -186,8 +183,8 @@ async function main() {
|
|
|
186
183
|
}
|
|
187
184
|
// Copy templates from create-pw-core package to target directory
|
|
188
185
|
console.log('\nCopying template files...');
|
|
189
|
-
if (isDevRepo
|
|
190
|
-
const srcDir =
|
|
186
|
+
if (isDevRepo) {
|
|
187
|
+
const srcDir = path.join(devRepoPath, 'examples');
|
|
191
188
|
console.log(`\x1b[33mLocal pw-core repository found. Copying templates directly from: ${srcDir}\x1b[0m`);
|
|
192
189
|
copyRecursiveSync(srcDir, targetDir);
|
|
193
190
|
}
|
|
@@ -223,47 +220,32 @@ async function main() {
|
|
|
223
220
|
else {
|
|
224
221
|
targetPkg.scripts['test'] = 'playwright test';
|
|
225
222
|
}
|
|
223
|
+
// Merge dependencies
|
|
224
|
+
targetPkg.dependencies = targetPkg.dependencies || {};
|
|
225
|
+
if (templatePkg.dependencies) {
|
|
226
|
+
for (const [key, val] of Object.entries(templatePkg.dependencies)) {
|
|
227
|
+
targetPkg.dependencies[key] = 'latest';
|
|
228
|
+
}
|
|
229
|
+
}
|
|
226
230
|
// Merge devDependencies
|
|
227
231
|
targetPkg.devDependencies = targetPkg.devDependencies || {};
|
|
228
232
|
if (templatePkg.devDependencies) {
|
|
229
233
|
for (const [key, val] of Object.entries(templatePkg.devDependencies)) {
|
|
230
234
|
if (key !== 'pw-core') {
|
|
231
|
-
targetPkg.devDependencies[key] =
|
|
235
|
+
targetPkg.devDependencies[key] = 'latest';
|
|
232
236
|
}
|
|
233
237
|
}
|
|
234
238
|
}
|
|
235
239
|
// Check if we are testing locally or installing published package
|
|
236
|
-
let pwCoreInstallSource =
|
|
240
|
+
let pwCoreInstallSource = 'latest';
|
|
237
241
|
const envInstallLocal = process.env.PW_CORE_INSTALL_LOCAL;
|
|
238
242
|
if (envInstallLocal) {
|
|
239
243
|
// If running in development/local test, use the absolute path to pw-core directory
|
|
240
244
|
pwCoreInstallSource = `file:${envInstallLocal}`;
|
|
241
245
|
}
|
|
242
|
-
else {
|
|
246
|
+
else if (isDevRepo) {
|
|
243
247
|
// Check if running in the development repository
|
|
244
|
-
|
|
245
|
-
pwCoreInstallSource = `file:${devRepoPath}`;
|
|
246
|
-
}
|
|
247
|
-
else {
|
|
248
|
-
if (pwCoreInstallSource.startsWith('file:')) {
|
|
249
|
-
let resolvedRootPkgPath = '';
|
|
250
|
-
if (localExamplesDir) {
|
|
251
|
-
resolvedRootPkgPath = path.join(localExamplesDir, '..', 'package.json');
|
|
252
|
-
}
|
|
253
|
-
if (fs.existsSync(resolvedRootPkgPath)) {
|
|
254
|
-
try {
|
|
255
|
-
const rootPkg = JSON.parse(fs.readFileSync(resolvedRootPkgPath, 'utf8'));
|
|
256
|
-
pwCoreInstallSource = `^${rootPkg.version}`;
|
|
257
|
-
}
|
|
258
|
-
catch (e) {
|
|
259
|
-
pwCoreInstallSource = '^1.1.1';
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
else {
|
|
263
|
-
pwCoreInstallSource = '^1.1.1';
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
248
|
+
pwCoreInstallSource = `file:${devRepoPath}`;
|
|
267
249
|
}
|
|
268
250
|
targetPkg.devDependencies['pw-core'] = pwCoreInstallSource;
|
|
269
251
|
fs.writeFileSync(packageJsonPath, JSON.stringify(targetPkg, null, 2), 'utf8');
|