This repository has been archived by the owner on Nov 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
initializeWebUi.js
79 lines (71 loc) · 3.27 KB
/
initializeWebUi.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
'use strict'
const initializeWebCommand = {
command: 'ui:initializeWeb',
usage: 'ui:initializeWeb <ui-name> <target-repository> [<ui-repository>]',
description: 'Initializes the target repository using git as a fork of SCEPTER-webui or the provided ui-repository uri, then adds it as a submodule into the target ui-name subfolder within the ui folder. A blank <target-repository> must be created first to receive the forked code.',
callback: callbackFunction,
executeCloneCommand: executeCloneCommandFunction,
executeRepositoryModificationCommands: executeRepositoryModificationFunction,
executeInitializeRepositoryCommand: executeInitializeRepositoryFunction,
executeAddUiAsSubmoduleCommand: executeAddUiAsSubmoduleFunction,
executeInstallCommand: executeInstallFunction
}
function callbackFunction (args, credentials, command) {
const forkRepository = args[5] || 'git@github.com:source4societyorg/SCEPTER-webui.git'
const targetRepository = args[4]
const uiName = args[3]
if (typeof uiName === 'undefined' || typeof targetRepository === 'undefined') {
command.printMessage('Usage: node bin/scepter ' + initializeWebCommand.usage)
} else {
this.uiName = uiName
this.targetRepository = targetRepository
this.forkRepository = forkRepository
this.executeCloneCommand(command)
}
}
function executeCloneCommandFunction (command) {
command.executeCommand(
'git clone ' + initializeWebCommand.forkRepository + ' ui/' + initializeWebCommand.uiName + ' --recursive',
'UI has been created successfully',
'Failed to create the ui folder',
initializeWebCommand.executeRepositoryModificationCommands
)
}
function executeRepositoryModificationFunction (command) {
command.executeCommand(
'cd ui/' + initializeWebCommand.uiName + '; git remote rm origin',
'Disconnected repository from the remote boilerplate repository',
'Failed to disconnect from the remote repository',
initializeWebCommand.executeInitializeRepositoryCommand
)
}
function executeInitializeRepositoryFunction (command) {
command.executeCommand(
'cd ui/' + initializeWebCommand.uiName + ';git remote add origin ' + initializeWebCommand.targetRepository + '; git push origin master',
'Successfully forked ' + initializeWebCommand.forkRepository + ' into ' + initializeWebCommand.targetRepository,
'Failed to fork source repository',
initializeWebCommand.executeAddUiAsSubmoduleCommand
)
}
function executeAddUiAsSubmoduleFunction (command) {
let commandStringArgument = ''
const shell = typeof command.parameters !== 'undefined' ? command.parameters.shell : 'bash'
switch (shell) {
case 'powershell':
commandStringArgument = 'o'
}
command.executeCommand(
'rm -r -f' + commandStringArgument + ' ./ui/' + initializeWebCommand.uiName + '; git submodule add --force ' + initializeWebCommand.targetRepository + ' ui/' + initializeWebCommand.uiName,
'Added UI as submodule to project under ui/' + initializeWebCommand.uiName,
'Failed to add UI as submodule',
initializeWebCommand.executeInstallCommand
)
}
function executeInstallFunction (command) {
command.executeCommand(
'cd ui/' + initializeWebCommand.uiName + ';yarn install',
'Dependencies installed',
'Failed to install dependencies'
)
}
module.exports = initializeWebCommand