Skip to content

Commit

Permalink
New feature: module installation
Browse files Browse the repository at this point in the history
  • Loading branch information
gdlcf88 committed Oct 22, 2020
1 parent f677ed8 commit 53c2648
Show file tree
Hide file tree
Showing 6 changed files with 557 additions and 29 deletions.
8 changes: 4 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
<link rel="import" href="sections/abp-cli/abp-cli-translate.html">
<link rel="import" href="sections/abp-cli/abp-cli-account.html">
<link rel="import" href="sections/abphelper-cli/abphelper-cli-installation.html">
<link rel="import" href="sections/abphelper-cli/abphelper-cli-module.html">
<link rel="import" href="sections/abphelper-cli/abphelper-cli-generate-crud.html">
<link rel="import" href="sections/abphelper-cli/abphelper-cli-generate-appService.html">
<link rel="import" href="sections/abphelper-cli/abphelper-cli-generate-controller.html">
<link rel="import" href="sections/abphelper-cli/abphelper-cli-generate-localization.html">
<link rel="import" href="sections/abphelper-cli/abphelper-cli-ef-migrations.html">
<link rel="import" href="sections/modules-manager/modules-manager-installer.html">
<link rel="import" href="sections/modules-manager/modules-manager-market.html">
<!-- <link rel="import" href="sections/awesome-tools/awesome-tools-ef-provider.html"> -->
</head>
Expand All @@ -44,7 +44,7 @@ <h5 class="nav-category">
<svg class="nav-icon"><use xlink:href="assets/img/icons.svg#icon-windows"></use></svg>
Abp CLI
</h5>
<button type="button" id="button-abp-cli-installation" data-section="abp-cli-installation" class="nav-button">Install or update <em>Abp CLI</em></button>
<button type="button" id="button-abp-cli-installation" data-section="abp-cli-installation" class="nav-button">Install <em>Abp CLI</em></button>
<button type="button" id="button-abp-cli-new" data-section="abp-cli-new" class="nav-button">Generate a <em>new</em> Abp solution</button>
<button type="button" id="button-abp-cli-update" data-section="abp-cli-update" class="nav-button"><em>Update</em> framework and modules</button>
<button type="button" id="button-abp-cli-add" data-section="abp-cli-add" class="nav-button"><em>Add</em> an Abp package or module</button>
Expand All @@ -59,7 +59,8 @@ <h5 class="nav-category">
<svg class="nav-icon"><use xlink:href="assets/img/icons.svg#icon-windows"></use></svg>
AbpHelper CLI
</h5>
<button type="button" id="button-abphelper-cli-installation" data-section="abphelper-cli-installation" class="nav-button">Install or update <em>AbpHelper CLI</em></button>
<button type="button" id="button-abphelper-cli-installation" data-section="abphelper-cli-installation" class="nav-button">Install <em>AbpHelper CLI</em></button>
<button type="button" id="button-abphelper-cli-module" data-section="abphelper-cli-module" class="nav-button">Install community <em>modules</em></button>
<button type="button" id="button-abphelper-cli-generate-crud" data-section="abphelper-cli-generate-crud" class="nav-button">Generate <em>CRUD</em></button>
<button type="button" id="button-abphelper-cli-generate-appService" data-section="abphelper-cli-generate-appService" class="nav-button">Generate <em>AppService</em></button>
<button type="button" id="button-abphelper-cli-generate-controller" data-section="abphelper-cli-generate-controller" class="nav-button">Generate <em>controller</em></button>
Expand All @@ -72,7 +73,6 @@ <h5 class="nav-category">
<svg class="nav-icon"><use xlink:href="assets/img/icons.svg#icon-windows"></use></svg>
Modules Manager
</h5>
<button type="button" id="button-modules-manager-installer" data-section="modules-manager-installer" class="nav-button"><em>Install</em> or update community modules</button>
<button type="button" id="button-modules-manager-market" data-section="modules-manager-market" class="nav-button">Explore the Abp <em>module market</em></button>
</div>

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "abphelper-gui",
"productName": "AbpHelper",
"version": "0.6.0",
"version": "0.7.0",
"description": "AbpHelper is a tool that helps you with developing Abp vNext applications.",
"main": "main.js",
"bin": "cli.js",
Expand Down
167 changes: 167 additions & 0 deletions renderer-process/abphelper-cli/abphelper-cli-module-add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
const { dialog } = require('electron').remote
const exec = require('child_process').exec

