Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transfer features from unofficial plugin #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_modules
out
doppler.vsix
.vscode-test
.history
6 changes: 6 additions & 0 deletions media/add-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions media/add.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions media/checkmark-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions media/checkmark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 53 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,33 @@
],
"menus": {
"view/title": [
{
"command": "doppler.explorer.addProject",
"when": "view == doppler-explorer"
},
{
"command": "doppler.explorer.refresh",
"when": "view == doppler-explorer",
"group": "navigation"
}
],
"view/item/context": [
{
"command": "doppler.addEnvironment",
"when": "view == doppler-explorer && viewItem == 0",
"group": "inline"
},
{
"command": "doppler.addConfig",
"when": "view == doppler-explorer && viewItem == 1",
"group": "inline"
},
{
"command": "doppler.selectConfig",
"when": "view == doppler-explorer && viewItem == 2",
"group": "inline"
}
],
"editor/title": [
{
"command": "doppler.explorer.editor.config.dashboard",
Expand All @@ -91,6 +112,38 @@
]
},
"commands": [
{
"command": "doppler.explorer.addProject",
"category": "Doppler",
"title": "Add Project"
},
{
"command": "doppler.addEnvironment",
"category": "Doppler",
"title": "Add Environment",
"icon": {
"light": "media/add.svg",
"dark": "media/add-dark.svg"
}
},
{
"command": "doppler.addConfig",
"category": "Doppler",
"title": "Add Config",
"icon": {
"light": "media/add.svg",
"dark": "media/add-dark.svg"
}
},
{
"command": "doppler.selectConfig",
"category": "Doppler",
"title": "Select Config",
"icon": {
"light": "media/checkmark.svg",
"dark": "media/checkmark-dark.svg"
}
},
{
"command": "doppler.install",
"category": "Doppler",
Expand Down
3 changes: 3 additions & 0 deletions src/lib/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import setup from "./setup";
import documentation from "./documentation";
import install from "./install";
import update from "./update";
import selectConfig from "./select-config";

export default function (context: ExtensionContext) {
context.subscriptions.push(commands.registerCommand("doppler.login", login));
Expand All @@ -18,4 +19,6 @@ export default function (context: ExtensionContext) {
context.subscriptions.push(commands.registerCommand("doppler.install", install));

context.subscriptions.push(commands.registerCommand("doppler.update", update));

context.subscriptions.push(commands.registerCommand('doppler.selectConfig', selectConfig));
}
16 changes: 16 additions & 0 deletions src/lib/commands/select-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { window } from "vscode";
import * as helpers from "../helpers";
import * as doppler from "../doppler";

export default async function (args: any) {
const config = args.config;
const project = args.project;
if (!(await doppler.auth.hasDopplerCLI())) {
await window.showErrorMessage("The Doppler CLI must be installed first before it can be updated.");

return;
}

await helpers.terminal.run("doppler", ["setup", `--project=${project}`, `--config=${config}`]);
await window.showInformationMessage(`Doppler has been configured for ${project}.${config}`);
}
10 changes: 10 additions & 0 deletions src/lib/doppler/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,14 @@ export class DopplerConfigsProvider {

return response.configs as DopplerConfig[];
}

public async add(project: string, environment: string, name: string) {
const response = await this.request.post('/v3/configs', {
project,
environment,
name: name.trim(),
});

return response.config as DopplerConfig;
}
}
9 changes: 9 additions & 0 deletions src/lib/doppler/environments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,13 @@ export class DopplerEnvironmentsProvider {

return response.environments as DopplerEnvironment[];
}

public async add(project: string, name: string) {
const response = await this.request.post(`/v3/environments?project=${project}`, {
name: name.trim(),
slug: name.trim().replace(/\s/g, '-').toLowerCase()
});

return response.config as DopplerEnvironment;
}
}
9 changes: 9 additions & 0 deletions src/lib/doppler/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,13 @@ export class DopplerProjectsProvider {
const response = await this.request.getAllPages("projects", `/v3/projects`);
return response.projects as DopplerProject[];
}

public async add(name: string, description?: string) {
const response = await this.request.post('/v3/projects', {
name: name.trim(),
description,
});

return response.project as DopplerProject;
}
}
56 changes: 56 additions & 0 deletions src/lib/explorer/editor_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
ProviderResult,
TreeItemCollapsibleState,
ThemeIcon,
window
} from "vscode";
import * as doppler from "../doppler";
import DopplerFileSystemProvider from "./file_system_provider";
Expand Down Expand Up @@ -48,6 +49,60 @@ export default class DopplerEditorProvider implements TreeDataProvider<Entry>, T
commands.registerCommand("doppler.explorer.refresh", () => {
this._onDidChangeTreeData.fire(undefined);
});

commands.registerCommand('doppler.explorer.addProject', async () => {
const input = await window.showInputBox({
placeHolder: 'Project_Name',
prompt: 'Enter name of project',
});
if (input) {
await doppler.projects.add(input);
window.showInformationMessage(`Successfully added ${input}`);
await commands.executeCommand("doppler.explorer.refresh");
}
});

commands.registerCommand(
'doppler.addEnvironment',
async (args: any) => {
const project = args.project;
const input = await window.showInputBox({
placeHolder: 'Environment_Name',
prompt: 'Enter name of environment (no special characters or spaces)',
});
if (input) {
await doppler
.environments.add(project, input);
window.showInformationMessage(
`Successfully added ${input} to ${project}`
);
await commands.executeCommand("doppler.explorer.refresh");
}
}
);
commands.registerCommand(
'doppler.addConfig',
async (args: any) => {
const environment = args.environment;
const project = args.project;
const input = await window.showInputBox({
placeHolder: 'Config_Name',
prompt: 'Enter name of config',
});
if (input) {
await doppler
.configs.add(
project,
environment,
input
);
window.showInformationMessage(
`Successfully added ${input} to ${environment} in ${project}`
);
await commands.executeCommand("doppler.explorer.refresh");
}
}
);
}

// Required part of the TextDocumentContentProvider interface
Expand All @@ -64,6 +119,7 @@ export default class DopplerEditorProvider implements TreeDataProvider<Entry>, T
};

return {
contextValue: element.type.toString(),
iconPath: new ThemeIcon(icons[element.type]),
resourceUri: element.uri,
collapsibleState: element.isDirectory ? TreeItemCollapsibleState.Collapsed : undefined,
Expand Down