Skip to content

Commit 5c3666e

Browse files
committed
Preinstall PS Gallery
1 parent 18a2710 commit 5c3666e

File tree

5 files changed

+65
-14
lines changed

5 files changed

+65
-14
lines changed

tools/office-cmdlet-updater/constants/commands.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
module.exports = {
22
GET_TEAM: 'Get-Team',
3+
INSTALL_PS_GALLERY: 'Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted',
34
INSTALL_PACKAGE_PROVIDER: 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force',
45
INSTALL_MICROSOFT_TEAM: 'Install-Module MicrosoftTeams -SkipPublisherCheck -Force',
56
CONNECT_MICROSOFT_TEAM: 'Connect-MicrosoftTeams',
67
INSTALL_PLATYPS: 'Install-Module -Name platyPS -SkipPublisherCheck -Scope CurrentUser -Force',
78
IMPORT_PLATYPS: 'Import-Module platyPS',
89
UPDATE_MARKDOWN: 'Update-MarkdownHelp -Path "{}" -LogPath "{}" -Session $Session',
9-
SKYPE_SET_POLICY: 'Set-ExecutionPolicy RemoteSigned ',
10-
SKYPE_INSTALL_MODULE: 'Import-Module "C:\\\\Program Files\\\\Common Files\\\\Skype for Business Online\\\\Modules\\\\SkypeOnlineConnector\\\\SkypeOnlineConnector.psd1" -Force',
10+
SKYPE_ENABLE_WIN_RM: 'sc.exe start WinRM',
11+
SKYPE_INSTALL_LYNC_MODULE: 'Import-Module LyncOnlineConnector',
12+
SKYPE_INSTALL_MODULE: 'Import-Module SkypeOnlineConnector -Force',
1113
SKYPE_GET_CRED: '$cred = Get-Credential',
1214
SKYPE_CREATE_SESSION: '$session = New-CsOnlineSession -Credential $cred -Verbose',
13-
SKYPE_IMPORT_SESSION: 'Import-PSSession -Session $session',
15+
SKYPE_IMPORT_SESSION: 'Import-PSSession -Session $session -Verbose',
1416
SHAREPOINT_INSTALL_MODULE: 'Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking',
1517
WHITEBOARD_INSTALL_MODULE: 'Install-Module -Name WhiteboardAdmin -Force',
1618
EXCHANGE_INSTALL_MODULE: 'Install-Module -Name ExchangeOnlineShell -Force',

tools/office-cmdlet-updater/constants/errors.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
module.exports.powerShellErrors = {
2+
PS_GALLERY_INSTALL_ERROR: "You should using x64 version of PowerShell",
23
DOC_PATH_DOESNT_EXIST: "Path to documentation folder doesn't exist",
34
INSTALL_PLATYPS_ERROR: "Can't install 'platyPS' module",
45
IMPORT_PLATYPS_ERROR: "Cant't import 'platyPS' module",
56
INSTALL_MICROSOFT_TEAM_ERROR: "Can't install 'Microsoft team' module",
6-
AUTH_MICROSOFT_TEAM_ERROR: "Can't auth into 'Microsoft team'"
7+
AUTH_MICROSOFT_TEAM_ERROR: "Can't auth into 'Microsoft team'",
8+
EMPTY_CONFIG_CREDENTIALS: "Empty credentials fields in a config file. Please, feel 'platyPS.credentials' section into a config file"
79
};
810

911
module.exports.markdownErrors = {

tools/office-cmdlet-updater/controllers/cli.controller.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,18 @@ class CliController {
6565
createPr: isNeedPullRequest
6666
} = cli;
6767

68-
await this.markdownController.updateMarkdown({
69-
cliModuleName,
70-
cliCmdletName,
71-
isNeedPullRequest,
72-
isNeedEmail
73-
});
68+
await this.markdownController
69+
.updateMarkdown({
70+
cliModuleName,
71+
cliCmdletName,
72+
isNeedPullRequest,
73+
isNeedEmail
74+
})
75+
.catch((err) => {
76+
console.error(err);
77+
78+
this.powerShellService.dispose();
79+
});
7480
});
7581
}
7682
}

tools/office-cmdlet-updater/services/cmdlet.dependencies.service.js

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const commands = require('../constants/commands');
2+
const errors = require('../constants/errors');
23
const format = require('string-format');
34