let isRunning = false

let extraOptions = {
shared: true,
domain: true,
efcore: true,
mongodb: false,
contracts: true,
application: true,
httpapi: true,
client: true,
web: true
}

let consoleNode = document.getElementById('box-abphelper-cli-module-add').getElementsByTagName('textarea')[0]

const execBtn = document.getElementById('module-add-execute')
const selectSolutionFileBtn = document.getElementById('module-add-select-solution-file-btn')
const extraOptionsCheckBox = {
shared: document.getElementById('module-add-options-shared'),
domain: document.getElementById('module-add-options-domain'),
efcore: document.getElementById('module-add-options-efcore'),
mongodb: document.getElementById('module-add-options-mongodb'),
contracts: document.getElementById('module-add-options-contracts'),
application: document.getElementById('module-add-options-application'),
httpapi: document.getElementById('module-add-options-httpapi'),
client: document.getElementById('module-add-options-client'),
web: document.getElementById('module-add-options-web')
}

selectSolutionFileBtn.addEventListener('click', (event) => {
dialog.showOpenDialog({
filters: [
{ name: 'Abp Solution', extensions: ['sln'] },
],
properties: ['openFile']
}).then(result => {
if (result.filePaths[0]) {
document.getElementById('module-add-solution-file').value = result.filePaths[0]
}
}).catch(err => {
console.log(err)
})
})

function findLastStr(str, cha, num) {
let times = num == 0 ? 1 : num;
var x = str.lastIndexOf(cha);
for (var i = 0; i < times - 1; i++) {
x = str.lastIndexOf(cha, x - 1);
}
return x;
}

function getSolutionRootPath(slnFilePath) {
let separator = slnFilePath.indexOf('/') != -1 ? '/' : '\\'
return slnFilePath.substr(0, findLastStr(slnFilePath, separator, 1))
}

execBtn.addEventListener('click', (event) => {
runExec()
})

extraOptionsCheckBox.shared.addEventListener('click', (event) => {
extraOptions.shared = extraOptionsCheckBox.shared.checked
})

extraOptionsCheckBox.domain.addEventListener('click', (event) => {
extraOptions.domain = extraOptionsCheckBox.domain.checked
})

extraOptionsCheckBox.efcore.addEventListener('click', (event) => {
extraOptions.efcore = extraOptionsCheckBox.efcore.checked
})

extraOptionsCheckBox.mongodb.addEventListener('click', (event) => {
extraOptions.mongodb = extraOptionsCheckBox.mongodb.checked
})

extraOptionsCheckBox.contracts.addEventListener('click', (event) => {
extraOptions.contracts = extraOptionsCheckBox.contracts.checked
})

extraOptionsCheckBox.application.addEventListener('click', (event) => {
extraOptions.application = extraOptionsCheckBox.application.checked
})

extraOptionsCheckBox.httpapi.addEventListener('click', (event) => {
extraOptions.httpapi = extraOptionsCheckBox.httpapi.checked
})

extraOptionsCheckBox.client.addEventListener('click', (event) => {
extraOptions.client = extraOptionsCheckBox.client.checked
})

extraOptionsCheckBox.web.addEventListener('click', (event) => {
extraOptions.web = extraOptionsCheckBox.web.checked
})

function addDoubleQuote(str) {
return '"' + str + '"'
}

