|
| 1 | +import ensureRepo from './lib/ensure-repo.js'; |
| 2 | +import { readdir, readFile } from 'node:fs/promises'; |
| 3 | +import { parse, stringify } from 'yaml'; |
| 4 | +import { automated } from './lib/log.js'; |
| 5 | +import { dryExeca } from './lib/dry-execa.js'; |
| 6 | +import enq from 'enquirer'; |
| 7 | +import dryWrite from './lib/dry-write.js'; |
| 8 | + |
| 9 | +const { Invisible } = enq; |
| 10 | + |
| 11 | +export default async function guides(args, options) { |
| 12 | + const dryRun = options.dryRun ?? false; |
| 13 | + |
| 14 | + await ensureRepo( |
| 15 | + '[email protected]:ember-learn/guides-source.git', |
| 16 | + 'master', |
| 17 | + dryRun, |
| 18 | + ); |
| 19 | + |
| 20 | + const versionsFile = await parse( |
| 21 | + await readFile(`./guides/versions.yml`, 'utf-8'), |
| 22 | + ); |
| 23 | + const currentVersion = versionsFile.currentVersion; |
| 24 | + |
| 25 | + automated('Removing guides.'); |
| 26 | + const guidesFolders = await readdir('./guides'); |
| 27 | + for (let folder of guidesFolders) { |
| 28 | + if (folder.startsWith('v')) { |
| 29 | + await dryExeca(`rm -rf ./guides/${folder}`, dryRun); |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + automated('Removing pre-built guides.'); |
| 34 | + const publicFolders = await readdir('./public'); |
| 35 | + for (let folder of publicFolders) { |
| 36 | + if (folder.startsWith('v')) { |
| 37 | + await dryExeca(`rm -rf ./public/${folder}`, dryRun); |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + const keyPrompt = new Invisible({ |
| 42 | + name: 'apiKey', |
| 43 | + message: `Go to https://dashboard.algolia.com/account/api-keys/all?applicationId=Y1OMR4C7MF" |
| 44 | +Copy the Write API Key with the copy button beside the obfuscated key and paste it below (note it won't seem like you're pasting)`, |
| 45 | + }); |
| 46 | + |
| 47 | + const apiKey = await keyPrompt.run(); |
| 48 | + |
| 49 | + automated('Writing ./config/credentials.json'); |
| 50 | + dryWrite( |
| 51 | + `./config/credentials.json`, |
| 52 | + `{ |
| 53 | + "algoliaKey": "${apiKey}", |
| 54 | + "algoliaIndex": "ember-guides", |
| 55 | + "algoliaApplication": "Y1OMR4C7MF" |
| 56 | +}`, |
| 57 | + dryRun, |
| 58 | + ); |
| 59 | + |
| 60 | + automated('Pruning allVersions in ./guides/versions.yml'); |
| 61 | + versionsFile.allVersions = [currentVersion]; |
| 62 | + dryWrite('./guides/versions.yml', stringify(versionsFile), dryRun); |
| 63 | + |
| 64 | + const deployConfig = await readFile('./config/deploy.js', 'utf-8'); |
| 65 | + |
| 66 | + automated('Deleting versionsToIgnore in ./config/deploy.js'); |
| 67 | + dryWrite( |
| 68 | + './config/deploy.js', |
| 69 | + deployConfig.replace(/versionsToIgnore.*/, ''), |
| 70 | + dryRun, |
| 71 | + ); |
| 72 | + |
| 73 | + // echo |
| 74 | + automated('Deleting dist folder'); |
| 75 | + await dryExeca('rm -rf dist', dryRun); |
| 76 | + |
| 77 | + // echo |
| 78 | + automated('Deleting tmp folder'); |
| 79 | + await dryExeca('rm -rf tmp', dryRun); |
| 80 | + |
| 81 | + // echo |
| 82 | + automated('Deploying'); |
| 83 | + await dryExeca('pnpm i', dryRun); |
| 84 | + await dryExeca('ember deploy production', dryRun); |
| 85 | + |
| 86 | + automated('Restoring branch.'); |
| 87 | + await dryExeca('git reset --hard', dryRun); |
| 88 | +} |
0 commit comments