Skip to content

Commit

Permalink
Merge pull request #18 from flexn-io/chore/rnv_upgrade
Browse files Browse the repository at this point in the history
Chore/rnv upgrade
  • Loading branch information
pavjacko committed Apr 15, 2024
2 parents 3fd6805 + 85021c7 commit 31fcb38
Show file tree
Hide file tree
Showing 27 changed files with 5,206 additions and 5,488 deletions.
92 changes: 45 additions & 47 deletions buildHooks/src/genApiCli.ts
Expand Up @@ -2,8 +2,9 @@ import {
writeFileSync,
logHook,
registerAllPlatformEngines,
getAllSuitableTasks,
getRegisteredTasks,
RnvTaskOptionPresets,
RnvTask,
} from '@rnv/core';
import path from 'path';

Expand All @@ -16,25 +17,16 @@ const kebabToTitleCase = (string: string): string => {
.join(' ');
};

const toKebabCase = (string: string): string => {
return string.trim().toLocaleLowerCase().split(' ').join('-');
};

export const generateDocsApiCli = async (c) => {
logHook('generateDocsApiCli');

registerAllPlatformEngines(c);
registerAllPlatformEngines();

const tasks = getAllSuitableTasks(c);

// console.log('tasks', tasks);
const tasksGroupedByCommand = Object.values(tasks).reduce((acc, task: any) => {
if (!acc[task.command]) {
acc[task.command] = {};
}
if (task.subCommand) {
acc[task.command][task.subCommand] = task;
} else {
acc[task.command] = task;
}
return acc;
}, {});
const registeredTasks = getRegisteredTasks();

const header = `---
id: cli
Expand All @@ -47,57 +39,63 @@ sidebar_label: rnv CLI

content += `## Commands\n\n`;

const printTaskDetails = (tsk, cmd, param?) => {
content += param ? `#### ${param}\n\n` : '';
const printTaskDetails = (registeredTask: RnvTask) => {
const { description, ownerID, dependsOn, task, options } = registeredTask;

content += `${tsk.description}\n\n`;
content += `${description}\n\n`;

// Engines/Providers
if (tsk.providers?.length) {
const provs = tsk.providers.map((v) => `[${v}](engines/${v}.md)`);

content += `Available in engines: ${provs.join(', ')}\n\n`;
content += `Provided by: ${ownerID}\n\n`;

// Depends On
if (dependsOn?.length > 0) {
content += `Depends On:\n`;
const toDisplay: string[] = [];
dependsOn?.forEach((task) => {
toDisplay.push(`[\`${task}\`](#${toKebabCase(task)})`);
});
content += toDisplay.join(', ');
content += `\n\n`;
}

// options
content += `\nAvailable Options:\n`;
const toDisplay: string[] = [];
tsk.params?.forEach((param) => {
toDisplay.push(`[\`${param.key}\`](#${param.key.toLowerCase()})`);
});
content += toDisplay.join(', ');
content += `\n\n`;
if (options?.length > 0) {
content += `\nAvailable Options:\n`;
const toDisplay: string[] = [];
options?.forEach((param) => {
toDisplay.push(`[\`${param.key}\`](#${toKebabCase(param.key)})`);
});
content += toDisplay.join(', ');
content += `\n\n`;
}

//Example
let exCmd = param ? `${cmd} ${param}` : cmd;
content += `Example:\n\`\`\`bash\nnpx rnv ${exCmd}\n\`\`\``;
content += `Example:\n\`\`\`bash\nnpx rnv ${task}\n\`\`\``;
content += '\n\n';
};

Object.keys(tasksGroupedByCommand).forEach((command) => {
content += `### ${command}\n\n`;
Object.values(registeredTasks).forEach((registeredTask) => {
content += `### ${registeredTask.task}\n\n`;

const subCommandsOrTask = tasksGroupedByCommand[command];

if (subCommandsOrTask.command) {
// it's a task
printTaskDetails(subCommandsOrTask, command);
} else {
Object.keys(subCommandsOrTask).forEach((subCommand) => {
const task = subCommandsOrTask[subCommand];
printTaskDetails(task, command, task.subCommand);
});
}
printTaskDetails(registeredTask);
});

// CLI options
content += `## Options\n\n`;
RnvTaskOptionPresets.withAll().forEach((param) => {
content += `### ${param.key}\n`;
content += `${param.description}\n\n`;
// content += `Required: ${param.isRequired ? 'Yes' : 'No'}\n\n`;
if (param.shortcut) content += `Shortcut: \`\`-${param.shortcut}\`\`\n\n`;
if (param.value) content += `Value: \`\`${param.value}\`\`\n\n`;
const type = param.isValueType ? 'Value' : param.isVariadic ? 'Variadic' : 'Flag';
content += `Type: ${type}${param.isRequired ? ', required' : ''}\n\n`;

// Example
if (param.examples) {
content += `Examples:\n`;
param.examples.forEach((example) => {
content += `\`\`\`bash\nnpx rnv ${example}\n\`\`\`\n`;
});
}
});

writeFileSync(path.join(c.paths.project.dir, `/docs/api/cli.md`), header + content);
Expand Down
29 changes: 9 additions & 20 deletions buildHooks/src/genApiSchema.ts
@@ -1,44 +1,33 @@
import {
RootAppSchema,
RootEngineSchema,
RootGlobalSchema,
RootIntegrationSchema,
RootLocalSchema,
RootPluginSchema,
RootPluginsSchema,
RootPrivateSchema,
RootProjectSchema,
RootTemplateSchema,
RootTemplatesSchema,
getContext,
logSuccess,
} from '@rnv/core';
import { ZodFileSchema, getContext, logSuccess } from '@rnv/core';
import { zodToJsonSchema } from 'zod-to-json-schema';
import { z } from 'zod';
import path from 'path';
import fs from 'fs';

const { zodConfigFileApp, zodConfigFileProject, zodConfigFileTemplate, zodConfigFilePlugin, zodConfigFileIntegration } =
ZodFileSchema;

export const generateSchema = async () => {
_generateSchemaFile({
schema: RootProjectSchema,
schema: zodConfigFileProject,
schemaId: 'rnv.project',
sideBarTitle: 'renative.json (Project Config)',
});
_generateSchemaFile({ schema: RootAppSchema, schemaId: 'rnv.app', sideBarTitle: 'renative.json (App Config)' });
_generateSchemaFile({ schema: zodConfigFileApp, schemaId: 'rnv.app', sideBarTitle: 'renative.json (App Config)' });
// _generateSchemaFile({ schema: RootLocalSchema, schemaId: 'rnv.local' });
// _generateSchemaFile({ schema: RootEngineSchema, schemaId: 'rnv.engine' });
// _generateSchemaFile({ schema: RootGlobalSchema, schemaId: 'rnv.global' });
// _generateSchemaFile({ schema: RootPluginsSchema, schemaId: 'rnv.plugins' });
_generateSchemaFile({
schema: RootTemplateSchema,
schema: zodConfigFileTemplate,
schemaId: 'rnv.template',
sideBarTitle: 'renative.template.json (Template Config)',
});
// _generateSchemaFile({ schema: RootPrivateSchema, schemaId: 'rnv.private' });
_generateSchemaFile({ schema: RootPluginSchema, schemaId: 'rnv.plugin', sideBarTitle: 'renative.plugin.json' });
_generateSchemaFile({ schema: zodConfigFilePlugin, schemaId: 'rnv.plugin', sideBarTitle: 'renative.plugin.json' });
// _generateSchemaFile({ schema: RootTemplatesSchema, schemaId: 'rnv.templates' });
_generateSchemaFile({
schema: RootIntegrationSchema,
schema: zodConfigFileIntegration,
schemaId: 'rnv.integration',
sideBarTitle: 'renative.integration.json',
});
Expand Down
8 changes: 4 additions & 4 deletions buildHooks/src/genReferenceEngines.ts
Expand Up @@ -3,7 +3,7 @@ import {
registerAllPlatformEngines,
RnvContext,
RnvEngine,
PlatformKey,
RnvPlatformKey,
RnvEnginePlatform,
} from '@rnv/core';
import path from 'path';
Expand All @@ -12,7 +12,7 @@ import fs from 'fs';
const cleanUrl = (v: string) => v.replace('@', '').replace('/', '');

export const updateMdFilesEngines = async (c: RnvContext) => {
registerAllPlatformEngines(c);
registerAllPlatformEngines();
const engines = c.runtime.enginesById;

Object.values(engines).forEach((engine) => {
Expand All @@ -35,7 +35,7 @@ const _generateEngineDoc = (c: RnvContext, engine: RnvEngine) => {

if (enginePlatforms) {
Object.keys(enginePlatforms).forEach((v) => {
const pKey = v as PlatformKey;
const pKey = v as RnvPlatformKey;
const engPlatform = enginePlatforms?.[pKey];
if (engPlatform) {
const npm = engineConfigPlatforms?.[pKey]?.npm;
Expand Down Expand Up @@ -107,7 +107,7 @@ ${extContent}
writeFileSync(docFilePath, fixedFile);
};

const _getExtensionContent = (platform: PlatformKey, engine: RnvEngine) => {
const _getExtensionContent = (platform: RnvPlatformKey, engine: RnvEngine) => {
let out = '';
let p: RnvEnginePlatform | undefined;
if (engine?.platforms?.[platform]) {
Expand Down
2 changes: 1 addition & 1 deletion buildHooks/src/genReferencePlatforms.ts
Expand Up @@ -32,7 +32,7 @@ ${extContent}
const _getExtensionContent = (c: RnvContext, platform) => {
let out = `Extenstions are defined via engines. Engines with ${platform} support: \n`;

registerAllPlatformEngines(c);
registerAllPlatformEngines();
const engines = c.runtime.enginesById;

Object.values(engines).forEach((engine) => {
Expand Down
6 changes: 3 additions & 3 deletions buildHooks/src/genReferencePlugins.ts
@@ -1,4 +1,4 @@
import { doResolve, readObjectSync, fsExistsSync, writeFileSync, SUPPORTED_PLATFORMS, PlatformKey } from '@rnv/core';
import { doResolve, readObjectSync, fsExistsSync, writeFileSync, RnvPlatforms, RnvPlatformKey } from '@rnv/core';
import merge from 'deepmerge';
import path from 'path';

Expand Down Expand Up @@ -34,9 +34,9 @@ sidebar_label: Plugins
const npm = plugin.version ? `Npm: https://www.npmjs.com/package/${key}` : '';
const version = plugin.version ? `Version: \`${plugin.version}\`` : '';
const platforms = Object.keys(plugin)
.map((v) => (SUPPORTED_PLATFORMS.includes(v as PlatformKey) ? v : null))
.map((v) => (RnvPlatforms.includes(v as RnvPlatformKey) ? v : null))
.filter((v) => v);
const supPlats = platforms.length ? platforms : SUPPORTED_PLATFORMS;
const supPlats = platforms.length ? platforms : RnvPlatforms;
const deprecated = plugin.deprecated ? `> ${plugin.deprecated}` : '';
const props = plugin.props ? `Props: ${Object.keys(plugin.props).map((v) => `\`${v}\``)}` : '';

Expand Down
4 changes: 2 additions & 2 deletions config.next.json
Expand Up @@ -55,12 +55,12 @@
"type"
],
"ranking": [
"exact",
"words",
"filters",
"typo",
"attribute",
"proximity"
"proximity",
"exact"
]
}
}

0 comments on commit 31fcb38

Please sign in to comment.