Skip to content

Commit

Permalink
only prompt for project if more than one in workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennitz committed Nov 14, 2017
1 parent af1fee6 commit 474c2f3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 30 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Changelog

- 1.0.3: Only prompt for project if more than one project in workspace.
- 1.0.2: Add support for multi root workspaces.
- 1.0.1: Use generact from npm.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"license": "MIT",
"displayName": "generact",
"description": "Generate React components by replicating your own.",
"version": "1.0.2",
"version": "1.0.4",
"publisher": "Dennitz",
"repository": {
"type": "git",
Expand Down
73 changes: 44 additions & 29 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,47 @@ export function activate(context: vscode.ExtensionContext) {
'extension.generact',
async () => {
// The code you place here will be executed every time your command is executed
projectPrompt().then((projectItem: vscode.QuickPickItem | undefined) => {
console.log('projectItem', projectItem);
if (projectItem) {
const root = projectItem.description;
componentPrompt(
root,
).then(async (componentItem: vscode.QuickPickItem | undefined) => {
if (componentItem) {
const name = (await namePrompt(componentItem.label)) || '';
const folder =
(await folderPrompt(
getComponentFolder(componentItem.description),
name,
)) || getComponentFolder(componentItem.description);
if (
!vscode.workspace.workspaceFolders ||
vscode.workspace.workspaceFolders.length === 0
) {
vscode.window.showInformationMessage('You must open a project first.');
} else {
projectPrompt().then(
(projectItem: vscode.QuickPickItem | undefined) => {
if (projectItem) {
const root = projectItem.description;
componentPrompt(
root,
).then(
async (componentItem: vscode.QuickPickItem | undefined) => {
if (componentItem) {
const name = (await namePrompt(componentItem.label)) || '';
const folder =
(await folderPrompt(
getComponentFolder(componentItem.description),
name,
)) || getComponentFolder(componentItem.description);

try {
await replicate(
root + componentItem.description,
{ name, folder },
root,
);
} catch (e) {
vscode.window.showWarningMessage(
'An Error occured while writing.',
);
console.log(e);
}
try {
await replicate(
root + componentItem.description,
{ name, folder },
root,
);
} catch (e) {
vscode.window.showWarningMessage(
'An Error occured while writing.',
);
console.log(e);
}
}
},
);
}
});
}
});
},
);
}
},
);

Expand All @@ -62,6 +72,11 @@ function projectPrompt() {
}));
}

if (projects.length === 1) {
// wrapped in a promise to have a single return type
return Promise.resolve(projects[0]);
}

return vscode.window.showQuickPick(projects, options);
}

Expand Down

0 comments on commit 474c2f3

Please sign in to comment.