|
8 | 8 | // using https://unpkg.com/@ionic/[email protected]/core.json
|
9 | 9 | // using https://unpkg.com/@ionic/[email protected]/core.json
|
10 | 10 |
|
11 |
| -const fs = require("fs"); |
12 |
| -const https = require("https"); |
| 11 | +import fs from "fs"; |
| 12 | +import https from "https"; |
13 | 13 |
|
14 | 14 | const kebabize = (str) => {
|
15 | 15 | return str
|
@@ -248,140 +248,5 @@ export function testUserAgent(win: Window, expr: RegExp);
|
248 | 248 | });
|
249 | 249 | };
|
250 | 250 |
|
251 |
| -function download(res) { |
252 |
| - let data = ""; |
253 |
| - res.on("data", (chunk) => { |
254 |
| - data += chunk; |
255 |
| - }); |
256 |
| - res.on("end", () => { |
257 |
| - fs.writeFile(file, data, (err) => { |
258 |
| - if (err) throw err; |
259 |
| - console.log(`File saved as ${file} - length ${data.length}`); |
260 |
| - doStuff(); |
261 |
| - }); |
262 |
| - }); |
263 |
| -} |
264 |
| - |
265 |
| -function extractVersion(url) { |
266 |
| - const regex = /@(\d+\.\d+\.\d+)/; |
267 |
| - const match = url.match(regex); |
268 |
| - |
269 |
| - if (match) { |
270 |
| - const version = match[1]; |
271 |
| - // console.log(version); // Output: "7.0.3" |
272 |
| - return version; |
273 |
| - } else { |
274 |
| - console.log("No version number found"); |
275 |
| - return "ERROR"; |
276 |
| - } |
277 |
| -} |
278 |
| - |
279 |
| -function bumpPackageJson(version) { |
280 |
| - const currentDirectory = process.cwd(); |
281 |
| - |
282 |
| - if (currentDirectory.includes("script")) { |
283 |
| - console.log( |
284 |
| - "Current directory contains the word 'script' - that is how we want it" |
285 |
| - ); |
286 |
| - } else { |
287 |
| - console.log( |
288 |
| - "Current directory does not contain the word 'script' - aborting" |
289 |
| - ); |
290 |
| - process.exit(); |
291 |
| - } |
292 |
| - |
293 |
| - const filePath = "../package.json"; |
294 |
| - const packageName = "ionic-svelte"; |
295 |
| - |
296 |
| - fs.readFile(filePath, "utf-8", (err, data) => { |
297 |
| - if (err) throw err; |
298 |
| - |
299 |
| - // make backup |
300 |
| - fs.writeFile(filePath + ".bak", data, "utf-8", (err) => { |
301 |
| - if (err) throw err; |
302 |
| - console.log(`Backup created of ${filePath}`); |
303 |
| - }); |
304 |
| - |
305 |
| - const packageJson = JSON.parse(data); |
306 |
| - |
307 |
| - if (packageJson.dependencies && packageJson.dependencies[packageName]) { |
308 |
| - packageJson.dependencies[packageName] = version; |
309 |
| - } else if ( |
310 |
| - packageJson.devDependencies && |
311 |
| - packageJson.devDependencies[packageName] |
312 |
| - ) { |
313 |
| - packageJson.devDependencies[packageName] = version; |
314 |
| - } else { |
315 |
| - console.log( |
316 |
| - `Package ${packageName} not found in dependencies or devDependencies` |
317 |
| - ); |
318 |
| - } |
319 |
| - |
320 |
| - const updatedPackageJson = JSON.stringify(packageJson, null, 2); |
321 |
| - |
322 |
| - fs.writeFile(filePath, updatedPackageJson, "utf-8", (err) => { |
323 |
| - if (err) throw err; |
324 |
| - console.log( |
325 |
| - `Version of package ${packageName} updated to ${version}\n${updatedPackageJson}` |
326 |
| - ); |
327 |
| - }); |
328 |
| - }); |
329 |
| -} |
330 |
| - |
331 |
| -const url = "https://unpkg.com/@ionic/docs/core.json"; |
332 |
| -const file = "core.json"; |
333 |
| - |
334 |
| -https.get(url, (res) => { |
335 |
| - if (res.statusCode >= 300 && res.statusCode <= 399 && res.headers.location) { |
336 |
| - // Redirect detected |
337 |
| - |
338 |
| - console.log("redirect", res.headers.location); |
339 |
| - const version = extractVersion(res.headers.location); |
340 |
| - console.log("Version found", version); |
341 |
| - |
342 |
| - bumpPackageJson(version); |
343 |
| - // bumpCreatorPackages(version, '../packages/create-capacitor-svelte-app/src/creator.js'); |
344 |
| - // bumpCreatorPackages(version,'../packages/create-ionic-svelte-app/src/creator.js'); |
345 |
| - |
346 |
| - https.get("https://unpkg.com" + res.headers.location, (res) => { |
347 |
| - download(res); |
348 |
| - }); |
349 |
| - } else { |
350 |
| - download(res); |
351 |
| - } |
352 |
| -}); |
353 |
| - |
354 |
| -function bumpCreatorPackages(version, fileName) { |
355 |
| - // Read the contents of the creator.js file |
356 |
| - |
357 |
| - fs.readFile(fileName, "utf8", (err, data) => { |
358 |
| - if (err) { |
359 |
| - console.error(err); |
360 |
| - return; |
361 |
| - } |
362 |
| - |
363 |
| - // make backup |
364 |
| - fs.writeFile(fileName + ".bak", data, "utf-8", (err) => { |
365 |
| - if (err) throw err; |
366 |
| - console.log(`Backup created of ${fileName}`); |
367 |
| - }); |
368 |
| - |
369 |
| - // Define the search and replace strings |
370 |
| - const searchStr = "['@ionic/core@"; |
371 |
| - const replaceStr = "['@ionic/core@" + version; |
372 |
| - |
373 |
| - // Use a regular expression to search and replace the desired string |
374 |
| - const regex = new RegExp(`${searchStr}\\d+\\.\\d+\\.\\d+'`, "g"); |
375 |
| - const newData = data.replace(regex, replaceStr); |
376 |
| - |
377 |
| - // Write the updated contents back to the file |
378 |
| - fs.writeFile("creasssstor.js", newData, "utf8", (err) => { |
379 |
| - if (err) { |
380 |
| - console.error(err); |
381 |
| - return; |
382 |
| - } |
383 |
| - |
384 |
| - console.log("File updated successfully!"); |
385 |
| - }); |
386 |
| - }); |
387 |
| -} |
| 251 | +doStuff(); |
| 252 | +console.log("done!"); |
0 commit comments