add programatic and command line build tool with TypeScript declaration

This commit is contained in:
cutls
2021-04-14 13:58:21 +09:00
parent 8621b66203
commit a8f060578a
9 changed files with 144 additions and 87 deletions

7
app/build.d.ts vendored Normal file
View File

@@ -0,0 +1,7 @@
declare function _exports(options?: {
onlyStore?: boolean;
withStore?: boolean;
withIa32?: boolean;
withArm64?: boolean;
}): void;
export = _exports;

View File

@@ -8,6 +8,7 @@ const version = data.version
const codename = data.codename
const ver = `${version} (${codename})`
const construct = require('./view/make/make.js')
const { ModuleResolutionKind } = require('typescript')
const { platform, arch } = process
const Platform = builder.Platform
const Arch = builder.Arch
@@ -62,12 +63,15 @@ async function build(os, arch, config) {
publish: 'never'
})
}
async function cmd() {
if (isTrue('onlyStore') || isTrue('withStore')) {
async function cmd(options) {
if (isTrue(options, 'help', 'h')) {
return console.log(help())
}
if (isTrue(options, 'onlyStore') || isTrue(options, 'withStore')) {
console.log('start building for application stores')
construct(ver, basefile, false, true)
if (platform == 'win32') {
if ((isTrue('withIa32') && arch == 'x64') || arch == 'ia32') {
if ((isTrue(options, 'withIa32') && arch == 'x64') || arch == 'ia32') {
await build(Platform.WINDOWS, Arch.ia32, config)
fs.renameSync(
`../build/TheDesk ${version}.exe`,
@@ -93,12 +97,12 @@ async function cmd() {
if (arch == 'ia32') {
await build(Platform.LINUX, Arch.ia32, config)
}
if ((isTrue('withIa32') && arch == 'x64')) {
if ((isTrue(options, 'withIa32') && arch == 'x64')) {
console.log('snapcraft does not curretly support builing i386 on amd64')
}
if (arch == 'x64') {
await build(Platform.LINUX, Arch.x64, config)
if (!isTrue('onlyStore')) {
if (!isTrue(options, 'onlyStore')) {
fs.renameSync(
`../build/thedesk_${version}_amd64.snap`,
`../build/thedesk_${version}_amd64-store.snap`
@@ -111,11 +115,11 @@ async function cmd() {
return false
}
}
if (!isTrue('onlyStore')) {
if (!isTrue(options, 'onlyStore')) {
console.log('start building for normal usage')
construct(ver, basefile, false, false)
if (platform == 'win32') {
if ((isTrue('withIa32') && arch == 'x64') || arch == 'ia32') {
if ((isTrue(options, 'withIa32') && arch == 'x64') || arch == 'ia32') {
await build(Platform.WINDOWS, Arch.ia32, config)
fs.renameSync(
`../build/TheDesk ${version}.exe`,
@@ -133,7 +137,7 @@ async function cmd() {
'../build/TheDesk.exe'
)
}
if (isTrue('withArm64')) {
if ((isTrue(options, 'withArm64') && arch == 'x64') || arch == 'arm64') {
await build(Platform.WINDOWS, Arch.arm64, config)
fs.renameSync(
`../build/TheDesk ${version}.exe`,
@@ -148,7 +152,7 @@ async function cmd() {
if (arch == 'ia32') {
await build(Platform.LINUX, Arch.ia32, config)
}
if ((isTrue('withIa32') && arch == 'x64')) {
if (isTrue(options, 'withIa32') && arch == 'x64') {
console.log('snapcraft does not curretly support builing i386 on amd64')
}
if (arch == 'x64') {
@@ -157,7 +161,7 @@ async function cmd() {
`../build/thedesk_${version}_amd64.snap`,
`../build/thedesk_${version}_amd64-normal.snap`
)
if (isTrue('onlyStore') || isTrue('withStore')) {
if (isTrue(options, 'onlyStore') || isTrue(options, 'withStore')) {
fs.renameSync(
`../build/thedesk_${version}_amd64-store.snap`,
`../build/thedesk_${version}_amd64.snap`
@@ -171,10 +175,42 @@ async function cmd() {
}
}
}
function isTrue(long, short) {
function isTrue(options, long, short) {
const { argv } = process
if (options ? options[long] : 0) return true
if (argv.includes(`--${long}`)) return true
if (short && argv.includes(`-${short}`)) return true
return false
}
cmd()
function help() {
return `
TheDesk Builder command tool
yarn build [options] (or node build.js [options])
yarn build:[preset] (check package.json)
--help or -h: show help
--onlyStore: App Store of platforms assets(without update check)
--withStore: App Store assets and normal version
[only Windows]
if you pass these args on Linux or macOS, it just will be ignored...
--withIa32: ia32 build on x64 system(if your machine is ia32, it will be built if this arg is not passed)
--withArm64(beta) arm64 build on x64 system(if your machine is arm64, it will be built if this arg is not passed, and not build store build for arm64)
Programatic usage
`
}
/**
* Builder
* @module builder
* @param {Object} [options] - Options
* @param {boolean} [options.onlyStore] - App Store of platforms assets(without update check)
* @param {boolean} [options.withStore] - App Store of platforms assets(without update check) assets and normal version
* @param {boolean} [options.withIa32] - [Windows only] ia32 build on x64 system(if your machine is ia32, it will be built if this arg is not passed)
* @param {boolean} [options.withArm64] - [Windows only(beta)] arm64 build on x64 system(if your machine is arm64, it will be built if this arg is not passed, and not build store build for arm64)
* @return {void}
*/
module.exports = cmd

2
app/buildCli.js Normal file
View File

@@ -0,0 +1,2 @@
const cmd = require('./build')
cmd()

View File

@@ -15,10 +15,10 @@
"dev": "run-p dev:*",
"dev:run": "electron ./ --dev",
"dev:watchview": "node view/make/makeCli.js --watch",
"build": "node build.js",
"build": "node buildCli.js",
"build:pwa": "node view/make/makeCli.js --pwa",
"build:all:x64": "node build.js --withStore",
"build:all": "node build.js --withStore --withIa32",
"build:all:x64": "node buildCli.js --withStore",
"build:all": "node buildCli.js --withStore --withIa32 --withArm64",
"lint:fix": "eslint js --fix",
"lint": "eslint js"
},
@@ -84,8 +84,7 @@
"eslint": "^7.23.0",
"npm-run-all": "^4.1.5",
"readline-sync": "1.4.10",
"ts-node": "^9.1.1",
"typescript": "^4.2.4"
"ts-node": "^9.1.1"
},
"resolutions": {
"@types/fs-extra": "9.0.11"

2
app/view/make/make.d.ts vendored Normal file
View File

@@ -0,0 +1,2 @@
export = construct;
declare function construct(ver: any, basefile: any, pwa: any, store: any): void;

View File

@@ -26,7 +26,7 @@
<body class="">
<script>
var ver = '22.1.2 (Koume)'
var gitHash = '4e2f3ad68a68c0b3c180d9106502d8324939b838'
var gitHash = '8621b66203e37ac2dd1e6bc6efd861fe9a8e6891'
//betaを入れるとバージョンチェックしない
//var ver="beta";
var acct_id = 0

View File

@@ -609,7 +609,7 @@
style="width:100%; max-width:40rem;"><img src="../../img/desk_full.svg" class="left" width="25"
style="padding-top:5px;">Main author: Cutls@cutls.com</a>
<br>
TheDesk @ <a href="https://github.com/cutls/TheDesk/commits/4e2f3ad68a68c0b3c180d9106502d8324939b838">4e2f3ad68a68c0b3c180d9106502d8324939b838</a> - <a
TheDesk @ <a href="https://github.com/cutls/TheDesk/commits/8621b66203e37ac2dd1e6bc6efd861fe9a8e6891">8621b66203e37ac2dd1e6bc6efd861fe9a8e6891</a> - <a
onclick="checkupd(); return localStorage.removeItem('new-ver-skip'); location.href='index.html';"
class="pointer pwa">Sprawdź aktualizacje</a><br>
<br>
@@ -619,7 +619,7 @@
<img src="https://status.cutls.com/badge-service?site=thedesk.top">
</a><br>
<h5>OSS License</h5>
<a href="https://app.fossa.com/projects/git%2Bgithub.com%2Fcutls%2FTheDesk/refs/branch/master/4e2f3ad68a68c0b3c180d9106502d8324939b838"
<a href="https://app.fossa.com/projects/git%2Bgithub.com%2Fcutls%2FTheDesk/refs/branch/master/8621b66203e37ac2dd1e6bc6efd861fe9a8e6891"
alt="FOSSA Status"><img
src="https://app.fossa.com/api/projects/git%2Bgithub.com%2Fcutls%2FTheDesk.svg?type=small" /></a>
<br>