Skip to content

feat(cli): add message when all files compile successfully in nango dev #3908

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 19 commits into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
c421e08
feat(cli): add message when all files compile successfully in `nango …
kaposke Apr 15, 2025
acfd2bd
Merge remote-tracking branch 'origin/master' into gui/NAN-2985/feat-s…
kaposke Apr 15, 2025
cb0b18f
fix remaining usages of `compileAllFiles`
kaposke Apr 15, 2025
aec281d
Merge remote-tracking branch 'origin/master' into gui/NAN-2985/feat-s…
kaposke Apr 15, 2025
d3c3464
fix new tests
kaposke Apr 15, 2025
b870c14
Add missing failedFiles push
kaposke Apr 16, 2025
ae2334f
Add missing `chalk.red`
kaposke Apr 16, 2025
3ea6d9e
refactor .then
kaposke Apr 16, 2025
d6370fa
Change success message
kaposke Apr 16, 2025
b4846a1
Merge branch 'master' into gui/NAN-2985/feat-successful-compilation-m…
kaposke Apr 16, 2025
6f97a66
Don't revalidate yaml file on single file compilation
kaposke Apr 22, 2025
5dc4254
Handle file deletion
kaposke Apr 22, 2025
042f8b5
Merge branch 'master' into gui/NAN-2985/feat-successful-compilation-m…
kaposke Apr 22, 2025
182b737
Merge remote-tracking branch 'origin/master' into gui/NAN-2985/feat-s…
kaposke Apr 23, 2025
8c638bd
fix deploy service usage of compilaAllFiles
kaposke Apr 23, 2025
664dddf
Don't consider skipped files are failed
kaposke Apr 23, 2025
1aebd12
Merge branch 'master' into gui/NAN-2985/feat-successful-compilation-m…
kaposke Apr 23, 2025
8f3a088
Merge branch 'master' into gui/NAN-2985/feat-successful-compilation-m…
kaposke Apr 24, 2025
fc60d91
Merge branch 'master' into gui/NAN-2985/feat-successful-compilation-m…
kaposke Apr 24, 2025
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"test:unit": "vitest",
"test:integration": "vitest --config ./vite.integration.config.ts",
"test:cli": "vitest --config ./vite.cli.config.ts",
"test:cli:update-snapshots": "vitest --config ./vite.cli.config.ts --update",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note you can just press u when running tests to update snapshots

"test:openapi": "npx @apidevtools/swagger-cli validate docs-v2/spec.yaml",
"test:providers": "npx tsx scripts/validation/providers/validate.ts",
"docs": "tsx scripts/docs-gen-snippets.ts && cd ./docs-v2 && npx mintlify dev --port 3033",
Expand Down
80 changes: 0 additions & 80 deletions packages/cli/lib/__snapshots__/sync.unit.cli-test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -92,83 +92,3 @@ models:
__extends: GithubIssue
"
`;

exports[`generate function tests > should init the expected files in the nango-integrations directory 1`] = `
"// ---------------------------
// This file was generated by Nango (vTest)
// You can version this file
// ---------------------------

export interface GithubIssue {
id: number;
owner: string;
repo: string;
issue_number: number;
title: string;
author: string;
author_id: string;
state: string;
date_created: Date;
date_last_modified: Date;
};
"
`;

