Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
bburns committed Jul 7, 2024
1 parent e85b50b commit 1ec997a
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 22 deletions.
13 changes: 7 additions & 6 deletions packages/cli/lib/services/compile.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,25 @@ export async function compileAllFiles({

const parsed = res.response!;
const compilerOptions = (JSON.parse(tsconfig) as { compilerOptions: Record<string, any> }).compilerOptions;
if (debug) {
printDebug(`Compiler options: ${JSON.stringify(compilerOptions, null, 2)}`);
}

const compiler = tsNode.create({
skipProject: true, // when installed locally we don't want ts-node to pick up the package tsconfig.json file
compilerOptions
});

if (debug) {
printDebug(`Compiler options: ${JSON.stringify(compilerOptions, null, 2)}`);
}

let scriptDirectory: string | undefined;
if (scriptName && providerConfigKey && type) {
scriptDirectory = resolveTsFileLocation({ fullPath, scriptName, providerConfigKey, type }).replace(fullPath, '');
console.log(chalk.green(`Compiling ${scriptName}.ts in ${fullPath}${scriptDirectory}`));
}

const integrationFiles = listFilesToCompile({ scriptName, fullPath, scriptDirectory, parsed, debug });

let success = true;

for (const file of integrationFiles) {
try {
const completed = await compile({ fullPath, file, parsed, compiler, debug });
Expand Down Expand Up @@ -332,9 +333,9 @@ export function listFilesToCompile({
// get file paths that match the given path parts,
// with last part treated as a file extension.
// eg getMatchingFiles('bar', 'ts') -> glob.sync('bar/*.ts')
// note: glob needs posix paths for input, so use slash fn
function getMatchingFiles(...args: string[]): string[] {
args.splice(-1, 1, `*.${args.slice(-1)[0]}`);
// note: glob needs posix paths for input, so use slash fn
const pattern = slash(args.join('/')); // eg 'bar/*.ts'
const pattern = slash(args.join('/'));
return glob.sync(pattern);
}
13 changes: 0 additions & 13 deletions packages/cli/lib/services/compile.service.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,14 @@ import { getFileToCompile, listFilesToCompile } from './compile.service';
import { fileURLToPath } from 'node:url';
import type { NangoYamlParsed } from '@nangohq/types';

// eg "C:\\Users\bburns\\Workspace\\forks\\nango\\packages\\cli\\lib\\services"
const thisFolder = path.dirname(fileURLToPath(import.meta.url));

// function join(...args) {
// args = args.map(arg => )
// return path.join(...args)
// }

describe('listFiles', () => {
it('should list files with glob', () => {
const files = listFilesToCompile({ fullPath: thisFolder, parsed: { integrations: [], models: new Map(), yamlVersion: 'v2' } });
expect(files.length).toBeGreaterThan(1);
//. why should this be the first entry?
expect(files[0]).toStrictEqual({
baseName: 'verification.service',
//. but listFiles gives
// 'packages\\cli\\lib\\services\\verification.service.ts'
// why?
// that's relative to curdir, not fullpath
// oh, that's what glob does - wew
// path.relative(join..., '')
inputPath: join(thisFolder, 'verification.service.ts'),
outputPath: join(thisFolder, 'dist/verification.service.js')
});
Expand Down
2 changes: 0 additions & 2 deletions packages/cli/lib/services/model.service.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,9 @@ describe('fieldToTypescript', () => {
describe('generate exports', () => {
describe('json', () => {
it('should export to JSON', () => {
// const folderTS = `/tmp/cli-exports-json`;
const folderTS = join(os.tmpdir(), 'cli-exports-json');
fs.rmSync(folderTS, { recursive: true, force: true });
fs.mkdirSync(folderTS, { recursive: true });
// const pathTS = path.join(`/tmp/cli-exports-json`, 'schema.ts');
const pathTS = join(folderTS, 'schema.ts');
fs.writeFileSync(pathTS, `export interface Test { id: string; name: number[]; }`);

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/lib/sync.unit.cli-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { exampleSyncName } from './constants.js';
import { compileAllFiles, compileSingleFile, getFileToCompile } from './services/compile.service.js';
import { getNangoRootPath } from './utils.js';
import parserService from './services/parser.service.js';
import { copyDirectoryAndContents, removeVersion, getTestDirectory, fixturesPath } from './tests/helpers.js';
import { copyDirectoryAndContents, removeVersion, fixturesPath, getTestDirectory } from './tests/helpers.js';
import { parse } from './services/config.service.js';

describe('generate function tests', () => {
Expand Down
1 change: 1 addition & 0 deletions vite.cli.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default defineConfig({
env: {
NANGO_ENCRYPTION_KEY: 'RzV4ZGo5RlFKMm0wYWlXdDhxTFhwb3ZrUG5KNGg3TmU='
},
testTimeout: 20000,
chaiConfig: {
truncateThreshold: 10000
},
Expand Down

0 comments on commit 1ec997a

Please sign in to comment.