-
Notifications
You must be signed in to change notification settings - Fork 484
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
Changes from all commits
c421e08
acfd2bd
cb0b18f
aec281d
d3c3464
b870c14
ae2334f
3ea6d9e
d6370fa
b4846a1
6f97a66
5dc4254
042f8b5
182b737
8c638bd
664dddf
1aebd12
8f3a088
fc60d91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ import { getLayoutMode } from './utils/layoutMode.js'; | |
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); | ||
|
||
|
@@ -127,14 +129,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) { | ||
kaposke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return; | ||
function showCompilationMessage(failedFiles: Set<string>) { | ||
if (failedFiles.size === 0) { | ||
console.log(chalk.green('Compilation success! Watching files…')); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
kaposke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
watchPath.push(`./${nangoConfigFile}`); | ||
} | ||
|
||
if (debug) { | ||
printDebug(`Watching ${watchPath.join(', ')}`); | ||
|
@@ -144,7 +151,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'); | ||
kaposke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
}); | ||
|
||
|
@@ -157,46 +164,92 @@ export function tscWatch({ fullPath, debug = false }: { fullPath: string; debug? | |
fs.mkdirSync(distDir); | ||
} | ||
|
||
watcher.on('add', async (filePath: string) => { | ||
if (filePath === nangoConfigFile) { | ||
return; | ||
// First parsing of the config file | ||
let parsed: NangoYamlParsed | null = loadYamlAndGenerate({ fullPath, debug }); | ||
|
||
const failedFiles = new Set<string>(); | ||
|
||
watcher.on('add', (filePath: string) => { | ||
async function onAdd() { | ||
if (debug) { | ||
printDebug(`Added ${filePath}`); | ||
} | ||
if (filePath === nangoConfigFile || !parsed) { | ||
return; | ||
} | ||
const success = await compileSingleFile({ | ||
fullPath, | ||
file: getFileToCompile({ fullPath, filePath }), | ||
tsconfig, | ||
parsed, | ||
debug | ||
}); | ||
if (success) { | ||
failedFiles.delete(filePath); | ||
} else { | ||
failedFiles.add(filePath); | ||
} | ||
showCompilationMessage(failedFiles); | ||
} | ||
|
||
void onAdd(); | ||
}); | ||
|
||
watcher.on('change', (filePath: string) => { | ||
async function onChange() { | ||
if (debug) { | ||
printDebug(`Changed ${filePath}`); | ||
} | ||
if (filePath === nangoConfigFile) { | ||
parsed = loadYamlAndGenerate({ fullPath, debug }); | ||
|
||
if (!parsed) { | ||
return; | ||
} | ||
|
||
const { failedFiles: newFailedFiles } = await compileAllFiles({ fullPath, debug }); | ||
failedFiles.clear(); | ||
for (const file of newFailedFiles) { | ||
failedFiles.add(file); | ||
} | ||
showCompilationMessage(failedFiles); | ||
return; | ||
} | ||
|
||
if (!parsed) { | ||
return; | ||
} | ||
|
||
const success = await compileSingleFile({ fullPath, file: getFileToCompile({ fullPath, filePath }), parsed, debug }); | ||
if (success) { | ||
failedFiles.delete(filePath); | ||
} else { | ||
failedFiles.add(filePath); | ||
} | ||
showCompilationMessage(failedFiles); | ||
} | ||
await compileSingleFile({ fullPath, file: getFileToCompile({ fullPath, filePath }), tsconfig, parsed, debug }); | ||
|
||
void onChange(); | ||
}); | ||
|
||
watcher.on('unlink', (filePath: string) => { | ||
if (filePath === nangoConfigFile) { | ||
if (debug) { | ||
printDebug(`Unlinked ${filePath}`); | ||
} | ||
if (filePath === nangoConfigFile || !parsed) { | ||
return; | ||
} | ||
const providerConfiguration = getProviderConfigurationFromPath({ filePath, parsed }); | ||
const baseName = path.basename(filePath, '.ts'); | ||
const fileName = providerConfiguration ? `${baseName}-${providerConfiguration.providerConfigKey}.js` : `${baseName}.js`; | ||
const jsFilePath = `./dist/${fileName}`; | ||
|
||
failedFiles.delete(filePath); | ||
|
||
try { | ||
fs.unlinkSync(jsFilePath); | ||
} catch { | ||
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 }) { | ||
const watchPath = path.join(fullPath, nangoConfigFile); | ||
if (debug) { | ||
printDebug(`Watching ${watchPath}`); | ||
} | ||
const watcher = chokidar.watch(watchPath, { ignoreInitial: true }); | ||
|
||
watcher.on('change', () => { | ||
loadYamlAndGenerate({ fullPath, debug }); | ||
}); | ||
} |
There was a problem hiding this comment.
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