-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feat] Add support of data connector for "new", "init" and "publish" …
…commands (#75)
- Loading branch information
Showing
11 changed files
with
136 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/connector-cli/src/commands/init/templates/data-connector.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Data.DataPage> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
getModel(context: Connector.Dictionary): Promise<Data.DataModel> { | ||
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, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { outputDirectory } from '../../../utils/connector-project'; | ||
|
||
export const getGitIgnoreFile = () => `node_modules | ||
${outputDirectory}`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: '[email protected]', | ||
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<Media.MediaPage> { | ||
throw new Error("Method not implemented."); | ||
} | ||
detail( | ||
id: string, | ||
context: Connector.Dictionary | ||
): Promise<Media.MediaDetail> { | ||
throw new Error("Method not implemented."); | ||
} | ||
download( | ||
id: string, | ||
previewType: Media.DownloadType, | ||
|
@@ -82,9 +32,11 @@ export default class MyConnector implements Media.MediaConnector { | |
): Promise<Connector.ArrayBufferPointer> { | ||
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}`; |
35 changes: 35 additions & 0 deletions
35
src/connector-cli/src/commands/init/templates/package.json.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: '[email protected]', | ||
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', | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}`], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters