Skip to content

Commit

Permalink
win passing
Browse files Browse the repository at this point in the history
  • Loading branch information
bburns committed Jul 5, 2024
1 parent 5aa0c48 commit a843c0d
Show file tree
Hide file tree
Showing 16 changed files with 121 additions and 137 deletions.
45 changes: 19 additions & 26 deletions packages/cli/lib/cli.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import fs from 'node:fs';

// import path from 'node:path';
// import { join } from 'node:path/posix';
// import path from 'node:path/posix';
// import { resolve } from 'node:path';
import path from './ourpath.js';
import path, { join } from 'node:path';
import { fileURLToPath } from 'node:url';
import chalk from 'chalk';
import chokidar from 'chokidar';
Expand Down Expand Up @@ -36,10 +31,10 @@ export const version = (debug: boolean) => {
};

export function generate({ fullPath, debug = false }: { fullPath: string; debug?: boolean }) {
const syncTemplateContents = fs.readFileSync(path.join(__dirname, './templates/sync.ejs'), 'utf8');
const actionTemplateContents = fs.readFileSync(path.join(__dirname, './templates/action.ejs'), 'utf8');
const githubExampleTemplateContents = fs.readFileSync(path.join(__dirname, './templates/github.sync.ejs'), 'utf8');
const postConnectionTemplateContents = fs.readFileSync(path.join(__dirname, './templates/post-connection.ejs'), 'utf8');
const syncTemplateContents = fs.readFileSync(join(__dirname, './templates/sync.ejs'), 'utf8');
const actionTemplateContents = fs.readFileSync(join(__dirname, './templates/action.ejs'), 'utf8');
const githubExampleTemplateContents = fs.readFileSync(join(__dirname, './templates/github.sync.ejs'), 'utf8');
const postConnectionTemplateContents = fs.readFileSync(join(__dirname, './templates/post-connection.ejs'), 'utf8');

const res = loadYamlAndGenerate({ fullPath, debug });
if (!res.success) {
Expand All @@ -60,9 +55,9 @@ export function generate({ fullPath, debug = false }: { fullPath: string; debug?
});
const stripped = rendered.replace(/^\s+/, '');

if (!fs.existsSync(path.join(fullPath, `${providerConfigKey}/${type}s/${name}.ts`))) {
fs.mkdirSync(path.join(fullPath, `${providerConfigKey}/${type}s`), { recursive: true });
fs.writeFileSync(path.join(fullPath, `${providerConfigKey}/${type}s/${name}.ts`), stripped);
if (!fs.existsSync(join(fullPath, `${providerConfigKey}/${type}s/${name}.ts`))) {
fs.mkdirSync(join(fullPath, `${providerConfigKey}/${type}s`), { recursive: true });
fs.writeFileSync(join(fullPath, `${providerConfigKey}/${type}s/${name}.ts`), stripped);
if (debug) {
printDebug(`Created ${name}.ts file`);
}
Expand All @@ -87,7 +82,7 @@ export function generate({ fullPath, debug = false }: { fullPath: string; debug?
process.exit(1);
}

if (fs.existsSync(path.join(fullPath, `${name}.ts`)) || fs.existsSync(path.join(fullPath, `${providerConfigKey}/${type}s/${name}.ts`))) {
if (fs.existsSync(join(fullPath, `${name}.ts`)) || fs.existsSync(join(fullPath, `${providerConfigKey}/${type}s/${name}.ts`))) {
if (debug) {
printDebug(`${name}.ts file already exists, so will not overwrite it.`);
}
Expand Down Expand Up @@ -125,10 +120,10 @@ export function generate({ fullPath, debug = false }: { fullPath: string; debug?
const stripped = rendered.replace(/^\s+/, '');

if (layoutMode === 'root') {
fs.writeFileSync(path.join(fullPath, `${name}.ts`), stripped);
fs.writeFileSync(join(fullPath, `${name}.ts`), stripped);
} else {
fs.mkdirSync(path.join(fullPath, `${providerConfigKey}/${type}s`), { recursive: true });
fs.writeFileSync(path.join(fullPath, `${providerConfigKey}/${type}s/${name}.ts`), stripped);
fs.mkdirSync(join(fullPath, `${providerConfigKey}/${type}s`), { recursive: true });
fs.writeFileSync(join(fullPath, `${providerConfigKey}/${type}s/${name}.ts`), stripped);
}
if (debug) {
console.log(chalk.green(`Created ${name}.ts file`));
Expand Down Expand Up @@ -209,7 +204,7 @@ NANGO_DEPLOY_AUTO_CONFIRM=false # Default value`
}

export function tscWatch({ fullPath, debug = false }: { fullPath: string; debug?: boolean }) {
const tsconfig = fs.readFileSync(`${getNangoRootPath()}/tsconfig.dev.json`, 'utf8');
const tsconfig = fs.readFileSync(join(getNangoRootPath(), 'tsconfig.dev.json'), 'utf8');
const res = loadYamlAndGenerate({ fullPath, debug });
if (!res.success) {
console.log(chalk.red(res.error?.message));
Expand All @@ -234,7 +229,7 @@ export function tscWatch({ fullPath, debug = false }: { fullPath: string; debug?
}
});

const distDir = path.join(fullPath, 'dist');
const distDir = join(fullPath, 'dist');

if (!fs.existsSync(distDir)) {
if (debug) {
Expand All @@ -254,7 +249,7 @@ export function tscWatch({ fullPath, debug = false }: { fullPath: string; debug?

watcher.on('unlink', (filePath: string) => {
// filePath = filePath.replace(/\\/g, '/');
filePath = slash(filePath);
// filePath = slash(filePath);
if (filePath === nangoConfigFile) {
return;
}
Expand All @@ -272,7 +267,7 @@ export function tscWatch({ fullPath, debug = false }: { fullPath: string; debug?

watcher.on('change', async (filePath: string) => {
// filePath = filePath.replace(/\\/g, '/');
filePath = slash(filePath);
// filePath = slash(filePath);
if (filePath === nangoConfigFile) {
await compileAllFiles({ fullPath, debug });
return;
Expand All @@ -282,7 +277,7 @@ export function tscWatch({ fullPath, debug = false }: { fullPath: string; debug?
}

export function configWatch({ fullPath, debug = false }: { fullPath: string; debug?: boolean }) {
const watchPath = path.join(fullPath, nangoConfigFile);
const watchPath = join(fullPath, nangoConfigFile);
if (debug) {
printDebug(`Watching ${watchPath}`);
}
Expand All @@ -296,8 +291,7 @@ export function configWatch({ fullPath, debug = false }: { fullPath: string; deb
let child: ChildProcess | undefined;
process.on('SIGINT', () => {
if (child) {
// const dockerDown = spawn('docker', ['compose', '-f', `${getNangoRootPath()}/docker/docker-compose.yaml`, '--project-directory', '.', 'down'], {
const dockerDown = spawn('docker', ['compose', '-f', path.join(getNangoRootPath(), 'docker/docker-compose.yaml'), '--project-directory', '.', 'down'], {
const dockerDown = spawn('docker', ['compose', '-f', join(getNangoRootPath(), 'docker/docker-compose.yaml'), '--project-directory', '.', 'down'], {
stdio: 'inherit'
});
dockerDown.on('exit', () => {
Expand All @@ -316,8 +310,7 @@ process.on('SIGINT', () => {
export const dockerRun = async (debug = false) => {
const cwd = process.cwd();

// const args = ['compose', '-f', `${getNangoRootPath()}/docker/docker-compose.yaml`, '--project-directory', '.', 'up', '--build'];
const args = ['compose', '-f', path.join(getNangoRootPath(), 'docker/docker-compose.yaml'), '--project-directory', '.', 'up', '--build'];
const args = ['compose', '-f', join(getNangoRootPath(), 'docker/docker-compose.yaml'), '--project-directory', '.', 'up', '--build'];

if (debug) {
printDebug(`Running docker with args: ${args.join(' ')}`);
Expand Down
30 changes: 15 additions & 15 deletions packages/cli/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { Command } from 'commander';
import fs from 'fs';
import chalk from 'chalk';
import figlet from 'figlet';
import path from 'path/posix';
import path from 'path';
import * as dotenv from 'dotenv';
import slash from 'slash';
// import slash from 'slash';

import { init, generate, tscWatch, configWatch, dockerRun, version } from './cli.js';
import deployService from './services/deploy.service.js';
Expand Down Expand Up @@ -89,7 +89,7 @@ program
.description('Initialize a new Nango project')
.action(function (this: Command) {
const { debug } = this.opts();
const fullPath = slash(process.cwd());
const fullPath = process.cwd();
init({ absolutePath: fullPath, debug });

console.log(chalk.green(`Nango integrations initialized!`));
Expand All @@ -100,7 +100,7 @@ program
.description('Generate a new Nango integration')
.action(function (this: Command) {
const { debug } = this.opts();
generate({ fullPath: slash(process.cwd()), debug });
generate({ fullPath: process.cwd(), debug });
});

program
Expand All @@ -126,7 +126,7 @@ program
)
.action(async function (this: Command, sync: string, connectionId: string) {
const { autoConfirm, debug, e: environment, integrationId } = this.opts();
const fullPath = slash(process.cwd());
const fullPath = process.cwd();
await verificationService.necessaryFilesExist({ fullPath, autoConfirm, debug });
const dryRun = new DryRunService({ fullPath });
await dryRun.run({ ...this.opts(), sync, connectionId, optionalEnvironment: environment, optionalProviderConfigKey: integrationId }, debug);
Expand All @@ -138,7 +138,7 @@ program
.option('--no-compile-interfaces', `Watch the ${nangoConfigFile} and recompile the interfaces on change`, true)
.action(async function (this: Command) {
const { compileInterfaces, autoConfirm, debug } = this.opts();
const fullPath = slash(process.cwd());
const fullPath = process.cwd();
await verificationService.necessaryFilesExist({ fullPath, autoConfirm, debug, checkDist: false });

if (compileInterfaces) {
Expand All @@ -159,23 +159,23 @@ program
.action(async function (this: Command, environment: string) {
const options: DeployOptions = this.opts();
const { debug } = options;
const fullPath = slash(process.cwd());
const fullPath = process.cwd();
await deployService.prep({ fullPath, options: { ...options, env: 'production' as ENV }, environment, debug });
});

program
.command('migrate-config')
.description('Migrate the nango.yaml from v1 (deprecated) to v2')
.action(function (this: Command) {
v1toV2Migration(slash(path.resolve(process.cwd(), NANGO_INTEGRATIONS_LOCATION)));
v1toV2Migration(path.resolve(process.cwd(), NANGO_INTEGRATIONS_LOCATION));
});

program
.command('migrate-to-directories')
.description('Migrate the script files from root level to structured directories.')
.action(async function (this: Command) {
const { debug } = this.opts();
await directoryMigration(slash(path.resolve(process.cwd(), NANGO_INTEGRATIONS_LOCATION)), debug);
await directoryMigration(path.resolve(process.cwd(), NANGO_INTEGRATIONS_LOCATION), debug);
});

// Hidden commands //
Expand All @@ -189,7 +189,7 @@ program
.option('--no-compile-interfaces', `Don't compile the ${nangoConfigFile}`, true)
.action(async function (this: Command, environment: string) {
const options: DeployOptions = this.opts();
const fullPath = slash(process.cwd());
const fullPath = process.cwd();
await deployService.prep({ fullPath, options: { ...options, env: 'local' }, environment, debug: options.debug });
});

Expand All @@ -209,7 +209,7 @@ program
.option('--no-compile-interfaces', `Don't compile the ${nangoConfigFile}`, true)
.action(async function (this: Command, environment: string) {
const options: DeployOptions = this.opts();
const fullPath = slash(process.cwd());
const fullPath = process.cwd();
await deployService.prep({ fullPath, options: { ...options, env: 'staging' }, environment, debug: options.debug });
});

Expand All @@ -218,7 +218,7 @@ program
.description('Compile the integration files to JavaScript')
.action(async function (this: Command) {
const { autoConfirm, debug } = this.opts();
const fullPath = slash(process.cwd());
const fullPath = process.cwd();
await verificationService.necessaryFilesExist({ fullPath, autoConfirm, debug, checkDist: false });

const match = verificationService.filesMatchConfig({ fullPath });
Expand All @@ -239,7 +239,7 @@ program
.option('--no-compile-interfaces', `Watch the ${nangoConfigFile} and recompile the interfaces on change`, true)
.action(async function (this: Command) {
const { compileInterfaces, autoConfirm, debug } = this.opts();
const fullPath = slash(process.cwd());
const fullPath = process.cwd();
await verificationService.necessaryFilesExist({ fullPath, autoConfirm, debug });
if (compileInterfaces) {
configWatch({ fullPath, debug });
Expand All @@ -263,7 +263,7 @@ program
.description('Verify the parsed sync config and output the object for verification')
.action(async function (this: Command) {
const { autoConfirm } = this.opts();
const fullPath = slash(process.cwd());
const fullPath = process.cwd();
await verificationService.necessaryFilesExist({ fullPath, autoConfirm });
const { success, error, response } = parse(path.resolve(fullPath, NANGO_INTEGRATIONS_LOCATION));

Expand All @@ -283,7 +283,7 @@ program
.arguments('environmentName')
.action(async function (this: Command, environmentName: string) {
const { debug } = this.opts();
const fullPath = slash(process.cwd());
const fullPath = process.cwd();
await deployService.admin({ fullPath, environmentName, debug });
});

Expand Down
10 changes: 0 additions & 10 deletions packages/cli/lib/ourpath.ts

This file was deleted.

42 changes: 21 additions & 21 deletions packages/cli/lib/services/compile.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import fs from 'fs';
import { glob } from 'glob';
import * as tsNode from 'ts-node';
import chalk from 'chalk';
import path from 'path/posix';
import path from 'path';
import { build } from 'tsup';
// import slash from 'slash';
import slash from 'slash';

import { getNangoRootPath, printDebug } from '../utils.js';
import { loadYamlAndGenerate } from './model.service.js';
Expand All @@ -29,8 +29,7 @@ export async function compileAllFiles({
}): Promise<boolean> {
console.log('compileAllFiles', fullPath);

// const tsconfig = fs.readFileSync(`${getNangoRootPath()}/tsconfig.dev.json`, 'utf8');
const tsconfig = fs.readFileSync(path.join(getNangoRootPath() || '', 'tsconfig.dev.json'), 'utf8');
const tsconfig = fs.readFileSync(path.join(getNangoRootPath(), 'tsconfig.dev.json'), 'utf8');
console.log('tsconfig', tsconfig);

const distDir = path.join(fullPath, 'dist');
Expand Down Expand Up @@ -69,7 +68,6 @@ export async function compileAllFiles({
let success = true;
for (const file of integrationFiles) {
try {
// console.log('calling compile', { fullPath, file, parsed });
const completed = await compile({ fullPath, file, parsed, compiler, debug });
if (!completed) {
if (scriptName && file.inputPath.includes(scriptName)) {
Expand Down Expand Up @@ -232,10 +230,13 @@ async function compile({

//. compile with tsup ? but used tsNode above?
console.log('calling build...');
const tsconfigPath = slash(path.join(getNangoRootPath(), 'tsconfig.dev.json'));
// build may throw an error
await build({
entryPoints: [file.inputPath],
tsconfig: path.join(getNangoRootPath() || '', 'tsconfig.dev.json'),
// entryPoints: [file.inputPath],
entryPoints: [slash(file.inputPath)],
// tsconfig: path.join(getNangoRootPath(), 'tsconfig.dev.json'),
tsconfig: tsconfigPath,
skipNodeModulesBundle: true,
silent: !debug,
outDir: path.join(fullPath, 'dist'),
Expand Down Expand Up @@ -281,7 +282,6 @@ export function resolveTsFileLocation({
providerConfigKey: string;
type: ScriptFileType;
}) {
// const nestedPath = path.resolve(fullPath, providerConfigKey, type, `${scriptName}.ts`);
const nestedPath = path.resolve(fullPath, `${providerConfigKey}/${type}/${scriptName}.ts`);
if (fs.existsSync(nestedPath)) {
return fs.realpathSync(path.resolve(nestedPath, '../'));
Expand Down Expand Up @@ -321,25 +321,24 @@ export function listFilesToCompile({
parsed.integrations.forEach((integration) => {
const syncPath = `${integration.providerConfigKey}/syncs`;
const actionPath = `${integration.providerConfigKey}/actions`;
const postConnectionPath = `${integration.providerConfigKey}/post-connection-scripts`;

files = [
...files,
...getMatchingFiles(fullPath, syncPath, 'ts'),
...getMatchingFiles(fullPath, actionPath, 'ts'),
...getMatchingFiles(fullPath, postConnectionPath, 'ts')
];
const postPath = `${integration.providerConfigKey}/post-connection-scripts`;

const syncFiles = getMatchingFiles(fullPath, syncPath, 'ts');
const actionFiles = getMatchingFiles(fullPath, actionPath, 'ts');
const postFiles = getMatchingFiles(fullPath, postPath, 'ts');

files = [...files, ...syncFiles, ...actionFiles, ...postFiles];
console.log('files', files);

if (debug) {
if (getMatchingFiles(fullPath, syncPath, 'ts').length > 0) {
if (syncFiles.length > 0) {
printDebug(`Found nested sync files in ${syncPath}`);
}
if (getMatchingFiles(fullPath, actionPath, 'ts').length > 0) {
if (actionFiles.length > 0) {
printDebug(`Found nested action files in ${actionPath}`);
}
if (getMatchingFiles(fullPath, postConnectionPath, 'ts').length > 0) {
printDebug(`Found nested post connection script files in ${postConnectionPath}`);
if (postFiles.length > 0) {
printDebug(`Found nested post connection script files in ${postPath}`);
}
}
});
Expand All @@ -358,7 +357,8 @@ function getMatchingFiles(...args: string[]): string[] {
// console.log('args', args);
const pattern = args.join('/');
// console.log('pattern', pattern);
return glob.sync(pattern, { posix: true });
// return glob.sync(pattern, { posix: true });
return glob.sync(pattern);

// const pattern = path.join(...args);
// console.log('pattern', pattern);
Expand Down
Loading

0 comments on commit a843c0d

Please sign in to comment.