Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic templates & Typed Schema #1177

Merged
merged 32 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3853275
add spec testers
pavjacko Oct 13, 2023
ae72f8a
schema updates
pavjacko Oct 13, 2023
1c3202d
update android schema
pavjacko Oct 14, 2023
3b61a1e
add spec test examples
pavjacko Oct 14, 2023
89cc50c
refactor ios platform types
pavjacko Oct 14, 2023
e342f90
update schema structure
pavjacko Oct 14, 2023
8ba56fb
refactor additions, cleanup
pavjacko Oct 14, 2023
bdc15a7
fix recursive types
pavjacko Oct 14, 2023
71aefce
update android schema
pavjacko Oct 15, 2023
6e86d13
update schema
pavjacko Oct 15, 2023
c2a6097
add exported json schemas, update schemas ts, known issue: The inferr…
pavjacko Oct 15, 2023
0428d5b
fix schema types
pavjacko Oct 15, 2023
247af2b
update schema definitions
pavjacko Oct 15, 2023
60795df
switch to fully typed getConfigProp
pavjacko Oct 15, 2023
7e445a7
update getConfigProp usages
pavjacko Oct 15, 2023
bd55676
schema fixes, add missing props, migrate to typed getConfigProp
pavjacko Oct 16, 2023
85b8d32
ts generics fixes
pavjacko Oct 16, 2023
07355ff
schema fixes, add platform schema decorators
pavjacko Oct 16, 2023
714ab94
simplify schema merges
pavjacko Oct 16, 2023
d4b777f
split schemas to fragments
pavjacko Oct 16, 2023
3cd0007
schema fixes
pavjacko Oct 16, 2023
3d5bff1
fix outstanding schema types
pavjacko Oct 16, 2023
27f6e6c
update generated schemas
pavjacko Oct 16, 2023
7cae741
upgrade plugin schemas and types
pavjacko Oct 16, 2023
7b35270
plugin types & merges fixes
pavjacko Oct 16, 2023
bf8a0d8
type schema fixes
pavjacko Oct 16, 2023
a6e0897
add windows props, fix TS crapping its pants with "..inferred type of…
pavjacko Oct 16, 2023
6f01cf1
code cleanup
pavjacko Oct 16, 2023
cb719ca
Merge branch 'main' into feat/dynamic-templates
pavjacko Oct 16, 2023
17c8e78
fix fs writeCleanFile
pavjacko Oct 17, 2023
ee14fc5
disable new file types (moved to next PR)
pavjacko Oct 17, 2023
9e2900c
security patch: https://github.com/flexn-io/renative/security/code-sc…
pavjacko Oct 17, 2023
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: 2 additions & 1 deletion packages/build-hooks-schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"watch": "tsc --watch --preserveWatchOutput"
},
"dependencies": {
"zod-to-json-schema": "3.21.4"
"zod-to-json-schema": "3.21.4",
"zod": "3.22.4"
},
"peerDependencies": {
"@rnv/core": "^1.0.0-canary.7"
Expand Down
49 changes: 44 additions & 5 deletions packages/build-hooks-schema/src/schema.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,53 @@
import { RnvContext, RootProjectSchema, logSuccess } from '@rnv/core';
import {
RootAppSchema,
RootEngineSchema,
RootGlobalSchema,
RootIntegrationSchema,
RootLocalSchema,
RootPluginSchema,
RootPluginsSchema,
RootPrivateSchema,
RootProjectSchema,
RootTemplateSchema,
RootTemplatesSchema,
getContext,
logSuccess,
} from '@rnv/core';
import { zodToJsonSchema } from 'zod-to-json-schema';
import { z } from 'zod';
import path from 'path';
import fs from 'fs';

export const generateSchema = async (c: RnvContext) => {
const jsonSchema = zodToJsonSchema(RootProjectSchema, 'mySchema');
export const generateSchema = async () => {
_generateSchemaFile({ schema: RootProjectSchema, schemaId: 'rnv.project' });
_generateSchemaFile({ schema: RootAppSchema, schemaId: 'rnv.app' });
_generateSchemaFile({ schema: RootLocalSchema, schemaId: 'rnv.local' });
_generateSchemaFile({ schema: RootEngineSchema, schemaId: 'rnv.engine' });
_generateSchemaFile({ schema: RootGlobalSchema, schemaId: 'rnv.global' });
_generateSchemaFile({ schema: RootPluginsSchema, schemaId: 'rnv.plugins' });
_generateSchemaFile({ schema: RootTemplateSchema, schemaId: 'rnv.template' });
_generateSchemaFile({ schema: RootPrivateSchema, schemaId: 'rnv.private' });
_generateSchemaFile({ schema: RootPluginSchema, schemaId: 'rnv.plugin' });
_generateSchemaFile({ schema: RootTemplatesSchema, schemaId: 'rnv.templates' });
_generateSchemaFile({ schema: RootIntegrationSchema, schemaId: 'rnv.integration' });

logSuccess('Sucessfully exported renative.project.json schema');
};

const _generateSchemaFile = (opts: { schema: z.ZodObject<any>; schemaId: string }) => {
const { schema, schemaId } = opts;
const ctx = getContext();
const jsonSchema: any = zodToJsonSchema(schema, schemaId);
jsonSchema['$schema'] = 'http://json-schema.org/draft-04/schema#';

const destPath = path.join(c.paths.project.dir, '.rnv/schema/renative.project.json');
jsonSchema.definitions[schemaId].properties['$schema'] = {
type: 'string',
description: 'schema definition',
};

const destPath = path.join(ctx.paths.project.dir, `packages/core/jsonSchema/${schemaId}.json`);
fs.writeFileSync(destPath, JSON.stringify(jsonSchema, null, 2));

logSuccess('Sucessfully exported renative.project.json schema');
const destPath2 = path.join(ctx.paths.project.dir, `.rnv/schema/${schemaId}.json`);
fs.writeFileSync(destPath2, JSON.stringify(jsonSchema, null, 2));
};
3,444 changes: 3,444 additions & 0 deletions packages/core/jsonSchema/rnv.app.json

Large diffs are not rendered by default.

100 changes: 100 additions & 0 deletions packages/core/jsonSchema/rnv.engine.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"$ref": "#/definitions/rnv.engine",
"definitions": {
"rnv.engine": {
"type": "object",
"properties": {
"custom": {
"description": "Object ysed to extend your renative with custom props. This allows renative json schema to be validated"
},
"id": {
"type": "string",
"description": "ID of engine"
},
"engineExtension": {
"type": "string",
"description": "Engine extension ised by rnv during compilation"
},
"overview": {
"type": "string",
"description": "Overview description of engine"
},
"plugins": {
"type": "object",
"additionalProperties": {
"type": "string"
},
"description": "List of required plugins for this engine to work properly"
},
"npm": {
"type": "object",
"properties": {},
"additionalProperties": false
},
"platforms": {
"type": "object",
"additionalProperties": {
"type": "object",
"properties": {
"engine": {
"type": "string"
},
"npm": {
"type": "object",
"properties": {
"dependencies": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"devDependencies": {
"$ref": "#/definitions/rnv.engine/properties/platforms/additionalProperties/properties/npm/properties/dependencies"
},
"peerDependencies": {
"$ref": "#/definitions/rnv.engine/properties/platforms/additionalProperties/properties/npm/properties/dependencies"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
},
"propertyNames": {
"enum": [
"ios",
"android",
"firetv",
"androidtv",
"androidwear",
"web",
"webtv",
"tizen",
"tizenmobile",
"tvos",
"webos",
"macos",
"windows",
"linux",
"tizenwatch",
"kaios",
"chromecast",
"xbox"
]
}
},
"$schema": {
"type": "string",
"description": "schema definition"
}
},
"required": [
"id",
"engineExtension",
"overview"
],
"additionalProperties": false
}
},
"$schema": "http://json-schema.org/draft-04/schema#"
}
52 changes: 52 additions & 0 deletions packages/core/jsonSchema/rnv.global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"$ref": "#/definitions/rnv.global",
"definitions": {
"rnv.global": {
"type": "object",
"properties": {
"defaultTargets": {
"type": "object",
"additionalProperties": {
"type": "string"
},
"propertyNames": {
"enum": [
"ios",
"android",
"firetv",
"androidtv",
"androidwear",
"web",
"webtv",
"tizen",
"tizenmobile",
"tvos",
"webos",
"macos",
"windows",
"linux",
"tizenwatch",
"kaios",
"chromecast",
"xbox"
]
},
"description": "Define targets to be used when -t is not set on any project run"
},
"sdks": {
"type": "object",
"additionalProperties": {
"type": "string"
},
"description": "Define your sdk configurations"
},
"$schema": {
"type": "string",
"description": "schema definition"
}
},
"additionalProperties": false
}
},
"$schema": "http://json-schema.org/draft-04/schema#"
}
16 changes: 16 additions & 0 deletions packages/core/jsonSchema/rnv.integration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"$ref": "#/definitions/rnv.integration",
"definitions": {
"rnv.integration": {
"type": "object",
"properties": {
"$schema": {
"type": "string",
"description": "schema definition"
}
},
"additionalProperties": false
}
},
"$schema": "http://json-schema.org/draft-04/schema#"
}
64 changes: 64 additions & 0 deletions packages/core/jsonSchema/rnv.local.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"$ref": "#/definitions/rnv.local",
"definitions": {
"rnv.local": {
"type": "object",
"properties": {
"workspaceAppConfigsDir": {
"type": "string",
"description": "Defines app configs dir outside of current project"
},
"defaultTargets": {
"type": "object",
"additionalProperties": {
"type": "string"
},
"propertyNames": {
"enum": [
"ios",
"android",
"firetv",
"androidtv",
"androidwear",
"web",
"webtv",
"tizen",
"tizenmobile",
"tvos",
"webos",
"macos",
"windows",
"linux",
"tizenwatch",
"kaios",
"chromecast",
"xbox"
]
},
"description": "Define targets to be used when -t is not set on any project run"
},
"_meta": {
"type": "object",
"properties": {
"currentAppConfigId": {
"type": "string"
},
"requiresJetify": {
"type": "boolean"
}
},
"additionalProperties": false
},
"extend": {
"type": "string"
},
"$schema": {
"type": "string",
"description": "schema definition"
}
},
"additionalProperties": false
}
},
"$schema": "http://json-schema.org/draft-04/schema#"
}
Loading