Skip to content

Commit

Permalink
Allowing custom folder name for plugin installation
Browse files Browse the repository at this point in the history
Signed-off-by: Vacha Shah <[email protected]>
  • Loading branch information
VachaShah committed Jun 11, 2021
1 parent 433165a commit 58edde7
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 2 deletions.
Binary file not shown.
5 changes: 4 additions & 1 deletion src/cli_plugin/install/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ export async function install(settings, logger) {

assertVersion(settings);

const targetDir = path.join(settings.pluginDir, kebabCase(settings.plugins[0].id));
const folderName = settings.plugins[0].folderName
? settings.plugins[0].folderName
: kebabCase(settings.plugins[0].id);
const targetDir = path.join(settings.pluginDir, folderName);
await renamePlugin(settings.workingPath, targetDir);

logger.log('Plugin installation complete');
Expand Down
12 changes: 12 additions & 0 deletions src/cli_plugin/install/opensearch_dashboards.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ export function existingInstall(settings, logger) {
} catch (e) {
if (e.code !== 'ENOENT') throw e;
}
if (settings.plugins[0].folderName !== '') {
try {
statSync(path.join(settings.pluginDir, settings.plugins[0].folderName));

logger.error(
`Plugin ${settings.plugins[0].id} already exists with custom folder name, please remove before installing a new version`
);
process.exit(70);
} catch (e) {
if (e.code !== 'ENOENT') throw e;
}
}
}

export function assertVersion(settings) {
Expand Down
8 changes: 7 additions & 1 deletion src/cli_plugin/install/opensearch_dashboards.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ describe('opensearchDashboards cli', function () {
tempArchiveFile: tempArchiveFilePath,
plugin: 'test-plugin',
version: '1.0.0',
plugins: [{ id: 'foo' }],
plugins: [
{
id: 'foo',
folderName: '',
},
],
pluginDir,
};

Expand Down Expand Up @@ -86,6 +91,7 @@ describe('opensearchDashboards cli', function () {
plugins: [
{
id: 'foo',
folderName: '',
opensearchDashboardsVersion: '5.0.0-SNAPSHOT',
},
],
Expand Down
20 changes: 20 additions & 0 deletions src/cli_plugin/install/pack.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ describe('opensearchDashboards cli', function () {
expect(settings.plugins).toMatchInlineSnapshot(`
Array [
Object {
"folderName": "",
"id": "testPlugin",
"opensearchDashboardsVersion": "1.0.0",
"stripPrefix": "opensearch-dashboards/test-plugin",
Expand All @@ -134,6 +135,7 @@ describe('opensearchDashboards cli', function () {
expect(settings.plugins).toMatchInlineSnapshot(`
Array [
Object {
"folderName": "",
"id": "testPlugin",
"opensearchDashboardsVersion": "5.0.1",
"stripPrefix": "opensearch-dashboards/test-plugin",
Expand All @@ -148,16 +150,19 @@ describe('opensearchDashboards cli', function () {
expect(settings.plugins).toMatchInlineSnapshot(`
Array [
Object {
"folderName": "",
"id": "fungerPlugin",
"opensearchDashboardsVersion": "1.0.0",
"stripPrefix": "opensearch-dashboards/funger-plugin",
},
Object {
"folderName": "",
"id": "pdf",
"opensearchDashboardsVersion": "1.0.0",
"stripPrefix": "opensearch-dashboards/pdf",
},
Object {
"folderName": "",
"id": "testPlugin",
"opensearchDashboardsVersion": "1.0.0",
"stripPrefix": "opensearch-dashboards/test-plugin",
Expand All @@ -166,6 +171,21 @@ describe('opensearchDashboards cli', function () {
`);
});

it('populate settings.plugin.folderName', async () => {
await copyReplyFile('test_plugin_custom_folder.zip');
await getPackData(settings, logger);
expect(settings.plugins).toMatchInlineSnapshot(`
Array [
Object {
"folderName": "customPluginName",
"id": "testPlugin",
"opensearchDashboardsVersion": "1.0.0",
"stripPrefix": "opensearch-dashboards/test-plugin-custom-folder",
},
]
`);
});

it('throw an error if there is no opensearch-dashboards plugin', async () => {
await copyReplyFile('test_plugin_no_opensearch_dashboards.zip');
await expect(getPackData(settings, logger)).rejects.toThrowErrorMatchingInlineSnapshot(
Expand Down
4 changes: 4 additions & 0 deletions src/cli_plugin/install/zip.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ export function analyzeArchive(archive) {
plugins.push({
id: manifest.id,
stripPrefix: match[1],
folderName:
typeof manifest.folderName === 'string' && manifest.folderName
? manifest.folderName
: '',

// Plugins must specify their version, and by default that version in the plugin
// manifest should match the version of opensearch-dashboards down to the patch level. If these
Expand Down
1 change: 1 addition & 0 deletions src/cli_plugin/install/zip.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ describe('opensearchDashboards cli', function () {
expect(packages).toMatchInlineSnapshot(`
Array [
Object {
"folderName": "",
"id": "testPlugin",
"opensearchDashboardsVersion": "1.0.0",
"stripPrefix": "opensearch-dashboards/test-plugin",
Expand Down

0 comments on commit 58edde7

Please sign in to comment.