Skip to content
This repository was archived by the owner on Aug 15, 2022. It is now read-only.

Commit fd2b045

Browse files
committed
Wizard to create gitlibs JSON config
1 parent 01b0b82 commit fd2b045

File tree

3 files changed

+84
-1
lines changed

3 files changed

+84
-1
lines changed

extension.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Import the module and reference it with the alias vscode in your code below
33
const vscode = require(`vscode`);
44

5+
const {instance, Field, CustomUI} = vscode.extensions.getExtension(`halcyontechltd.code-for-ibmi`).exports;
6+
57
const statusView = require(`./src/views/status`);
68
const commitView = require(`./src/views/commits`);
79
const fileHistory = require(`./src/views/fileHistory`);
@@ -53,6 +55,78 @@ function activate(context) {
5355
doc.fileName = relativePath;
5456
await vscode.window.showTextDocument(doc, { preview: false });
5557
}),
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+
}),
56130
);
57131
}
58132

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"Other"
2828
],
2929
"activationEvents": [
30+
"onCommand:git-client-ibmi.createGitLibs",
3031
"onView:git-client-ibmi.status",
3132
"onCommand:git-client-ibmi.status.refresh",
3233
"onCommand:git-client-ibmi.status.add",
@@ -43,7 +44,13 @@
4344
],
4445
"main": "./extension",
4546
"contributes": {
46-
"commands": [{
47+
"commands": [
48+
{
49+
"command": "git-client-ibmi.createGitLibs",
50+
"title": "Configure new git library",
51+
"category": "Git on IBM i"
52+
},
53+
{
4754
"command": "git-client-ibmi.status.refresh",
4855
"title": "Refresh status view",
4956
"category": "Git on IBM i",

src/views/status.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ module.exports = class Status {
233233
if (gitlibs) {
234234
let isValid = true;
235235

236+
if (gitlibs.length === undefined) isValid = false;
237+
236238
for (const configItem of gitlibs) {
237239
if (typeof configItem.library !== `string` || typeof configItem.ifsPath !== `string`) {
238240
isValid = false;

0 commit comments

Comments
 (0)