function runExec() {
let moduleName = document.getElementById('module-add-moduleName').value
let solutionFile = document.getElementById('module-add-solution-file').value
let version = document.getElementById('module-add-options-version').value
let exclude = document.getElementById('module-add-options-exclude').value
if (isRunning || !moduleName || !solutionFile) return

let solutionRootPath = getSolutionRootPath(solutionFile)
if (!solutionRootPath) return

isRunning = true
execBtn.disabled = true
document.getElementById('module-add-process').style.display = 'block'

let cliCommand = process.platform === 'win32' ? '%USERPROFILE%\\.dotnet\\tools\\abphelper' : '$HOME/.dotnet/tools/abphelper'
let cmdStr = cliCommand + ' module add ' + moduleName + ' -d ' + addDoubleQuote(solutionRootPath)
if (extraOptions.shared) cmdStr += ' --shared'
if (extraOptions.domain) cmdStr += ' --domain'
if (extraOptions.efcore) cmdStr += ' --entity-framework-core'
if (extraOptions.mongodb) cmdStr += ' --mongo-db'
if (extraOptions.contracts) cmdStr += ' --contracts'
if (extraOptions.application) cmdStr += ' --application'
if (extraOptions.httpapi) cmdStr += ' --http-api'
if (extraOptions.client) cmdStr += ' --client'
if (extraOptions.web) cmdStr += ' --web'
if (version) cmdStr += ' --version ' + version
if (exclude) cmdStr += ' --exclude ' + exclude
clearConsoleContent()
addConsoleContent(cmdStr + '\n\nRunning...\n')
scrollConsoleToBottom()
console.log(cmdStr)
if (process.platform === 'win32') cmdStr = '@chcp 65001 >nul & cmd /d/s/c ' + cmdStr
workerProcess = exec(cmdStr, {cwd: '/'})

workerProcess.stdout.on('data', function (data) {
addConsoleContent(data)
scrollConsoleToBottom()
});

workerProcess.stderr.on('data', function (data) {
addConsoleContent(data)
scrollConsoleToBottom()
});

workerProcess.on('close', function (code) {
isRunning = false
execBtn.disabled = false
})

function scrollConsoleToBottom() {
consoleNode.scrollTo(0, consoleNode.scrollHeight)
}

function addConsoleContent(text) {
consoleNode.appendChild(document.createTextNode(text))
}

function clearConsoleContent() {
consoleNode.innerHTML = ''
}
}
165 changes: 165 additions & 0 deletions renderer-process/abphelper-cli/abphelper-cli-module-remove.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
const { dialog } = require('electron').remote
const exec = require('child_process').exec

let isRunning = false

let extraOptions = {
shared: true,
domain: true,
efcore: true,
mongodb: false,
contracts: true,
application: true,
httpapi: true,
client: true,
web: true
}

let consoleNode = document.getElementById('box-abphelper-cli-module-remove').getElementsByTagName('textarea')[0]

const execBtn = document.getElementById('module-remove-execute')
const selectSolutionFileBtn = document.getElementById('module-remove-select-solution-file-btn')
const extraOptionsCheckBox = {
shared: document.getElementById('module-remove-options-shared'),
domain: document.getElementById('module-remove-options-domain'),
efcore: document.getElementById('module-remove-options-efcore'),
mongodb: document.getElementById('module-remove-options-mongodb'),
contracts: document.getElementById('module-remove-options-contracts'),
application: document.getElementById('module-remove-options-application'),
httpapi: document.getElementById('module-remove-options-httpapi'),
client: document.getElementById('module-remove-options-client'),
web: document.getElementById('module-remove-options-web')
}

selectSolutionFileBtn.addEventListener('click', (event) => {
dialog.showOpenDialog({
filters: [
{ name: 'Abp Solution', extensions: ['sln'] },
],
properties: ['openFile']
}).then(result => {
if (result.filePaths[0]) {
document.getElementById('module-remove-solution-file').value = result.filePaths[0]
}
}).catch(err => {
console.log(err)
})
})

function findLastStr(str, cha, num) {
let times = num == 0 ? 1 : num;
var x = str.lastIndexOf(cha);
for (var i = 0; i < times - 1; i++) {
x = str.lastIndexOf(cha, x - 1);
}
return x;
}

