feat: introduce deno cli entrypoint

pull/385/head
Webber 2022-04-15 01:53:25 +02:00
parent 47b25cf3b1
commit 8cbb31c08b
9 changed files with 181 additions and 5 deletions

View File

@ -55,6 +55,8 @@
// For this project only use kebab-case
"unicorn/filename-case": ["error", { "cases": { "kebabCase": true } }],
// Allow Array.from(set) mitigate TS2569 which would require '--downlevelIteration'
"unicorn/prefer-spread": "off"
"unicorn/prefer-spread": "off",
// Temporarily allow disabling for whole file
"eslint-comments/no-use": "off"
}
}

View File

@ -1,6 +1,58 @@
name: 'Unity - Builder'
author: Webber Takken <webber@takken.io>
description: 'Build Unity projects for different platforms.'
runs:
using: 'composite'
steps:
- run: echo "Using GameCI CLI to build project"
shell: bash
- uses: denoland/setup-deno@v1
with:
deno-version: v1.x
- run: |
deno run --allow-run .\src\deno-1\gameci.ts build \
--targetPlatform="${{ inputs.targetPlatform }}" \
--unityVersion="${{ inputs.unityVersion }}" \
--customImage="${{ inputs.customImage }}" \
--projectPath="${{ inputs.projectPath }}" \
--buildName="${{ inputs.buildName }}" \
--buildsPath="${{ inputs.buildsPath }}" \
--buildMethod="${{ inputs.buildMethod }}" \
--customParameters="${{ inputs.customParameters }}" \
--versioning="${{ inputs.versioning }}" \
--version="${{ inputs.version }}" \
--androidVersionCode="${{ inputs.androidVersionCode }}" \
--androidAppBundle="${{ inputs.androidAppBundle }}" \
--androidKeystoreName="${{ inputs.androidKeystoreName }}" \
--androidKeystoreBase64="${{ inputs.androidKeystoreBase64 }}" \
--androidKeystorePass="${{ inputs.androidKeystorePass }}" \
--androidKeyaliasName="${{ inputs.androidKeyaliasName }}" \
--androidKeyaliasPass="${{ inputs.androidKeyaliasPass }}" \
--androidTargetSdkVersion="${{ inputs.androidTargetSdkVersion }}" \
--sshAgent="${{ inputs.sshAgent }}" \
--gitPrivateToken="${{ inputs.gitPrivateToken }}" \
--chownFilesTo="${{ inputs.chownFilesTo }}" \
--allowDirtyBuild="${{ inputs.allowDirtyBuild }}" \
--postBuildSteps="${{ inputs.postBuildSteps }}" \
--preBuildSteps="${{ inputs.preBuildSteps }}" \
--customJobHooks="${{ inputs.customJobHooks }}" \
--customJob="${{ inputs.customJob }}" \
--awsBaseStackName="${{ inputs.awsBaseStackName }}" \
--cloudRunnerCluster="${{ inputs.cloudRunnerCluster }}" \
--cloudRunnerCpu="${{ inputs.cloudRunnerCpu }}" \
--cloudRunnerMemory="${{ inputs.cloudRunnerMemory }}" \
--cachePushOverrideCommand="${{ inputs.cachePushOverrideCommand }}" \
--cachePullOverrideCommand="${{ inputs.cachePullOverrideCommand }}" \
--readInputFromOverrideList="${{ inputs.readInputFromOverrideList }}" \
--readInputOverrideCommand="${{ inputs.readInputOverrideCommand }}" \
--kubeConfig="${{ inputs.kubeConfig }}" \
--kubeVolume="${{ inputs.kubeVolume }}" \
--kubeStorageClass="${{ inputs.kubeStorageClass }}" \
--kubeVolumeSize="${{ inputs.kubeVolumeSize }}" \
--cacheKey="${{ inputs.cacheKey }}" \
--checkDependencyHealthOverride="${{ inputs.checkDependencyHealthOverride }}" \
--startDependenciesOverride="${{ inputs.startDependenciesOverride }}"
shell: bash
inputs:
targetPlatform:
required: true
@ -174,6 +226,3 @@ outputs:
branding:
icon: 'box'
color: 'gray-dark'
runs:
using: 'node12'
main: 'dist/index.js'

