Commit 2967377

Anton Medvedev <anton@medv.io>
2022-06-09 08:58:55
Update examples
1 parent 4e786e4
examples/background-process.mjs
@@ -14,9 +14,9 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-let serve = $`npx serve`
+const serve = $`npx serve`
 
-for await (let chunk of serve.stdout) {
+for await (const chunk of serve.stdout) {
   if (chunk.includes('Accepting connections')) break
 }
 
examples/backup-github.mjs
@@ -14,8 +14,8 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-let username = await question('What is your GitHub username? ')
-let token = await question('Do you have GitHub token in env? ', {
+const username = await question('What is your GitHub username? ')
+const token = await question('Do you have GitHub token in env? ', {
   choices: Object.keys(process.env),
 })
 
@@ -29,14 +29,14 @@ let res = await fetch(
   `https://api.github.com/users/${username}/repos?per_page=1000`,
   { headers }
 )
-let data = await res.json()
-let urls = data.map((x) =>
+const data = await res.json()
+const urls = data.map((x) =>
   x.git_url.replace('git://github.com/', 'git@github.com:')
 )
 
 await $`mkdir -p backups`
 cd('./backups')
 
-for (let url of urls) {
+for (const url of urls) {
   await $`git clone ${url}`
 }
examples/interactive.mjs
@@ -14,17 +14,17 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-let { stdin, stdout } = $`npm init`
+const p = $`npm init`.stdio('pipe')
 
-for await (let chunk of stdout) {
-  if (chunk.includes('package name:')) stdin.write('test\n')
-  if (chunk.includes('version:')) stdin.write('1.0.0\n')
-  if (chunk.includes('description:')) stdin.write('My test package\n')
-  if (chunk.includes('entry point:')) stdin.write('index.mjs\n')
-  if (chunk.includes('test command:')) stdin.write('test.mjs\n')
-  if (chunk.includes('git repository:')) stdin.write('my-org/repo\n')
-  if (chunk.includes('keywords:')) stdin.write('foo, bar\n')
-  if (chunk.includes('author:')) stdin.write('Anton Medvedev\n')
-  if (chunk.includes('license:')) stdin.write('MIT\n')
-  if (chunk.includes('Is this OK?')) stdin.write('yes\n')
+for await (const chunk of p.stdout) {
+  if (chunk.includes('package name:')) p.stdin.write('test\n')
+  if (chunk.includes('version:')) p.stdin.write('1.0.0\n')
+  if (chunk.includes('description:')) p.stdin.write('My test package\n')
+  if (chunk.includes('entry point:')) p.stdin.write('index.mjs\n')
+  if (chunk.includes('test command:')) p.stdin.write('test.mjs\n')
+  if (chunk.includes('git repository:')) p.stdin.write('my-org/repo\n')
+  if (chunk.includes('keywords:')) p.stdin.write('foo, bar\n')
+  if (chunk.includes('author:')) p.stdin.write('Anton Medvedev\n')
+  if (chunk.includes('license:')) p.stdin.write('MIT\n')
+  if (chunk.includes('Is this OK?')) p.stdin.write('yes\n')
 }
examples/parallel.mjs
@@ -16,10 +16,10 @@
 
 import { spinner } from 'zx/experimental'
 
-let tests = await glob('test/*.test.js')
+const tests = await glob('test/*.test.js')
 await spinner('running tests', async () => {
   try {
-    let res = await Promise.all(tests.map((file) => $`npx uvu . ${file}`))
+    const res = await Promise.all(tests.map((file) => $`npx uvu . ${file}`))
     res.forEach((r) => console.log(r.toString()))
     console.log(chalk.bgGreen.black(' SUCCESS '))
   } catch (e) {