Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@ jobs:
- name: Run Prettier (Check)
run: yarn prettier:check

- name: Run Typescheck
run: yarn tsc --noEmit

- name: Run Unit Tests
run: yarn test
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"testEnvironment": "node"
},
"dependencies": {
"ajv": "^7.0.1",
"yargs": "^16.2.0"
},
"devDependencies": {
Expand Down
9 changes: 8 additions & 1 deletion src/cli/build.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { getConfig } from './config';
import { BuildRunOptions } from './types';

export const buildHandler = async (args: BuildRunOptions) => {
console.log(`OWL will build for the ${args.platform} platform.`);
const config = await getConfig(args.config);

console.log('Configuration:', JSON.stringify(config, null, 2));

console.log(
`OWL will build for the ${args.platform} platform. Config file: ${args.config}`
);
};
61 changes: 61 additions & 0 deletions src/cli/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { promises as fs } from 'fs';
import Ajv, { ErrorObject, JSONSchemaType } from 'ajv';

import { Config } from './types';

const validateSchema = (config: {}): Promise<Config> => {
const configSschema: JSONSchemaType<Config> = {
type: 'object',
properties: {
ios: {
type: 'object',
properties: {
workspace: { type: 'string' },
},
required: ['workspace'],
nullable: true,
additionalProperties: false,
},
android: {
type: 'object',
properties: {},
required: [],
nullable: true,
additionalProperties: false,
},
},
required: [],
anyOf: [{ required: ['ios'] }, { required: ['android'] }],
additionalProperties: false,
};

const ajv = new Ajv();
const validate = ajv.compile(configSschema);

return new Promise((resolve, reject) => {
if (validate(config)) {
resolve(config);
} else {
const errorMessage = validate
.errors!.map((err: ErrorObject) => `${err.schemaPath}: ${err.message}`)
.join(' ');
reject(errorMessage);
}
});
};

const readConfigFile = async (configPath: string) => {
try {
const configData = await fs.readFile(configPath, 'binary');
const configString = Buffer.from(configData).toString();
const parsedConfig = JSON.parse(configString);
return parsedConfig;
} catch (err) {
throw new Error(`Could not load the config at ${configPath}`);
}
};

export const getConfig = async (configPath: string): Promise<Config> => {
const config = await readConfigFile(configPath);
return await validateSchema(config);
};
13 changes: 11 additions & 2 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@ import { runHandler } from './run';

const plaformOption: Options = {
alias: 'p',
describe: 'Platform to build the app',
describe: 'Platform to build and run the app',
demandOption: true,
choices: ['ios', 'android'],
};

const configOption: Options = {
alias: 'c',
describe: 'Configuration file to be used',
type: 'string',
default: './owl.config.json',
};

const builderOptions = {
config: configOption,
platform: plaformOption,
};

Expand All @@ -31,6 +39,7 @@ argv
builder: builderOptions,
handler: runHandler,
})
.help('h')
.help('help')
.alias('h', 'help')
.showHelpOnFail(false, 'Specify --help for available options')
.alias('v', 'version').argv;
12 changes: 12 additions & 0 deletions src/cli/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,16 @@ import { Arguments } from 'yargs';

export interface BuildRunOptions extends Arguments {
platform: 'ios' | 'android';
config: string;
}

type ConfigIOS = {
workspace: string;
};

type ConfigAndroid = {};

export type Config = {
ios?: ConfigIOS;
android?: ConfigAndroid;
};
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
"strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */

/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
"noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
Expand Down
20 changes: 20 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,16 @@ ajv@^6.12.3:
json-schema-traverse "^0.4.1"
uri-js "^4.2.2"

ajv@^7.0.1:
version "7.0.1"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-7.0.1.tgz#d39ed49159672a91f796e2563e1e96984956e338"
integrity sha512-D2UYOXvDzGLVwld2/EyRu3xiJG885QUz2xS1phZzebYLPMPBFbPK4naXGDCtPltZoOG+I1+ZkNAJ65SJ3vqbsg==
dependencies:
fast-deep-equal "^3.1.1"
json-schema-traverse "^1.0.0"
require-from-string "^2.0.2"
uri-js "^4.2.2"

ansi-escapes@^4.2.1:
version "4.3.1"
resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-4.3.1.tgz#a5c47cc43181f1f38ffd7076837700d395522a61"
Expand Down Expand Up @@ -2293,6 +2303,11 @@ json-schema-traverse@^0.4.1:
resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz#69f6a87d9513ab8bb8fe63bdb0979c448e684660"
integrity sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==

json-schema-traverse@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz#ae7bcb3656ab77a73ba5c49bf654f38e6b6860e2"
integrity sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==

json-schema@0.2.3:
version "0.2.3"
resolved "https://registry.yarnpkg.com/json-schema/-/json-schema-0.2.3.tgz#b480c892e59a2f05954ce727bd3f2a4e882f9e13"
Expand Down Expand Up @@ -2903,6 +2918,11 @@ require-directory@^2.1.1:
resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42"
integrity sha1-jGStX9MNqxyXbiNE/+f3kqam30I=

require-from-string@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/require-from-string/-/require-from-string-2.0.2.tgz#89a7fdd938261267318eafe14f9c32e598c36909"
integrity sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==

require-main-filename@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-2.0.0.tgz#d0b329ecc7cc0f61649f62215be69af54aa8989b"
Expand Down