45
class CmdletDependenciesService {
@@ -8,7 +9,7 @@ class CmdletDependenciesService {
89
}
910

1011
async installDependencies({ cmdletName }) {
11-
await this.installPlatyPs();
12+
await this.installGlobalDependencies();
1213

1314
switch (cmdletName) {
1415
case 'teams': {
@@ -39,15 +40,31 @@ class CmdletDependenciesService {
3940
await this.preInstallStuffHub();
4041
break;
4142
}
43+
default: {
44+
45+
}
4246
}
4347
}
4448

49+
async installGlobalDependencies() {
50+
await this.installPsGallery();
51+
await this.installPlatyPs();
52+
}
53+
4554
async installPlatyPs() {
4655
await this.ps.invokeCommand(commands.INSTALL_PACKAGE_PROVIDER);
4756
await this.ps.invokeCommand(commands.INSTALL_PLATYPS);
4857
await this.ps.invokeCommand(commands.IMPORT_PLATYPS);
4958
}
5059

60+
async installPsGallery() {
61+
try {
62+
await this.ps.invokeCommand(commands.INSTALL_PS_GALLERY);
63+
} catch (e) {
64+
throw errors.powerShellErrors.PS_GALLERY_INSTALL_ERROR;
65+
}
66+
}
67+
5168
async preInstallTeams() {
5269
// TODO: check if user already auth
5370

@@ -62,7 +79,14 @@ class CmdletDependenciesService {
6279
async preInstallSkype({ login, pass }) {
6380
await this._createCredInPs({ login, pass });
6481

65-
// await this.ps.invokeCommand(commands.SKYPE_INSTALL_MODULE);
82+
await this.ps.invokeCommandAndIgnoreError({
83+
command: commands.SKYPE_ENABLE_WIN_RM,
84+
printError: true
85+
});
86+
87+
//await this.ps.invokeCommand(commands.SKYPE_GET_CRED);
88+
await this.ps.invokeCommand(commands.SKYPE_INSTALL_LYNC_MODULE);
89+
await this.ps.invokeCommand(commands.SKYPE_INSTALL_MODULE);
6690
await this.ps.invokeCommand(commands.SKYPE_CREATE_SESSION);
6791
await this.ps.invokeCommand(commands.SKYPE_IMPORT_SESSION);
6892
}
@@ -74,6 +98,11 @@ class CmdletDependenciesService {
7498
async preInstallExchange({ login, pass }) {
7599
await this._createCredInPs({ login, pass });
76100

101+
await this.ps.invokeCommandAndIgnoreError({
102+
command: commands.SKYPE_ENABLE_WIN_RM,
103+
printError: true
104+
});
105+
77106
//await this.ps.invokeCommand(commands.EXCHANGE_INSTALL_MODULE);
78107
await this.ps.invokeCommand(commands.EXCHANGE_GET_SESSION);
79108
await this.ps.invokeCommand(commands.EXCHANGE_SESSION_IMPORT);
@@ -88,7 +117,7 @@ class CmdletDependenciesService {
88117
const { login, pass } = this.config.get('platyPS.credentials');
89118

90119
if (!login || !pass) {
91-
throw new Error('Invalid credentials');
120+
throw new Error(errors.powerShellErrors.EMPTY_CONFIG_CREDENTIALS);
92121
}
93122

94123
return { login, pass };

tools/office-cmdlet-updater/services/power.shell.service.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class PowerShellService {
77
constructor(config) {
88
this.config = config;
99
this.ps = new Shell({
10-
executionPolicy: 'Bypass',
10+
executionPolicy: 'Unrestricted',
1111
noProfile: true
1212
});
1313
}
@@ -32,6 +32,18 @@ class PowerShellService {
3232
return output;
3333
}
3434

35+
async invokeCommandAndIgnoreError({ command, printError = false }) {
36+
await this.ps.addCommand(command);
37+
38+
const [output, err] = await of(this.ps.invoke());
39+
40+
if (err && printError) {
41+
console.error(err);
42+
}
43+
44+
return output;
45+
}
46+
3547
async dispose() {
3648
return await this.ps.dispose();
3749
}

0 commit comments

Comments
 (0)