diff --git a/src/connector-cli/resources/schemas/connector-config.json b/src/connector-cli/resources/schemas/connector-config.json index 256c32e..b9e248a 100644 --- a/src/connector-cli/resources/schemas/connector-config.json +++ b/src/connector-cli/resources/schemas/connector-config.json @@ -7,7 +7,7 @@ }, "type": { "type": "string", - "enum": ["media"] + "enum": ["media", "data"] }, "iconUrl": { "type": "string" diff --git a/src/connector-cli/src/commands/init/index.ts b/src/connector-cli/src/commands/init/index.ts index d9cb633..c1ee652 100644 --- a/src/connector-cli/src/commands/init/index.ts +++ b/src/connector-cli/src/commands/init/index.ts @@ -5,6 +5,7 @@ import path from 'path'; import { info, startCommand, verbose } from '../../core'; import { Type as ConnectorType, ExecutionError } from '../../core/types'; import { + getDataConnectorFile, getGitIgnoreFile, getMediaConnectorFile, getMediaConnectorTestFile, @@ -71,19 +72,23 @@ export async function runInit(options: InitCommandOptions): Promise { ); // 4. create connector file - const { content, fileName } = getMediaConnectorFile(); + const { content, fileName } = + options.type === ConnectorType.Media + ? getMediaConnectorFile() + : getDataConnectorFile(); info('Creating ' + fileName); fs.writeFileSync(path.join(projectDir, fileName), content); - // 5. create tests.json - const testsJson = getMediaConnectorTestFile(); - - info('Creating tests.json'); - fs.writeFileSync( - path.join(projectDir, './tests.json'), - JSON.stringify(testsJson, null, 2) - ); + if (options.type === ConnectorType.Media) { + // 5. create tests.json + const testsJson = getMediaConnectorTestFile(); + info('Creating tests.json'); + fs.writeFileSync( + path.join(projectDir, './tests.json'), + JSON.stringify(testsJson, null, 2) + ); + } // 6. create .gitignore const gitIgnore = getGitIgnoreFile(); diff --git a/src/connector-cli/src/commands/init/templates/data-connector.ts b/src/connector-cli/src/commands/init/templates/data-connector.ts new file mode 100644 index 0000000..d31da50 --- /dev/null +++ b/src/connector-cli/src/commands/init/templates/data-connector.ts @@ -0,0 +1,39 @@ +import { connectorFileName } from '../../../utils/connector-project'; + +const connectorFileContent = `import { Connector, Data } from "@chili-publish/studio-connectors"; + +export default class MyConnector implements Data.DataConnector { + + private runtime: Connector.ConnectorRuntimeContext; + + constructor(runtime: Connector.ConnectorRuntimeContext) { + this.runtime = runtime; + } + + getPage( + config: Data.PageConfig, + context: Connector.Dictionary + ): Promise { + throw new Error('Method not implemented.'); + } + + getModel(context: Connector.Dictionary): Promise { + throw new Error('Method not implemented.'); + } + + getConfigurationOptions(): Connector.ConnectorConfigValue[] | null { + return []; + } + + getCapabilities(): Data.DataConnectorCapabilities { + return { + filtering: false, + sorting: false, + model: false, + } + } +}`; +export const getDataConnectorFile = () => ({ + content: connectorFileContent, + fileName: connectorFileName, +}); diff --git a/src/connector-cli/src/commands/init/templates/gitignore.ts b/src/connector-cli/src/commands/init/templates/gitignore.ts new file mode 100644 index 0000000..9029ac0 --- /dev/null +++ b/src/connector-cli/src/commands/init/templates/gitignore.ts @@ -0,0 +1,4 @@ +import { outputDirectory } from '../../../utils/connector-project'; + +export const getGitIgnoreFile = () => `node_modules +${outputDirectory}`; diff --git a/src/connector-cli/src/commands/init/templates/index.ts b/src/connector-cli/src/commands/init/templates/index.ts new file mode 100644 index 0000000..30a3b6b --- /dev/null +++ b/src/connector-cli/src/commands/init/templates/index.ts @@ -0,0 +1,10 @@ +// Generic +export * from './gitignore'; +export * from './package.json'; +export * from './tsconfig'; + +// Media connector +export * from './media-connector'; + +// Data connector +export * from './data-connector'; diff --git a/src/connector-cli/src/commands/init/templates.ts b/src/connector-cli/src/commands/init/templates/media-connector.ts similarity index 51% rename from src/connector-cli/src/commands/init/templates.ts rename to src/connector-cli/src/commands/init/templates/media-connector.ts index 7172793..cf0c1fa 100644 --- a/src/connector-cli/src/commands/init/templates.ts +++ b/src/connector-cli/src/commands/init/templates/media-connector.ts @@ -1,58 +1,6 @@ -import { Type } from '../../core/types'; -import { - connectorFileName, - outputDirectory, - outputFilename, -} from '../../utils/connector-project'; +import { connectorFileName } from '../../../utils/connector-project'; -export const getPackageJson = (projectName: string, type: Type) => ({ - name: projectName, - description: '', - version: '1.0.0', - author: { - name: 'CHILI publish', - email: 'info@chili-publish.com', - url: 'https://github.com/chili-publish', - }, - config: { - type: type, - options: {}, - mappings: {}, - supportedAuth: [], - }, - license: 'MIT', - main: `${outputDirectory}/${outputFilename}`, - dependencies: { - typescript: '^5.2.2', - '@chili-publish/studio-connectors': '^1', - }, - scripts: { - build: 'yarn connector-cli build', - test: 'yarn connector-cli test -t tests.json && yarn connector-cli stress', - }, - devDependencies: { - '@chili-publish/connector-cli': '^1', - }, -}); - -export const getTsConfig = () => ({ - compilerOptions: { - lib: ['ES2020'], - noEmitHelpers: true, - module: 'ES2020', - outDir: `${outputDirectory}`, - target: 'ES2020', - moduleResolution: 'Node', - preserveConstEnums: false, - esModuleInterop: false, - removeComments: true, - declaration: false, - }, - include: [connectorFileName], - exclude: ['node_modules', `${outputDirectory}`], -}); - -const mediaConnectorFileContent = `import { Connector, Media } from "@chili-publish/studio-connectors"; +const connectorFileContent = `import { Connector, Media } from "@chili-publish/studio-connectors"; export default class MyConnector implements Media.MediaConnector { @@ -61,19 +9,21 @@ export default class MyConnector implements Media.MediaConnector { constructor(runtime: Connector.ConnectorRuntimeContext) { this.runtime = runtime; } - + query( options: Connector.QueryOptions, context: Connector.Dictionary ): Promise { throw new Error("Method not implemented."); } + detail( id: string, context: Connector.Dictionary ): Promise { throw new Error("Method not implemented."); } + download( id: string, previewType: Media.DownloadType, @@ -82,9 +32,11 @@ export default class MyConnector implements Media.MediaConnector { ): Promise { throw new Error("Method not implemented."); } + getConfigurationOptions(): Connector.ConnectorConfigValue[] | null { return []; } + getCapabilities(): Media.MediaConnectorCapabilities { return { query: false, @@ -95,7 +47,7 @@ export default class MyConnector implements Media.MediaConnector { } }`; export const getMediaConnectorFile = () => ({ - content: mediaConnectorFileContent, + content: connectorFileContent, fileName: connectorFileName, }); @@ -126,6 +78,3 @@ export const getMediaConnectorTestFile = () => ({ }, ], }); - -export const getGitIgnoreFile = () => `node_modules -${outputDirectory}`; diff --git a/src/connector-cli/src/commands/init/templates/package.json.ts b/src/connector-cli/src/commands/init/templates/package.json.ts new file mode 100644 index 0000000..166f225 --- /dev/null +++ b/src/connector-cli/src/commands/init/templates/package.json.ts @@ -0,0 +1,35 @@ +import { Type } from '../../../core/types'; +import { + outputDirectory, + outputFilename, +} from '../../../utils/connector-project'; + +export const getPackageJson = (projectName: string, type: Type) => ({ + name: projectName, + description: '', + version: '1.0.0', + author: { + name: 'CHILI publish', + email: 'info@chili-publish.com', + url: 'https://github.com/chili-publish', + }, + config: { + type: type, + options: {}, + mappings: {}, + supportedAuth: [], + }, + license: 'MIT', + main: `${outputDirectory}/${outputFilename}`, + dependencies: { + typescript: '^5.2.2', + '@chili-publish/studio-connectors': '^1.16.0', + }, + scripts: { + build: 'yarn connector-cli build', + test: 'yarn connector-cli test -t tests.json && yarn connector-cli stress', + }, + devDependencies: { + '@chili-publish/connector-cli': '^1.9.0', + }, +}); diff --git a/src/connector-cli/src/commands/init/templates/tsconfig.ts b/src/connector-cli/src/commands/init/templates/tsconfig.ts new file mode 100644 index 0000000..d1fad31 --- /dev/null +++ b/src/connector-cli/src/commands/init/templates/tsconfig.ts @@ -0,0 +1,21 @@ +import { + connectorFileName, + outputDirectory, +} from '../../../utils/connector-project'; + +export const getTsConfig = () => ({ + compilerOptions: { + lib: ['ES2020'], + noEmitHelpers: true, + module: 'ES2020', + outDir: `${outputDirectory}`, + target: 'ES2020', + moduleResolution: 'Node', + preserveConstEnums: false, + esModuleInterop: false, + removeComments: true, + declaration: false, + }, + include: [connectorFileName], + exclude: ['node_modules', `${outputDirectory}`], +}); diff --git a/src/connector-cli/src/commands/publish/steps/update-connector.ts b/src/connector-cli/src/commands/publish/steps/update-connector.ts index d925502..47f2721 100644 --- a/src/connector-cli/src/commands/publish/steps/update-connector.ts +++ b/src/connector-cli/src/commands/publish/steps/update-connector.ts @@ -8,7 +8,7 @@ export async function updateExistingConnector( token: string, payload: UpdateConnectorPayload ): Promise { - info('Retrieving connector to remove...'); + info('Retrieving connector to update...'); const existingConnector = await getConnectorById({ baseUrl: connectorEndpointBaseUrl, connectorId, diff --git a/src/connector-cli/src/commands/publish/types.ts b/src/connector-cli/src/commands/publish/types.ts index ad294b3..7579584 100644 --- a/src/connector-cli/src/commands/publish/types.ts +++ b/src/connector-cli/src/commands/publish/types.ts @@ -6,7 +6,7 @@ export interface ProxyOptions { interface ConnectorPayload { name: string; description: string; - type: 'media' | 'fonts'; + type: 'media' | 'fonts' | 'data'; version: string; iconUrl?: string; script: string; diff --git a/src/connector-cli/src/core/types/gen-types.ts b/src/connector-cli/src/core/types/gen-types.ts index 559171b..211731f 100644 --- a/src/connector-cli/src/core/types/gen-types.ts +++ b/src/connector-cli/src/core/types/gen-types.ts @@ -113,6 +113,7 @@ export enum SupportedAuth { } export enum Type { + Data = "data", Media = "media", } @@ -406,6 +407,7 @@ const typeMap: any = { "staticKey", ], "Type": [ + "data", "media", ], };