exports[`generate function tests > should init the expected files in the nango-integrations directory 2`] = `
"{
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"GithubIssue": {
"type": "object",
"properties": {
"id": {
"type": "number"
},
"owner": {
"type": "string"
},
"repo": {
"type": "string"
},
"issue_number": {
"type": "number"
},
"title": {
"type": "string"
},
"author": {
"type": "string"
},
"author_id": {
"type": "string"
},
"state": {
"type": "string"
},
"date_created": {
"type": "string",
"format": "date-time"
},
"date_last_modified": {
"type": "string",
"format": "date-time"
}
},
"required": [
"id",
"owner",
"repo",
"issue_number",
"title",
"author",
"author_id",
"state",
"date_created",
"date_last_modified"
],
"additionalProperties": false
}
},
"$comment": "This file was generated by Nango (vTest)"
}"
`;
95 changes: 73 additions & 22 deletions packages/cli/lib/cli.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import fs from 'node:fs';
import path, { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';

import chalk from 'chalk';
import chokidar from 'chokidar';
import ejs from 'ejs';
import * as dotenv from 'dotenv';
import ejs from 'ejs';

import { getProviderConfigurationFromPath, nangoConfigFile } from '@nangohq/nango-yaml';

import { getNangoRootPath, printDebug } from './utils.js';
import { loadYamlAndGenerate } from './services/model.service.js';
import { TYPES_FILE_NAME, exampleSyncName } from './constants.js';
import { compileAllFiles, compileSingleFile, getFileToCompile } from './services/compile.service.js';
import { loadYamlAndGenerate } from './services/model.service.js';
import { getLayoutMode } from './utils/layoutMode.js';
import { getProviderConfigurationFromPath, nangoConfigFile } from '@nangohq/nango-yaml';
import { getNangoRootPath, printDebug } from './utils.js';
import { NANGO_VERSION } from './version.js';

import type { NangoYamlParsed } from '@nangohq/types';

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

Expand Down Expand Up @@ -129,14 +133,19 @@ export function generate({ fullPath, debug = false }: { fullPath: string; debug?
}
}

export function tscWatch({ fullPath, debug = false }: { fullPath: string; debug?: boolean }) {
const tsconfig = fs.readFileSync(path.resolve(getNangoRootPath(), 'tsconfig.dev.json'), 'utf8');
const parsed = loadYamlAndGenerate({ fullPath, debug });
if (!parsed) {
return;
function showCompilationMessage(failedFiles: Set<string>) {
if (failedFiles.size === 0) {
console.log(chalk.green('No compilation errors.'));
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure you need a function for that. Inlining the if would be good enough imho

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that's a NIT, I prefer having it. I generally like to avoid duplicating user-facing messages. It should be updatable in a single place when needed.


const watchPath = ['./**/*.ts', `./${nangoConfigFile}`];
export function tscWatch({ fullPath, debug = false, watchConfigFile }: { fullPath: string; debug?: boolean; watchConfigFile: boolean }) {
const tsconfig = fs.readFileSync(path.resolve(getNangoRootPath(), 'tsconfig.dev.json'), 'utf8');

const watchPath = ['./**/*.ts'];
if (watchConfigFile) {
watchPath.push(`./${nangoConfigFile}`);
}

if (debug) {
printDebug(`Watching ${watchPath.join(', ')}`);
Expand All @@ -146,7 +155,7 @@ export function tscWatch({ fullPath, debug = false }: { fullPath: string; debug?
ignoreInitial: false,
ignored: (filePath: string) => {
const relativePath = path.relative(__dirname, filePath);
return relativePath.includes('node_modules') || path.basename(filePath) === TYPES_FILE_NAME;
return relativePath.includes('node_modules') || path.basename(filePath) === TYPES_FILE_NAME || relativePath.includes('.nango');
}
});

Expand All @@ -159,15 +168,65 @@ export function tscWatch({ fullPath, debug = false }: { fullPath: string; debug?
fs.mkdirSync(distDir);
}

watcher.on('add', async (filePath: string) => {
// First parsing of the config file
let parsed: NangoYamlParsed | null = loadYamlAndGenerate({ fullPath, debug });

const failedFiles = new Set<string>();

watcher.on('add', (filePath: string) => {
if (filePath === nangoConfigFile || !parsed) {
return;
}
void compileSingleFile({
fullPath,
file: getFileToCompile({ fullPath, filePath }),
tsconfig,
parsed,
debug
}).then((success) => {
if (success) {
failedFiles.delete(filePath);
} else {
failedFiles.add(filePath);
}
showCompilationMessage(failedFiles);
});
});

watcher.on('change', (filePath: string) => {
if (filePath === nangoConfigFile) {
parsed = loadYamlAndGenerate({ fullPath, debug });

if (!parsed) {
return;
}

void compileAllFiles({ fullPath, debug }).then(({ failedFiles: newFailedFiles }) => {
failedFiles.clear();
for (const file of newFailedFiles) {
failedFiles.add(file);
}
showCompilationMessage(failedFiles);
});
return;
}

if (!parsed) {
return;
}
await compileSingleFile({ fullPath, file: getFileToCompile({ fullPath, filePath }), tsconfig, parsed, debug });

void compileSingleFile({ fullPath, file: getFileToCompile({ fullPath, filePath }), parsed, debug }).then((success) => {
if (success) {
failedFiles.delete(filePath);
} else {
failedFiles.add(filePath);
}
showCompilationMessage(failedFiles);
});
});

watcher.on('unlink', (filePath: string) => {
if (filePath === nangoConfigFile) {
if (filePath === nangoConfigFile || !parsed) {
return;
}
const providerConfiguration = getProviderConfigurationFromPath({ filePath, parsed });
Expand All @@ -181,14 +240,6 @@ export function tscWatch({ fullPath, debug = false }: { fullPath: string; debug?
console.log(chalk.red(`Error deleting ${jsFilePath}`));
}
});

watcher.on('change', async (filePath: string) => {
if (filePath === nangoConfigFile) {
await compileAllFiles({ fullPath, debug });
return;
}
await compileSingleFile({ fullPath, file: getFileToCompile({ fullPath, filePath }), parsed, debug });
});
}

export function configWatch({ fullPath, debug = false }: { fullPath: string; debug?: boolean }) {
Expand Down
11 changes: 4 additions & 7 deletions packages/cli/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
import fs from 'fs';
import path from 'path';

import { nangoConfigFile } from '@nangohq/nango-yaml';
import chalk from 'chalk';
import { Command } from 'commander';
import * as dotenv from 'dotenv';
import figlet from 'figlet';

import { configWatch, generate, tscWatch, version } from './cli.js';
import { nangoConfigFile } from '@nangohq/nango-yaml';

import { generate, tscWatch, version } from './cli.js';
import { compileAllFiles } from './services/compile.service.js';
import { parse } from './services/config.service.js';
import deployService from './services/deploy.service.js';
Expand Down Expand Up @@ -164,11 +165,7 @@ program
const fullPath = process.cwd();
await verificationService.necessaryFilesExist({ fullPath, autoConfirm, debug, checkDist: false });

if (compileInterfaces) {
configWatch({ fullPath, debug });
}

tscWatch({ fullPath, debug });
tscWatch({ fullPath, debug, watchConfigFile: compileInterfaces });
});

program
Expand Down
13 changes: 10 additions & 3 deletions packages/cli/lib/services/compile.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ function getCachedParser({ fullPath, debug }: { fullPath: string; debug: boolean
};
}

interface CompileAllFilesResult {
success: boolean;
failedFiles: string[];
}

export async function compileAllFiles({
debug,
fullPath,
Expand All @@ -45,7 +50,7 @@ export async function compileAllFiles({
scriptName?: string;
providerConfigKey?: string;
type?: ScriptFileType;
}): Promise<boolean> {
}): Promise<CompileAllFilesResult> {
const tsconfig = fs.readFileSync(path.join(getNangoRootPath(), 'tsconfig.dev.json'), 'utf8');

const distDir = path.join(fullPath, 'dist');
Expand All @@ -59,7 +64,7 @@ export async function compileAllFiles({
const cachedParser = getCachedParser({ fullPath, debug });
const parsed = cachedParser();
if (!parsed) {
return false;
return { success: false, failedFiles: [] };
}

const compilerOptions = (JSON.parse(tsconfig) as { compilerOptions: Record<string, any> }).compilerOptions;
Expand All @@ -80,13 +85,15 @@ export async function compileAllFiles({

const integrationFiles = listFilesToCompile({ scriptName, fullPath, scriptDirectory, parsed, debug, providerConfigKey });
let allSuccess = true;
const failedFiles: string[] = [];
const compilationErrors: string[] = [];

for (const file of integrationFiles) {
try {
const completed = await compile({ fullPath, file, compiler, debug, cachedParser });
if (completed === false) {
allSuccess = false;
failedFiles.push(file.inputPath);
compilationErrors.push(`Failed to compile ${file.inputPath}`);
continue;
}
Expand All @@ -107,7 +114,7 @@ export async function compileAllFiles({
console.log(chalk.green('Successfully compiled all files present in the Nango YAML config file.'));
}

return allSuccess;
return { success: allSuccess, failedFiles };
}

export async function compileSingleFile({
Expand Down
Loading
Loading