function getSolutionRootPath(slnFilePath) {
let separator = slnFilePath.indexOf('/') != -1 ? '/' : '\\'
return slnFilePath.substr(0, findLastStr(slnFilePath, separator, 1))
}

execBtn.addEventListener('click', (event) => {
runExec()
})

extraOptionsCheckBox.shared.addEventListener('click', (event) => {
extraOptions.shared = extraOptionsCheckBox.shared.checked
})

extraOptionsCheckBox.domain.addEventListener('click', (event) => {
extraOptions.domain = extraOptionsCheckBox.domain.checked
})

extraOptionsCheckBox.efcore.addEventListener('click', (event) => {
extraOptions.efcore = extraOptionsCheckBox.efcore.checked
})

extraOptionsCheckBox.mongodb.addEventListener('click', (event) => {
extraOptions.mongodb = extraOptionsCheckBox.mongodb.checked
})

extraOptionsCheckBox.contracts.addEventListener('click', (event) => {
extraOptions.contracts = extraOptionsCheckBox.contracts.checked
})

extraOptionsCheckBox.application.addEventListener('click', (event) => {
extraOptions.application = extraOptionsCheckBox.application.checked
})

extraOptionsCheckBox.httpapi.addEventListener('click', (event) => {
extraOptions.httpapi = extraOptionsCheckBox.httpapi.checked
})

extraOptionsCheckBox.client.addEventListener('click', (event) => {
extraOptions.client = extraOptionsCheckBox.client.checked
})

extraOptionsCheckBox.web.addEventListener('click', (event) => {
extraOptions.web = extraOptionsCheckBox.web.checked
})

function addDoubleQuote(str) {
return '"' + str + '"'
}

function runExec() {
let moduleName = document.getElementById('module-remove-moduleName').value
let solutionFile = document.getElementById('module-remove-solution-file').value
let exclude = document.getElementById('module-remove-options-exclude').value
if (isRunning || !moduleName || !solutionFile) return

let solutionRootPath = getSolutionRootPath(solutionFile)
if (!solutionRootPath) return

isRunning = true
execBtn.disabled = true
document.getElementById('module-remove-process').style.display = 'block'

let cliCommand = process.platform === 'win32' ? '%USERPROFILE%\\.dotnet\\tools\\abphelper' : '$HOME/.dotnet/tools/abphelper'
let cmdStr = cliCommand + ' module remove ' + moduleName + ' -d ' + addDoubleQuote(solutionRootPath)
if (extraOptions.shared) cmdStr += ' --shared'
if (extraOptions.domain) cmdStr += ' --domain'
if (extraOptions.efcore) cmdStr += ' --entity-framework-core'
if (extraOptions.mongodb) cmdStr += ' --mongo-db'
if (extraOptions.contracts) cmdStr += ' --contracts'
if (extraOptions.application) cmdStr += ' --application'
if (extraOptions.httpapi) cmdStr += ' --http-api'
if (extraOptions.client) cmdStr += ' --client'
if (extraOptions.web) cmdStr += ' --web'
if (exclude) cmdStr += ' --exclude ' + exclude
clearConsoleContent()
addConsoleContent(cmdStr + '\n\nRunning...\n')
scrollConsoleToBottom()
console.log(cmdStr)
if (process.platform === 'win32') cmdStr = '@chcp 65001 >nul & cmd /d/s/c ' + cmdStr
workerProcess = exec(cmdStr, {cwd: '/'})

workerProcess.stdout.on('data', function (data) {
addConsoleContent(data)
scrollConsoleToBottom()
});

workerProcess.stderr.on('data', function (data) {
addConsoleContent(data)
scrollConsoleToBottom()
});

workerProcess.on('close', function (code) {
isRunning = false
execBtn.disabled = false
})

function scrollConsoleToBottom() {
consoleNode.scrollTo(0, consoleNode.scrollHeight)
}

function addConsoleContent(text) {
consoleNode.appendChild(document.createTextNode(text))
}

function clearConsoleContent() {
consoleNode.innerHTML = ''
}
}
Loading

0 comments on commit 53c2648

Please sign in to comment.