]> git.ipfire.org Git - thirdparty/vuejs/create-vue.git/commitdiff
chore: use zx for all npm scripts
authorHaoqun Jiang <haoqunjiang@gmail.com>
Mon, 17 Jan 2022 06:01:33 +0000 (14:01 +0800)
committerHaoqun Jiang <haoqunjiang@gmail.com>
Mon, 17 Jan 2022 06:01:33 +0000 (14:01 +0800)
package.json
scripts/prepublish.mjs
scripts/snapshot.mjs [moved from snapshot.js with 63% similarity]
scripts/test.mjs [new file with mode: 0644]
test.js [deleted file]

index ce5170b848d5b3533c5dcb476b5d46871221a912..898c917e0bef654cec276d7d30019b55adf7fd49 100644 (file)
@@ -17,9 +17,9 @@
     "prepare": "husky install",
     "format": "prettier --write .",
     "build": "esbuild --bundle index.js --format=cjs --platform=node --outfile=outfile.cjs",
-    "snapshot": "node snapshot.js",
+    "snapshot": "zx ./scripts/snapshot.mjs",
     "pretest": "run-s build snapshot",
-    "test": "node test.js",
+    "test": "zx ./scripts/test.mjs",
     "prepublishOnly": "zx ./scripts/prepublish.mjs"
   },
   "repository": {
index b472c7f861e835f3b5a9d7c8e26a588301181fac..e3a31dccc2d547a7b9fc57d77727d976cfa79844 100644 (file)
@@ -6,7 +6,8 @@ await $`pnpm snapshot`
 
 let { version } = JSON.parse(await fs.readFile('./package.json'))
 
-cd('./playground')
+const playgroundDir = path.resolve(__dirname, '../playground/')
+cd(playgroundDir)
 
 await $`git add -A .`
 try {
similarity index 63%
rename from snapshot.js
rename to scripts/snapshot.mjs
index 2a1dac7451c637813c9ede0e9a1732213c09eb87..18ad2b0ae9dac65e7cb257072958c8e12879138b 100644 (file)
@@ -1,29 +1,10 @@
-import { spawnSync } from 'child_process'
-import path from 'path'
+#!/usr/bin/env zx
+import 'zx/globals'
 
-const __dirname = path
-  .dirname(new URL(import.meta.url).pathname)
-  .substring(process.platform === 'win32' ? 1 : 0)
+$.verbose = false
 
-const bin = path.resolve(__dirname, './outfile.cjs')
-const playgroundDir = path.resolve(__dirname, './playground/')
-
-function createProjectWithFeatureFlags(flags) {
-  const projectName = flags.join('-')
-  console.log(`Creating project ${projectName}`)
-  const { status } = spawnSync(
-    'node',
-    [bin, projectName, ...flags.map((flag) => `--${flag}`), '--force'],
-    {
-      cwd: playgroundDir,
-      stdio: ['pipe', 'pipe', 'inherit']
-    }
-  )
-
-  if (status !== 0) {
-    process.exit(status)
-  }
-}
+const bin = path.resolve(__dirname, '../outfile.cjs')
+const playgroundDir = path.resolve(__dirname, '../playground/')
 
 const featureFlags = ['typescript', 'jsx', 'router', 'pinia', 'with-tests']
 
@@ -59,6 +40,10 @@ function fullCombination(arr) {
 const flagCombinations = fullCombination(featureFlags)
 flagCombinations.push(['default'])
 
+cd(playgroundDir)
 for (const flags of flagCombinations) {
-  createProjectWithFeatureFlags(flags)
+  const projectName = flags.join('-')
+  console.log(`Creating project ${projectName}`)
+
+  await $`node ${[bin, projectName, ...flags.map((flag) => `--${flag}`), '--force']}`
 }
diff --git a/scripts/test.mjs b/scripts/test.mjs
new file mode 100644 (file)
index 0000000..5d29eb1
--- /dev/null
@@ -0,0 +1,19 @@
+#!/usr/bin/env zx
+import 'zx/globals'
+
+const playgroundDir = path.resolve(__dirname, '../playground/')
+
+for (const projectName of fs.readdirSync(playgroundDir)) {
+  if (projectName.endsWith('with-tests')) {
+    cd(path.resolve(playgroundDir, projectName))
+
+    console.log(`Running unit tests in ${projectName}`)
+    await $`pnpm test:unit:ci`
+
+    console.log(`Building ${projectName}`)
+    await $`pnpm build`
+
+    console.log(`Running e2e tests in ${projectName}`)
+    await $`pnpm test:e2e:ci`
+  }
+}
diff --git a/test.js b/test.js
deleted file mode 100644 (file)
index c80ebd3..0000000
--- a/test.js
+++ /dev/null
@@ -1,42 +0,0 @@
-import fs from 'fs'
-import path from 'path'
-import { fileURLToPath } from 'url'
-
-import { spawnSync } from 'child_process'
-
-const __dirname = path.dirname(fileURLToPath(import.meta.url))
-const playgroundDir = path.resolve(__dirname, './playground/')
-
-for (const projectName of fs.readdirSync(playgroundDir)) {
-  if (projectName.endsWith('with-tests')) {
-    console.log(`Running unit tests in ${projectName}`)
-    const unitTestResult = spawnSync('pnpm', ['test:unit:ci'], {
-      cwd: path.resolve(playgroundDir, projectName),
-      stdio: 'inherit',
-      shell: true
-    })
-    if (unitTestResult.status !== 0) {
-      throw new Error(`Unit tests failed in ${projectName}`)
-    }
-
-    console.log(`Building ${projectName}`)
-    const buildResult = spawnSync('pnpm', ['build'], {
-      cwd: path.resolve(playgroundDir, projectName),
-      stdio: 'inherit',
-      shell: true
-    })
-    if (buildResult.status !== 0) {
-      throw new Error(`Build failed in ${projectName}`)
-    }
-
-    console.log(`Running e2e tests in ${projectName}`)
-    const e2eTestResult = spawnSync('pnpm', ['test:e2e:ci'], {
-      cwd: path.resolve(playgroundDir, projectName),
-      stdio: 'inherit',
-      shell: true
-    })
-    if (e2eTestResult.status !== 0) {
-      throw new Error(`E2E tests failed in ${projectName}`)
-    }
-  }
-}