Skip to content

add guides-search command #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
Loading