Skip to content
Open
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,6 @@ lambdas/
emails/

*.swp


.fa/
92 changes: 90 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"build": "tsc && npm run copy-files",
"copy-files": "cp -r ./src/resources/ ./dist/commands/resources/",
"prepublishOnly": "npm run build",
"postinstall": "test -f dist/postinstall.js && node dist/postinstall.js || true",
"start": "node --no-warnings=ExperimentalWarning --loader ts-node/esm src/index.ts",
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand Down Expand Up @@ -49,6 +50,7 @@
"log-symbols": "5.1.0",
"log-update": "5.0.1",
"merge": "2.1.1",
"posthog-node": "^5.21.2",
"queue": "7.0.0",
"remove-undefined-objects": "3.0.0",
"uuid": "9.0.0",
Expand Down
4 changes: 3 additions & 1 deletion src/commands/check-common-config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Command, Option} from "@commander-js/extra-typings";
import {FusionAuthClient} from '@fusionauth/typescript-client';
import chalk from "chalk";
import {errorAndExit} from '../utils.js';
import {errorAndExit, logEvent} from '../utils.js';
import {apiKeyOption, hostOption} from "../options.js";

interface CheckResult {
Expand All @@ -19,6 +19,8 @@ const action = async function ({key: apiKey, host, skipLicenseCheck}: {
host: string;
skipLicenseCheck: boolean;
}) {
logEvent('cli command check:common-config')

console.log(chalk.blue(`Checking common configuration on ${host}...`));

const results: CheckResult[] = [];
Expand Down
3 changes: 3 additions & 0 deletions src/commands/email-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ import {Command} from "@commander-js/extra-typings";
import {ensureDir, ensureFile} from "fs-extra";
import {v4} from "uuid";
import chalk from "chalk";
import { logEvent } from "../utils.js";

// noinspection JSUnusedGlobalSymbols
export const emailCreate = new Command('email:create')
.description('Create an email template in FusionAuth')
.option('-o, --output <output>', 'The output directory', './emails/')
.option('-l, --locales <locales...>', 'The locales to create.', [])
.action(async ({output, locales}) => {
logEvent('cli command email:create')

console.log(`Creating email template in ${output}`);

const emailTemplateId = v4();
Expand Down
3 changes: 2 additions & 1 deletion src/commands/email-download.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Command} from "@commander-js/extra-typings";
import {getEmailErrorMessage, getEmailSuccessMessage, reportError} from "../utils.js";
import {getEmailErrorMessage, getEmailSuccessMessage, logEvent, reportError} from "../utils.js";
import {EmailTemplate, FusionAuthClient} from "@fusionauth/typescript-client";
import {mkdir, writeFile} from "fs/promises";
import chalk from "chalk";
Expand All @@ -16,6 +16,7 @@ export const emailDownload = new Command('email:download')
.addOption(hostOption)
.option('-c, --clean', 'Clean the output directory before downloading', false)
.action(async (emailTemplateId, {output, key: apiKey, host, clean}) => {
logEvent('cli command email:download')

let clientResponse;
const errorMessage = getEmailErrorMessage('download', emailTemplateId);
Expand Down
3 changes: 3 additions & 0 deletions src/commands/email-duplicate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ import {Command} from "@commander-js/extra-typings";
import {copy} from "fs-extra";
import {v4} from "uuid";
import chalk from "chalk";
import { logEvent } from "../utils.js";

// noinspection JSUnusedGlobalSymbols
export const emailDuplicate = new Command('email:duplicate')
.description('Duplicate an email template')
.argument('<emailTemplateId>', 'The email template id to duplicate')
.option('-o, --output <output>', 'The output directory', './emails/')
.action(async (emailTemplateId: string, {output}) => {
logEvent('cli command email:duplicate')

console.log(`Duplicating email template ${emailTemplateId} in ${output}`);

const newEmailTemplateId = v4();
Expand Down
3 changes: 3 additions & 0 deletions src/commands/email-html-to-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {validate as isUUID} from "uuid";
import chalk from "chalk";
import {lstat, readdir, readFile, writeFile} from "fs/promises";
import {compile} from "html-to-text";
import { logEvent } from "../utils.js";

const htmlToText = compile({
wordwrap: false,
Expand All @@ -17,6 +18,8 @@ export const emailHtmlToText = new Command('email:html-to-text')
.argument('[emailTemplateId]', 'The email template id to convert. If not provided, all email templates will be converted')
.option('-o, --output <output>', 'The output directory', './emails/')
.action(async (emailTemplateId: string | undefined, {output}) => {
logEvent('cli command email:html-to-text')

if (!emailTemplateId) {
console.log(`Converting all email templates in ${output}`);
} else {
Expand Down
4 changes: 3 additions & 1 deletion src/commands/email-upload.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Command} from "@commander-js/extra-typings";
import {getEmailErrorMessage, reportError} from "../utils.js";
import {getEmailErrorMessage, logEvent, reportError} from "../utils.js";
import {EmailTemplate, EmailTemplateRequest, FusionAuthClient} from "@fusionauth/typescript-client";
import {pathExists} from "fs-extra";
import {lstat, readdir, readFile} from "fs/promises";
Expand All @@ -24,6 +24,8 @@ export const emailUpload = new Command('email:upload')
.option('-o, --overwrite', 'Overwrite the existing email template with the new one. F.e. locales that are not defined in the directory, but on the FusionAuth server will be removed.', false)
.option('--no-create', 'Create the email template if it does not exist')
.action(async (emailTemplateId, {input, key: apiKey, host, overwrite, create}) => {
logEvent('cli command email:upload')

const errorMessage = getEmailErrorMessage('uploading', emailTemplateId);

if (emailTemplateId) {
Expand Down
4 changes: 3 additions & 1 deletion src/commands/email-watch.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Command} from "@commander-js/extra-typings";
import {reportError} from "../utils.js";
import {logEvent, reportError} from "../utils.js";
import {watch} from "chokidar";
import Queue from "queue";
import logUpdate from "log-update";
Expand Down Expand Up @@ -40,6 +40,8 @@ export const emailWatch = new Command('email:watch')
.addOption(apiKeyOption)
.addOption(hostOption)
.action(async ({input, key: apiKey, host}) => {
logEvent('cli command email:watch')

console.log(`Watching email templates in ${input}`);

const watchedFiles = [
Expand Down
4 changes: 3 additions & 1 deletion src/commands/import-generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {FusionAuthClient} from '@fusionauth/typescript-client';
import {readFile} from 'fs/promises';
import chalk from 'chalk';
import {join} from 'path';
import {errorAndExit} from '../utils.js';
import {errorAndExit, logEvent} from '../utils.js';
import { faker } from '@faker-js/faker';
import * as fs from 'fs';

Expand All @@ -17,6 +17,8 @@ const action = async function ({numberOfFiles, countPerFile, applicationId, grou
filePrefix?: string | undefined;
}
): Promise<void> {
logEvent('cli command import:generate')

console.log(`Generating users`);
try {
const finalNumberOfFiles = (numberOfFiles !== undefined ? parseInt(numberOfFiles) : 10);
Expand Down
2 changes: 2 additions & 0 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export * from './lambda-delete.js';
export * from './lambda-retrieve.js';
export * from './message-download.js';
export * from './message-upload.js';
export * from './telemetry-disable.js';
export * from './telemetry-enable.js';
export * from './theme-watch.js';
export * from './theme-upload.js';
export * from './theme-download.js';
Expand Down
4 changes: 3 additions & 1 deletion src/commands/kickstart-install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import fs from 'node:fs'
import path from "node:path";
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { betaWarning, isDirEmpty, isDockerInstalled } from "../utils.js";
import { betaWarning, isDirEmpty, isDockerInstalled, logEvent } from "../utils.js";

const __dirname = dirname(fileURLToPath(import.meta.url));

Expand All @@ -32,6 +32,8 @@ async function createKickstart(kickstartPath: string, answers: any, newDir: stri
const action = async function (dir: string) {
const dockerInstalled = isDockerInstalled();
const directory = path.resolve(dir)
logEvent('cli command kickstart:install')

betaWarning()

try {
Expand Down
5 changes: 3 additions & 2 deletions src/commands/kickstart-kill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Command } from "@commander-js/extra-typings";
import chalk from "chalk";

import { spawn } from 'node:child_process';
import { betaWarning, isDockerInstalled } from "../utils.js";
import { betaWarning, isDockerInstalled, logEvent } from "../utils.js";
import boxen from "boxen";
import inquirer from "inquirer";

Expand All @@ -14,6 +14,7 @@ const action = async function () {
if (!isDockerInstalled()) throw (chalk.red('Error: You need Docker to run.'))

if (process.cwd() != process.env.CLI_DIR) throw(chalk.red('Error: Current directory was not kickstarted.'))
logEvent('cli command kickstart:kill')

inquirer.prompt([
{
Expand Down Expand Up @@ -60,6 +61,6 @@ const action = async function () {
}

export const kickstartKill = new Command()
.description('Runs docker compose down in current directory')
.command('kickstart:kill')
.description('Runs docker compose down in current directory')
.action(action)
3 changes: 2 additions & 1 deletion src/commands/kickstart-start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Command } from "@commander-js/extra-typings";
import chalk from "chalk";

import { spawn } from 'node:child_process';
import { betaWarning, isDockerInstalled } from "../utils.js";
import { betaWarning, isDockerInstalled, logEvent } from "../utils.js";
import 'dotenv/config';
import boxen from "boxen";
import yoctoSpinner from "yocto-spinner";
Expand All @@ -16,6 +16,7 @@ const action = async function () {
if (process.cwd() != process.env.CLI_DIR) throw (chalk.red('Error: Current directory was not kickstarted.'))

if (!isDockerInstalled()) console.error(chalk.red('Error: You need Docker to run.'))
logEvent('cli command kickstart:start')

const starting = spawn('docker compose up -d', { shell: true, stdio: 'inherit' })
starting.on('error', e => {
Expand Down
Loading