|
2 | 2 | // Import the module and reference it with the alias vscode in your code below |
3 | 3 | const vscode = require(`vscode`); |
4 | 4 |
|
| 5 | +const {instance, Field, CustomUI} = vscode.extensions.getExtension(`halcyontechltd.code-for-ibmi`).exports; |
| 6 | + |
5 | 7 | const statusView = require(`./src/views/status`); |
6 | 8 | const commitView = require(`./src/views/commits`); |
7 | 9 | const fileHistory = require(`./src/views/fileHistory`); |
@@ -53,6 +55,78 @@ function activate(context) { |
53 | 55 | doc.fileName = relativePath; |
54 | 56 | await vscode.window.showTextDocument(doc, { preview: false }); |
55 | 57 | }), |
| 58 | + |
| 59 | + vscode.commands.registerCommand(`git-client-ibmi.createGitLibs`, async () => { |
| 60 | + const connection = instance.getConnection(); |
| 61 | + |
| 62 | + if (connection) { |
| 63 | + let wizard = new CustomUI(); |
| 64 | + let field; |
| 65 | + |
| 66 | + // field = new Field(`text`, `info1`); |
| 67 | + // field.description = `This wizard will setup the configuration to make sure that source members are copied into a specific directory when saved - and also vice-versa when 'restored'/'checkout' from git when undoing changes. This is really the start of tracking your source members into a git repository. These settings apply to all users who use this extension as they are saved onto the IFS for all users. This attempts to create <code>/.gitlibs.json</code> in the IFS.`; |
| 68 | + // wizard.addField(field); |
| 69 | + |
| 70 | + field = new Field(`input`, `library`, `Source library`); |
| 71 | + field.description = `The library which contains the source. Whenever you save a member which resides in this library (in any source file), then it will be copies to the directory you specify.`; |
| 72 | + wizard.addField(field); |
| 73 | + |
| 74 | + field = new Field(`input`, `ifsPath`, `IFS path`); |
| 75 | + field.description = `The directory in which the source will be copied to. This directory is usually a git repository.` |
| 76 | + wizard.addField(field); |
| 77 | + |
| 78 | + field = new Field(`input`, `asp`, `ASP (optional)`); |
| 79 | + field.description = `If this library resides in an ASP, you should specify it here - otherwise leave it blank. If you don't provide one where it is needed, you may have issues restoring from git.` |
| 80 | + wizard.addField(field); |
| 81 | + |
| 82 | + field = new Field(`submit`, `doSubmitThingy`, `Setup`); |
| 83 | + wizard.addField(field); |
| 84 | + |
| 85 | + const {panel, data} = await wizard.loadPage(`Setup git library`); |
| 86 | + |
| 87 | + if (data) { |
| 88 | + panel.dispose(); |
| 89 | + |
| 90 | + if (data.asp.trim() === ``) data.asp = undefined; |
| 91 | + |
| 92 | + const content = instance.getContent(); |
| 93 | + |
| 94 | + /** @type {string} */ |
| 95 | + let jsonContent; |
| 96 | + let gitlibs; |
| 97 | + |
| 98 | + try { |
| 99 | + jsonContent = await content.downloadStreamfile(`/.gitlibs.json`); |
| 100 | + } catch (e) { |
| 101 | + //Doesn't exist... |
| 102 | + gitlibs = []; |
| 103 | + } |
| 104 | + |
| 105 | + if (jsonContent) { |
| 106 | + try { |
| 107 | + gitlibs = JSON.parse(jsonContent); |
| 108 | + } catch (e) { |
| 109 | + vscode.window.showErrorMessage(`Unable to read /.gitlibs.json. Invalid JSON.`); |
| 110 | + } |
| 111 | + } |
| 112 | + |
| 113 | + if (gitlibs) { |
| 114 | + try { |
| 115 | + gitlibs.push(data); |
| 116 | + await content.writeStreamfile(`/.gitlibs.json`, JSON.stringify(gitlibs, null, 2)); |
| 117 | + |
| 118 | + vscode.window.showInformationMessage(`.gitlibs.json updated.`); |
| 119 | + |
| 120 | + } catch (e) { |
| 121 | + vscode.window.showErrorMessage(`Unable to update /.gitlibs.json. ${e.message || e}`); |
| 122 | + } |
| 123 | + } |
| 124 | + |
| 125 | + } |
| 126 | + } else { |
| 127 | + vscode.window.showInformationMessage(`Connection to IBM i required to run wizard.`); |
| 128 | + } |
| 129 | + }), |
56 | 130 | ); |
57 | 131 | } |
58 | 132 |
|
|
0 commit comments