@developer_tribe/react-builder 0.1.23 → 0.1.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build-components/Button/getDefaults.d.ts +3 -0
- package/dist/build-components/Carousel/getDefaults.d.ts +3 -0
- package/dist/build-components/CarouselButtons/getDefaults.d.ts +3 -0
- package/dist/build-components/CarouselDots/getDefaults.d.ts +3 -0
- package/dist/build-components/CarouselItem/getDefaults.d.ts +3 -0
- package/dist/build-components/CarouselProvider/getDefaults.d.ts +3 -0
- package/dist/build-components/Image/getDefaults.d.ts +3 -0
- package/dist/build-components/Onboard/getDefaults.d.ts +3 -0
- package/dist/build-components/OnboardButton/getDefaults.d.ts +3 -0
- package/dist/build-components/OnboardButtons/getDefaults.d.ts +3 -0
- package/dist/build-components/OnboardDot/getDefaults.d.ts +3 -0
- package/dist/build-components/OnboardFooter/getDefaults.d.ts +3 -0
- package/dist/build-components/OnboardImage/getDefaults.d.ts +3 -0
- package/dist/build-components/OnboardItem/getDefaults.d.ts +3 -0
- package/dist/build-components/OnboardProvider/getDefaults.d.ts +3 -0
- package/dist/build-components/OnboardSubtitle/getDefaults.d.ts +3 -0
- package/dist/build-components/OnboardTitle/getDefaults.d.ts +3 -0
- package/dist/build-components/Text/getDefaults.d.ts +3 -0
- package/dist/build-components/View/getDefaults.d.ts +3 -0
- package/dist/build-components/getDefaults.d.ts +25 -0
- package/dist/build-components/index.d.ts +1 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/types/Device.d.ts +2 -2
- package/package.json +1 -1
- package/scripts/prebuild/build-components.js +4 -0
- package/scripts/prebuild/utils/createBuildComponentsIndex.js +4 -1
- package/scripts/prebuild/utils/createBuildComponentsRootGetDefaults.js +64 -0
- package/scripts/prebuild/utils/createGetDefaultsPerComponent.js +28 -0
- package/scripts/prebuild/utils/createRootGetDefaults.js +52 -0
- package/scripts/prebuild/utils/index.js +3 -0
- package/scripts/prebuild/utils/validateAllComponentsOrThrow.js +2 -2
- package/src/assets/devices.json +88 -88
- package/src/build-components/Button/getDefaults.ts +11 -0
- package/src/build-components/Carousel/getDefaults.ts +11 -0
- package/src/build-components/CarouselButtons/getDefaults.ts +13 -0
- package/src/build-components/CarouselDots/getDefaults.ts +13 -0
- package/src/build-components/CarouselItem/getDefaults.ts +13 -0
- package/src/build-components/CarouselProvider/getDefaults.ts +13 -0
- package/src/build-components/Image/getDefaults.ts +11 -0
- package/src/build-components/Onboard/getDefaults.ts +11 -0
- package/src/build-components/OnboardButton/getDefaults.ts +13 -0
- package/src/build-components/OnboardButtons/getDefaults.ts +13 -0
- package/src/build-components/OnboardDot/getDefaults.ts +13 -0
- package/src/build-components/OnboardFooter/OnboardFooter.tsx +157 -14
- package/src/build-components/OnboardFooter/getDefaults.ts +13 -0
- package/src/build-components/OnboardImage/getDefaults.ts +13 -0
- package/src/build-components/OnboardItem/getDefaults.ts +13 -0
- package/src/build-components/OnboardProvider/getDefaults.ts +13 -0
- package/src/build-components/OnboardSubtitle/getDefaults.ts +13 -0
- package/src/build-components/OnboardSubtitle/pattern.json +4 -0
- package/src/build-components/OnboardTitle/getDefaults.ts +13 -0
- package/src/build-components/OnboardTitle/pattern.json +4 -0
- package/src/build-components/Text/getDefaults.ts +11 -0
- package/src/build-components/View/getDefaults.ts +11 -0
- package/src/build-components/getDefaults.ts +149 -0
- package/src/build-components/index.ts +2 -0
- package/src/types/Device.ts +2 -2
- package/src/utils/getDevices.ts +7 -1
package/dist/types/Device.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export interface Device {
|
|
|
6
6
|
type: 'phone' | 'tablet';
|
|
7
7
|
/**
|
|
8
8
|
* Relative importance for generic targeting and display ordering.
|
|
9
|
-
* 1 = highest importance,
|
|
9
|
+
* 1 = highest importance, 100 = lowest importance
|
|
10
10
|
*/
|
|
11
|
-
importance?:
|
|
11
|
+
importance?: number;
|
|
12
12
|
}
|
package/package.json
CHANGED
|
@@ -13,6 +13,8 @@ import {
|
|
|
13
13
|
validateExistingComponentTsx,
|
|
14
14
|
createRenderNodeGenerated,
|
|
15
15
|
createBuildComponentsIndex,
|
|
16
|
+
createGetDefaultsPerComponent,
|
|
17
|
+
createBuildComponentsRootGetDefaults,
|
|
16
18
|
formatAllSourceFiles,
|
|
17
19
|
// lintNonGeneratedOrThrow,
|
|
18
20
|
} from './utils/index.js';
|
|
@@ -36,10 +38,12 @@ async function run() {
|
|
|
36
38
|
await ensurePropsTs(componentDir, componentName);
|
|
37
39
|
await createComponentTsx(componentDir, componentName);
|
|
38
40
|
await validateExistingComponentTsx(componentDir, componentName);
|
|
41
|
+
await createGetDefaultsPerComponent(componentDir, componentName);
|
|
39
42
|
}
|
|
40
43
|
|
|
41
44
|
await createRenderNodeGenerated(validated, paths);
|
|
42
45
|
await createBuildComponentsIndex(validated, paths);
|
|
46
|
+
await createBuildComponentsRootGetDefaults(validated, paths);
|
|
43
47
|
await formatAllSourceFiles(paths);
|
|
44
48
|
}
|
|
45
49
|
|
|
@@ -15,8 +15,11 @@ export async function createBuildComponentsIndex(validated, paths) {
|
|
|
15
15
|
.join('\n');
|
|
16
16
|
|
|
17
17
|
const renderNodeExport = `export { default as RenderNode } from './RenderNode.generated';`;
|
|
18
|
+
const getDefaultsExport = `export { getDefaults } from './getDefaults';`;
|
|
18
19
|
|
|
19
|
-
const sections = [renderNodeExport, exportLines]
|
|
20
|
+
const sections = [renderNodeExport, getDefaultsExport, exportLines]
|
|
21
|
+
.filter(Boolean)
|
|
22
|
+
.join('\n\n');
|
|
20
23
|
|
|
21
24
|
const fileContent =
|
|
22
25
|
`/* AUTO-GENERATED FILE - DO NOT EDIT */\n\n` +
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { promises as fs } from 'fs';
|
|
3
|
+
import { formatWithPrettier } from './formatWithPrettier.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates src/build-components/getDefaults.ts aggregating all component getDefaults
|
|
7
|
+
* with signature: getDefaults<T>(type: T, node: NodeData<List<T>>)
|
|
8
|
+
*/
|
|
9
|
+
export async function createBuildComponentsRootGetDefaults(validated, paths) {
|
|
10
|
+
const { COMPONENTS_ROOT } = paths;
|
|
11
|
+
const targetPath = path.join(COMPONENTS_ROOT, 'getDefaults.ts');
|
|
12
|
+
|
|
13
|
+
const importLines = validated
|
|
14
|
+
.map(({ componentName }) => {
|
|
15
|
+
return `import { getDefaults as get${componentName}Defaults } from './${componentName}/getDefaults';`;
|
|
16
|
+
})
|
|
17
|
+
.join('\n');
|
|
18
|
+
|
|
19
|
+
const typeImports = `import type { ${validated
|
|
20
|
+
.map(({ componentName }) => `${componentName}PropsGenerated`)
|
|
21
|
+
.join(', ')} } from './index';`;
|
|
22
|
+
|
|
23
|
+
const nodeImport = `import type { NodeData } from '../types/Node';`;
|
|
24
|
+
|
|
25
|
+
const typesMap = validated
|
|
26
|
+
.map(({ componentName, patternJson }) => {
|
|
27
|
+
const type = patternJson?.pattern?.type;
|
|
28
|
+
return ` ${JSON.stringify(type)}: ${componentName}PropsGenerated['attributes']`;
|
|
29
|
+
})
|
|
30
|
+
.join(';\n');
|
|
31
|
+
|
|
32
|
+
const switchCases = validated
|
|
33
|
+
.map(({ componentName, patternJson }) => {
|
|
34
|
+
const type = patternJson?.pattern?.type;
|
|
35
|
+
return ` case ${JSON.stringify(type)}:\n defaults = get${componentName}Defaults() as Partial<Types[T]>;\n break;`;
|
|
36
|
+
})
|
|
37
|
+
.join('\n');
|
|
38
|
+
|
|
39
|
+
const fileContent =
|
|
40
|
+
`/* AUTO-GENERATED FILE - DO NOT EDIT */\n\n` +
|
|
41
|
+
`${importLines}\n` +
|
|
42
|
+
`${typeImports}\n` +
|
|
43
|
+
`${nodeImport}\n\n` +
|
|
44
|
+
`export type Types = {\n${typesMap}\n};\n\n` +
|
|
45
|
+
`export type List<T> = T extends keyof Types ? Types[T] : never;\n\n` +
|
|
46
|
+
`export function getDefaults<T extends keyof Types>(type: T, node: NodeData<List<T>>): Partial<Types[T]> {\n` +
|
|
47
|
+
` let defaults: Partial<Types[T]> = {};\n\n` +
|
|
48
|
+
` switch (type as unknown as string) {\n` +
|
|
49
|
+
`${switchCases}\n` +
|
|
50
|
+
` default:\n` +
|
|
51
|
+
` defaults = {} as Partial<Types[T]>;\n` +
|
|
52
|
+
` }\n\n` +
|
|
53
|
+
` if ((node as unknown as { type?: string })?.type !== (type as unknown as string)) {\n` +
|
|
54
|
+
` throw new Error(\n` +
|
|
55
|
+
` \`getDefaults: node.type mismatch; expected \${String(type)}, received \${(node as unknown as { type?: string })?.type ?? 'undefined'}\`\n` +
|
|
56
|
+
` );\n` +
|
|
57
|
+
` }\n\n` +
|
|
58
|
+
` (node as unknown as { attributes?: unknown }).attributes = defaults as Types[T];\n\n` +
|
|
59
|
+
` return defaults;\n` +
|
|
60
|
+
`}\n`;
|
|
61
|
+
|
|
62
|
+
const formatted = await formatWithPrettier(fileContent);
|
|
63
|
+
await fs.writeFile(targetPath, formatted, 'utf8');
|
|
64
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { promises as fs } from 'fs';
|
|
3
|
+
import { formatWithPrettier } from './formatWithPrettier.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates src/build-components/<Component>/getDefaults.ts
|
|
7
|
+
* This file returns the `default` block from the folder's pattern.json.
|
|
8
|
+
*/
|
|
9
|
+
export async function createGetDefaultsPerComponent(
|
|
10
|
+
componentDir,
|
|
11
|
+
componentName
|
|
12
|
+
) {
|
|
13
|
+
const targetPath = path.join(componentDir, 'getDefaults.ts');
|
|
14
|
+
|
|
15
|
+
const importPath = `./${componentName}Props.generated`;
|
|
16
|
+
|
|
17
|
+
const fileContent =
|
|
18
|
+
`/* AUTO-GENERATED FILE - DO NOT EDIT */\n\n` +
|
|
19
|
+
`import pattern from './pattern.json';\n` +
|
|
20
|
+
`import type { ${componentName}PropsGenerated } from '${importPath}';\n\n` +
|
|
21
|
+
`export type ${componentName}Defaults = Partial<${componentName}PropsGenerated['attributes']>;\n\n` +
|
|
22
|
+
`export function getDefaults(): ${componentName}Defaults {\n` +
|
|
23
|
+
` return ((pattern as unknown as { default?: unknown })?.default ?? {}) as ${componentName}Defaults;\n` +
|
|
24
|
+
`}\n`;
|
|
25
|
+
|
|
26
|
+
const formatted = await formatWithPrettier(fileContent);
|
|
27
|
+
await fs.writeFile(targetPath, formatted, 'utf8');
|
|
28
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { promises as fs } from 'fs';
|
|
3
|
+
import { formatWithPrettier } from './formatWithPrettier.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates src/getDefaults.ts aggregating all component getDefaults.
|
|
7
|
+
*/
|
|
8
|
+
export async function createRootGetDefaults(validated, paths) {
|
|
9
|
+
const { SRC_ROOT } = paths;
|
|
10
|
+
const targetPath = path.join(SRC_ROOT, 'getDefaults.ts');
|
|
11
|
+
|
|
12
|
+
// Build import lines for all components
|
|
13
|
+
const importLines = validated
|
|
14
|
+
.map(({ componentName }) => {
|
|
15
|
+
return `import { getDefaults as get${componentName}Defaults } from './build-components/${componentName}/getDefaults';`;
|
|
16
|
+
})
|
|
17
|
+
.join('\n');
|
|
18
|
+
|
|
19
|
+
const typeImports = `import type { ${validated
|
|
20
|
+
.map(({ componentName }) => `${componentName}PropsGenerated`)
|
|
21
|
+
.join(', ')} } from './build-components';`;
|
|
22
|
+
|
|
23
|
+
const typesMap = validated
|
|
24
|
+
.map(({ componentName, patternJson }) => {
|
|
25
|
+
const type = patternJson?.pattern?.type;
|
|
26
|
+
return ` ${JSON.stringify(type)}: ${componentName}PropsGenerated['attributes']`;
|
|
27
|
+
})
|
|
28
|
+
.join(';\n');
|
|
29
|
+
|
|
30
|
+
const switchCases = validated
|
|
31
|
+
.map(({ componentName, patternJson }) => {
|
|
32
|
+
const type = patternJson?.pattern?.type;
|
|
33
|
+
return ` case ${JSON.stringify(type)}:\n return get${componentName}Defaults() as Partial<Types[T]>`;
|
|
34
|
+
})
|
|
35
|
+
.join('\n');
|
|
36
|
+
|
|
37
|
+
const fileContent =
|
|
38
|
+
`/* AUTO-GENERATED FILE - DO NOT EDIT */\n\n` +
|
|
39
|
+
`${importLines}\n` +
|
|
40
|
+
`${typeImports}\n\n` +
|
|
41
|
+
`export type Types = {\n${typesMap}\n};\n\n` +
|
|
42
|
+
`export function getDefaults<T extends keyof Types>(type: T): Partial<Types[T]> {\n` +
|
|
43
|
+
` switch (type as unknown as string) {\n` +
|
|
44
|
+
`${switchCases}\n` +
|
|
45
|
+
` default:\n` +
|
|
46
|
+
` return {};\n` +
|
|
47
|
+
` }\n` +
|
|
48
|
+
`}\n`;
|
|
49
|
+
|
|
50
|
+
const formatted = await formatWithPrettier(fileContent);
|
|
51
|
+
await fs.writeFile(targetPath, formatted, 'utf8');
|
|
52
|
+
}
|
|
@@ -13,3 +13,6 @@ export { createRenderNodeGenerated } from './createRenderNodeGenerated.js';
|
|
|
13
13
|
export { createBuildComponentsIndex } from './createBuildComponentsIndex.js';
|
|
14
14
|
export { formatAllSourceFiles } from './formatAllSourceFiles.js';
|
|
15
15
|
export { validateExistingComponentTsx } from './validateExistingComponentTsx.js';
|
|
16
|
+
export { createGetDefaultsPerComponent } from './createGetDefaultsPerComponent.js';
|
|
17
|
+
export { createRootGetDefaults } from './createRootGetDefaults.js';
|
|
18
|
+
export { createBuildComponentsRootGetDefaults } from './createBuildComponentsRootGetDefaults.js';
|
|
@@ -21,11 +21,11 @@ async function getAllEntriesInComponentsRoot(paths) {
|
|
|
21
21
|
d =>
|
|
22
22
|
d.name !== 'RenderNode.generated.tsx' &&
|
|
23
23
|
d.name !== 'other.tsx' &&
|
|
24
|
-
d.name !== 'index.ts'
|
|
24
|
+
d.name !== 'index.ts' &&
|
|
25
|
+
d.name !== 'getDefaults.ts'
|
|
25
26
|
);
|
|
26
27
|
});
|
|
27
28
|
}
|
|
28
|
-
|
|
29
29
|
// single-use: ensure all entries are directories
|
|
30
30
|
function ensureAllEntriesAreFolders(dirents, paths) {
|
|
31
31
|
const { COMPONENTS_ROOT } = paths;
|