Skip to content

Commit

Permalink
add guides-search command
Browse files Browse the repository at this point in the history
  • Loading branch information
mansona committed Dec 10, 2024
1 parent 5caca49 commit 5d3ea1d
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const pkg = JSON.parse(
);

import guides from './projects/guides.js';
import guidesSearch from './projects/guides-search.js';

program
.name(pkg.name)
Expand All @@ -30,4 +31,14 @@ program
}),
);

program
.command('guides-search')
.description('Update Algolia indexes for https://guides.emberjs.com')
.action((args, commandOptions) =>
guidesSearch(args, {
...program.opts(),
...commandOptions,
}),
);

program.parse();
88 changes: 88 additions & 0 deletions projects/guides-search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import ensureRepo from './lib/ensure-repo.js';
import { readdir, readFile } from 'node:fs/promises';
import { parse, stringify } from 'yaml';
import { automated } from './lib/log.js';
import { dryExeca } from './lib/dry-execa.js';
import enq from 'enquirer';
import dryWrite from './lib/dry-write.js';

const { Invisible } = enq;

export default async function guides(args, options) {
const dryRun = options.dryRun ?? false;

await ensureRepo(
'[email protected]:ember-learn/guides-source.git',
'master',
dryRun,
);

const versionsFile = await parse(
await readFile(`./guides/versions.yml`, 'utf-8'),
);
const currentVersion = versionsFile.currentVersion;

automated('Removing guides.');
const guidesFolders = await readdir('./guides');
for (let folder of guidesFolders) {
if (folder.startsWith('v')) {
await dryExeca(`rm -rf ./guides/${folder}`, dryRun);
}
}

automated('Removing pre-built guides.');
const publicFolders = await readdir('./public');
for (let folder of publicFolders) {
if (folder.startsWith('v')) {
await dryExeca(`rm -rf ./public/${folder}`, dryRun);
}
}

const keyPrompt = new Invisible({
name: 'apiKey',
message: `Go to https://dashboard.algolia.com/account/api-keys/all?applicationId=Y1OMR4C7MF"
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)`,
});

const apiKey = await keyPrompt.run();

automated('Writing ./config/credentials.json');
dryWrite(
`./config/credentials.json`,
`{
"algoliaKey": "${apiKey}",
"algoliaIndex": "ember-guides",
"algoliaApplication": "Y1OMR4C7MF"
}`,
dryRun,
);

automated('Pruning allVersions in ./guides/versions.yml');
versionsFile.allVersions = [currentVersion];
dryWrite('./guides/versions.yml', stringify(versionsFile), dryRun);

const deployConfig = await readFile('./config/deploy.js', 'utf-8');

automated('Deleting versionsToIgnore in ./config/deploy.js');
dryWrite(
'./config/deploy.js',
deployConfig.replace(/versionsToIgnore.*/, ''),
dryRun,
);

// echo
automated('Deleting dist folder');
await dryExeca('rm -rf dist', dryRun);

// echo
automated('Deleting tmp folder');
await dryExeca('rm -rf tmp', dryRun);

// echo
automated('Deploying');
await dryExeca('pnpm i', dryRun);
await dryExeca('ember deploy production', dryRun);

automated('Restoring branch.');
await dryExeca('git reset --hard', dryRun);
}

0 comments on commit 5d3ea1d

Please sign in to comment.