View File

@ -0,0 +1,24 @@
/* eslint-disable no-console */
import { exec, OutputMode } from 'https://deno.land/x/exec@0.0.5/mod.ts';
import { CliOptions } from '../core/cli-options.ts';
export class Bootstrapper {
private readonly options: CliOptions;
constructor(cliOptions: CliOptions) {
this.options = cliOptions;
}
public async run() {
console.log('using options', this.options);
const result = await exec('docker run -it unityci/editor:2020.3.15f2-base-1 /bin/bash -c "echo test"', {
output: OutputMode.Capture,
continueOnError: true,
// verbose: true,
});
console.log(result.output);
}
}

View File

@ -0,0 +1 @@
export type CliOptions = Map<string, string | number | boolean>;

11
cli/core/kernel.ts 100644
View File

@ -0,0 +1,11 @@
import { parseArgv } from './parse-argv.ts';
import { Bootstrapper } from '../controller/bootstrapper.ts';
export class Kernel {
public async run() {
const cliOptions = parseArgv(Deno.args);
const bootstrapper = new Bootstrapper(cliOptions);
bootstrapper.run();
}
}

View File

@ -0,0 +1,51 @@
import { CliOptions } from './cli-options.ts';
/**
* Parse command line arguments
*
* Usage:
* console.dir(parseArgv(Deno.args)); // Deno
* console.log(parseArgv(process.argv)); // Node
*
* Example:
* deno run my-script -test1=1 -test2 "2" -test3 -test4 false -test5 "one" -test6= -test7=9BX9
*
* Output:
* Map {
* "test1" => 1,
* "test2" => 2,
* "test3" => true,
* "test4" => false,
* "test5" => "one",
* "test6" => "",
* "test7" => "9BX9"
* }
*/
export const parseArgv = (argv: string[] = [], { verbose = false } = {}): CliOptions => {
const providedArguments = new Map<string, string | number | boolean>();
for (let current = 0, next = 1; current < argv.length; current += 1, next += 1) {
// Detect flag
if (!argv[current].startsWith('-')) continue;
let flag = argv[current].replace(/^-+/, '');
// Detect value
const hasNextArgument = next < argv.length && !argv[next].startsWith('-');
let value: string | number | boolean = hasNextArgument ? argv[next] : 'true';
// Split combinations
const isCombination = flag.includes('=');
if (isCombination) [flag, value] = flag.split('=');
// Parse types
if (['true', 'false'].includes(value)) value = value === 'true';
else if (!Number.isNaN(Number(value)) && !Number.isNaN(Number.parseInt(value))) value = Number.parseInt(value);
// Assign
// eslint-disable-next-line no-console
if (verbose) console.log(`Found flag "${flag}" with value "${value}" (${typeof value}).`);
providedArguments.set(flag, value);
}
return providedArguments;
};

7
cli/index.ts 100644
View File

@ -0,0 +1,7 @@
import { Kernel } from './core/kernel.ts';
(async () => {
const kernel = new Kernel();
await kernel.run();
})();

31
deno.json 100644
View File

@ -0,0 +1,31 @@
{
"compilerOptions": {
"allowJs": true,
"lib": ["deno.window"],
"strict": true
},
"lint": {
"files": {
"include": ["cli/"],
"exclude": []
},
"rules": {
"tags": ["recommended"],
"include": ["ban-untagged-todo"],
"exclude": ["no-unused-vars"]
}
},
"fmt": {
"files": {
"include": ["cli/"],
"exclude": []
},
"options": {
"useTabs": false,
"lineWidth": 120,
"indentWidth": 2,
"singleQuote": true,
"proseWrap": "preserve"
}
}
}

View File

@ -4,7 +4,7 @@
"target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"outDir": "./lib" /* Redirect output structure to the directory. */,
"rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
"rootDir": "./" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
"strict": true /* Enable all strict type-checking options. */,
"noImplicitAny": false /* Re-enable after fixing compatibility */ /* Raise error on expressions and declarations with an implied 'any' type. */,
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */