1
0
Fork 0

feat(main): load config from hard-coded file

This commit is contained in:
ssube 2020-08-12 18:33:33 -05:00 committed by Sean Sube
parent 903eba9a0c
commit 63878d37a9
4 changed files with 49 additions and 68 deletions

View File

@ -10,7 +10,6 @@ import replace from 'rollup-plugin-replace';
import serve from 'rollup-plugin-serve';
import { terser } from 'rollup-plugin-terser';
import typescript from 'rollup-plugin-typescript2';
import virtual from 'rollup-plugin-virtual';
import visualizer from 'rollup-plugin-visualizer';
import yaml from 'rollup-plugin-yaml';
@ -111,12 +110,6 @@ const bundle = {
PACKAGE_VERSION: metadata.version,
},
}),
/*
virtual({
'universal-user-agent':
'export function getUserAgent() {return `Node.js/${process.version.substr(1)} (${process.platform}); ${process.arch})`}',
}),
*/
alias({
resolve: ['.tsx', '.ts'],
entries: {

1
docs/.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
api/* linguist-generated=true

View File

@ -1,4 +1,8 @@
import { InvalidArgumentError } from '@apextoaster/js-utils';
import { InvalidArgumentError, isNil } from '@apextoaster/js-utils';
import { createSchema } from '@apextoaster/js-yaml-schema';
import { existsSync, readFileSync, realpathSync } from 'fs';
import { DEFAULT_SAFE_SCHEMA, safeLoad } from 'js-yaml';
import { join } from 'path';
import { ConfigData } from './config';
import { Commands, createParser } from './config/args';
@ -15,25 +19,34 @@ export { syncIssues, syncLabels } from './sync';
const SLICE_ARGS = 2;
async function loadConfig(path: string): Promise<ConfigData> {
const schema = createSchema({
include: {
exists: existsSync,
join,
read: readFileSync,
resolve: realpathSync,
schema: DEFAULT_SAFE_SCHEMA,
}
});
const rawConfig = readFileSync(path, {
encoding: 'utf-8',
});
const config = safeLoad(rawConfig, { schema });
if (isNil(config) || typeof config === 'string') {
throw new Error();
}
return config as ConfigData;
}
export async function main(argv: Array<string>): Promise<number> {
// get arguments
let mode = Commands.UNKNOWN as Commands;
const parser = createParser((argMode) => mode = argMode as Commands);
const args = parser.parse(argv.slice(SLICE_ARGS));
// load config
const config: ConfigData = {
projects: [{
colors: [],
flags: [],
name: '',
remote: {
data: {},
type: '',
},
states: [],
}],
};
const config = await loadConfig('/home/ssube/.cautious-journey.yml');
/* eslint-disable-next-line no-console */
console.log({
@ -45,15 +58,15 @@ export async function main(argv: Array<string>): Promise<number> {
// create logger
// create remote
const remote = new GithubRemote({
data: {},
type: '',
});
for (const project of config.projects) {
const remote = new GithubRemote(project.remote);
await remote.connect();
// mode switch
const options: SyncOptions = {
config,
project: '',
project: project.name,
remote,
};
switch (mode) {
@ -66,6 +79,7 @@ export async function main(argv: Array<string>): Promise<number> {
default:
throw new InvalidArgumentError('unknown mode');
}
}
return 0;
}

View File

@ -11,35 +11,11 @@ export class GithubRemote implements Remote {
protected options: RemoteOptions;
protected request?: Octokit;
/* eslint-disable-next-line no-useless-constructor */
constructor(options: RemoteOptions) {
this.options = options;
}
public async connect() {
/* eslint-disable-next-line no-console */
console.log('connecting to github', {
auth: this.options.data,
authStrategy: createAppAuth,
});
/*
const auth = createAppAuth({
id: parseInt(mustExist(this.options.data.id), 10),
privateKey: mustExist(this.options.data.privateKey),
});
const install = await auth({
installationId: parseInt(mustExist(this.options.data.installationId), 10),
type: 'installation',
});
this.request = new Octokit({
auth: install,
authStrategy: createAppAuth,
});
*/
this.request = new Octokit({
auth: {
id: parseInt(mustExist(this.options.data.id), 10),
@ -95,9 +71,6 @@ export class GithubRemote implements Remote {
});
}
/* eslint-disable-next-line no-console */
console.log('list issues:', path, issues);
return issues;
}