Skip to content

Commit

Permalink
Merge pull request #31 from aha-app/DEVELOP-675-download-latest-typed…
Browse files Browse the repository at this point in the history
…efs-graphql-aha-cli

DEVELOP-675: Download latest typedefs for GraphQL from aha-cli
  • Loading branch information
percyhanna authored Jul 26, 2021
2 parents faa8067 + 9ebdf73 commit 5d8960b
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 3,017 deletions.
2,736 changes: 0 additions & 2,736 deletions aha.d.ts

This file was deleted.

11 changes: 0 additions & 11 deletions schema/package-schema.json

This file was deleted.

218 changes: 0 additions & 218 deletions schema/schema.json

This file was deleted.

19 changes: 3 additions & 16 deletions src/commands/extension/create.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import ux from 'cli-ux';
import * as fs from 'fs';
import * as inquirer from 'inquirer';
import * as path from 'path';
import BaseCommand from '../../base';
import { packageRoot } from '../../utils/package-info';
import { fetchRemoteTypes } from '../../utils/extension-utils';
import questions from '../../utils/questions';
import templates from '../../utils/templates';

Expand Down Expand Up @@ -88,20 +87,6 @@ export default class Create extends BaseCommand {
templates.readmeTemplate(extensionAnswers.name)
);

const modulePath = path.join(directoryName, 'node_modules', 'aha-cli');
fs.mkdirSync(path.join(modulePath, 'schema'), { recursive: true });
fs.copyFileSync(
path.join(packageRoot(), 'aha.d.ts'),
path.join(modulePath, 'aha.d.ts')
);
fs.copyFileSync(
path.join(packageRoot(), 'schema', 'schema.json'),
path.join(modulePath, 'schema', 'schema.json')
);
fs.copyFileSync(
path.join(packageRoot(), 'schema', 'package-schema.json'),
path.join(modulePath, 'schema', 'package-schema.json')
);
fs.writeFileSync(
`${directoryName}/tsconfig.json`,
templates.tsconfigTemplate()
Expand All @@ -123,6 +108,8 @@ export default class Create extends BaseCommand {
ahaExtensionSchema.contributes
);

await fetchRemoteTypes(directoryName);

ux.action.stop(`Extension created in directory '${directoryName}'`);
}
}
6 changes: 5 additions & 1 deletion src/commands/extension/install.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import BaseCommand from '../../base';
import { flags } from '@oclif/command';
import { installExtension } from '../../utils/extension-utils';
import {
fetchRemoteTypes,
installExtension,
} from '../../utils/extension-utils';

export default class Install extends BaseCommand {
static needsAuth = true;
Expand All @@ -19,5 +22,6 @@ export default class Install extends BaseCommand {

async run() {
await installExtension(this, this.flags.dumpCode, this.flags.noCache);
await fetchRemoteTypes();
}
}
7 changes: 6 additions & 1 deletion src/commands/extension/watch.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import BaseCommand from '../../base';
import { flags } from '@oclif/command';
import * as chokidar from 'chokidar';
import { installExtension } from '../../utils/extension-utils';
import {
fetchRemoteTypes,
installExtension,
} from '../../utils/extension-utils';

const WAIT_TIMEOUT = 250;
export default class Watch extends BaseCommand {
Expand All @@ -27,6 +30,8 @@ export default class Watch extends BaseCommand {
await this.performInstall();
this.log('Watching for changes in the current directory ...');

await fetchRemoteTypes();

chokidar
.watch('.', { ignoreInitial: true, ignored: '.git' })
.on('all', async (event, changedPath) => {
Expand Down
29 changes: 29 additions & 0 deletions src/utils/extension-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import ux from 'cli-ux';
import * as esbuild from 'esbuild';
import * as FormData from 'form-data';
import * as fs from 'fs';
import * as path from 'path';
import HTTP from 'http-call';
import { Readable } from 'stream';
import { createGzip } from 'zlib';
import BaseCommand from '../base';
Expand All @@ -24,6 +26,33 @@ export function identifierFromConfiguration(configuration: any) {
return configuration.name.replace('@', '').replace('/', '.');
}

export async function fetchRemoteTypes(extensionRoot = process.cwd()) {
ux.action.start('Downloading JSON schemas and TypeScript types from Aha!');

// prettier-ignore
const typings = {
'./types/aha-components.d.ts': 'https://cdn.aha.io/assets/extensions/types/aha-components.d.ts',
'./types/aha-models.d.ts': 'https://cdn.aha.io/assets/extensions/types/aha-models.d.ts',
'./schema/schema.json': 'https://cdn.aha.io/assets/extensions/schema/schema.json',
'./schema/package-schema.json': 'https://cdn.aha.io/assets/extensions/schema/package-schema.json',
};

const modulePath = path.join(extensionRoot, '.aha-cache');

const promises = Object.entries(typings).map(async ([filePath, url]) => {
const absoluteFilePath = path.join(modulePath, filePath);
fs.mkdirSync(path.dirname(absoluteFilePath), { recursive: true });
const fileStream = fs.createWriteStream(absoluteFilePath);

const result = await HTTP.get(url, { raw: true });
result.response.pipe(fileStream);
return new Promise(resolve => fileStream.on('close', resolve));
});

await Promise.all(promises);
ux.action.stop();
}

function fileNameFromConfiguration(configuration: any) {
return `${identifierFromConfiguration(configuration)}-v${
configuration.version
Expand Down
28 changes: 0 additions & 28 deletions src/utils/package-info.ts

This file was deleted.

Loading

0 comments on commit 5d8960b

Please sign in to comment.