@betty-blocks/cli 25.58.5 → 25.59.1
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.
|
@@ -27,45 +27,96 @@ const name = args[0];
|
|
|
27
27
|
// eslint-disable-next-line no-void
|
|
28
28
|
void (() => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
29
|
yield checkUpdateAvailable_1.checkUpdateAvailableCLI();
|
|
30
|
-
if (
|
|
31
|
-
throw
|
|
30
|
+
if (!/^[a-z][a-z0-9]*$/i.test(name)) {
|
|
31
|
+
throw Error(chalk_1.default.red(`\nName cannot contain special characters or spaces\n`));
|
|
32
32
|
}
|
|
33
|
-
if (yield fs_extra_1.pathExists(`src/prefabs/${name}.
|
|
34
|
-
throw
|
|
33
|
+
if (yield fs_extra_1.pathExists(`src/prefabs/${name}.tsx`)) {
|
|
34
|
+
throw Error(chalk_1.default.red(`\nPrefab ${name} already exists\n`));
|
|
35
35
|
}
|
|
36
36
|
if (yield fs_extra_1.pathExists(`src/components/${name}.js`)) {
|
|
37
|
-
throw
|
|
37
|
+
throw Error(chalk_1.default.red(`\nComponent ${name} already exists\n`));
|
|
38
38
|
}
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
const capitalisedName = name.charAt(0).toUpperCase() + name.slice(1);
|
|
40
|
+
const prefab = `import { prefab, Icon } from '@betty-blocks/component-sdk';
|
|
41
|
+
|
|
42
|
+
import { ${capitalisedName} } from './structures/${capitalisedName}';
|
|
43
|
+
|
|
44
|
+
const attributes = {
|
|
43
45
|
category: 'CONTENT',
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
46
|
+
icon: Icon.TitleIcon,
|
|
47
|
+
keywords: [''],
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export default prefab('${capitalisedName}', attributes, undefined, [${capitalisedName}({})]);
|
|
51
|
+
`;
|
|
52
|
+
const structureIndex = `import { component, PrefabReference } from '@betty-blocks/component-sdk';
|
|
53
|
+
import { Configuration } from '../Configuration';
|
|
54
|
+
import {
|
|
55
|
+
${name}Options as defaultOptions,
|
|
56
|
+
categories as defaultCategories,
|
|
57
|
+
} from './options';
|
|
58
|
+
|
|
59
|
+
export const ${capitalisedName} = (
|
|
60
|
+
config: Configuration,
|
|
61
|
+
descendants: PrefabReference[] = [],
|
|
62
|
+
) => {
|
|
63
|
+
const options = { ...(config.options || defaultOptions) };
|
|
64
|
+
const style = { ...config.style };
|
|
65
|
+
const ref = config.ref ? { ...config.ref } : undefined;
|
|
66
|
+
const label = config.label ? config.label : undefined;
|
|
67
|
+
const optionCategories = config.optionCategories
|
|
68
|
+
? { ...config.optionCategories }
|
|
69
|
+
: defaultCategories;
|
|
70
|
+
|
|
71
|
+
return component(
|
|
72
|
+
'${capitalisedName}',
|
|
73
|
+
{ options, ref, style, label, optionCategories },
|
|
74
|
+
descendants,
|
|
75
|
+
);
|
|
76
|
+
};
|
|
77
|
+
`;
|
|
78
|
+
const optionsIndex = `import { variable } from '@betty-blocks/component-sdk';
|
|
79
|
+
import { advanced } from '../../advanced';
|
|
80
|
+
|
|
81
|
+
export const categories = [
|
|
82
|
+
{
|
|
83
|
+
label: 'Advanced Options',
|
|
84
|
+
expanded: false,
|
|
85
|
+
members: ['dataComponentAttribute'],
|
|
86
|
+
},
|
|
87
|
+
];
|
|
88
|
+
|
|
89
|
+
export const ${name}Options = {
|
|
90
|
+
content: variable('Content', {
|
|
91
|
+
value: ['Hello world'],
|
|
92
|
+
configuration: { as: 'MULTILINE' },
|
|
93
|
+
}),
|
|
94
|
+
|
|
95
|
+
...advanced('${capitalisedName}'),
|
|
96
|
+
};
|
|
97
|
+
`;
|
|
98
|
+
const component = `(() => ({
|
|
99
|
+
name: '${capitalisedName}',
|
|
100
|
+
type: 'CONTENT_COMPONENT',
|
|
57
101
|
allowedTypes: [],
|
|
58
102
|
orientation: 'HORIZONTAL',
|
|
59
|
-
jsx:
|
|
103
|
+
jsx: (() => {
|
|
104
|
+
const { useText } = B;
|
|
105
|
+
const { content } = options;
|
|
106
|
+
return <div className={classes.root}>{useText(content)}</div>;
|
|
107
|
+
})(),
|
|
60
108
|
styles: () => () => ({
|
|
61
109
|
root: {},
|
|
62
110
|
}),
|
|
63
111
|
}))();
|
|
64
|
-
|
|
112
|
+
`;
|
|
65
113
|
yield Promise.all([
|
|
66
|
-
fs_extra_1.outputFile(`src/prefabs/${
|
|
67
|
-
fs_extra_1.outputFile(`src/
|
|
114
|
+
fs_extra_1.outputFile(`src/prefabs/structures/${capitalisedName}/index.ts`, structureIndex),
|
|
115
|
+
fs_extra_1.outputFile(`src/prefabs/structures/${capitalisedName}/options/index.ts`, optionsIndex),
|
|
116
|
+
fs_extra_1.outputFile(`src/prefabs/${name}.tsx`, prefab),
|
|
117
|
+
fs_extra_1.outputFile(`src/components/${name}.js`, component),
|
|
68
118
|
console.log(chalk_1.default.green('The component has been generated')),
|
|
119
|
+
console.log(chalk_1.default.blueBright("\nIf you would like to use the component in another prefab, \nwe recommend adding the import and export of the component structure to 'src/prefabs/structures/index.ts' for a clean import from the same file")),
|
|
69
120
|
]);
|
|
70
121
|
}))();
|
|
71
122
|
//# sourceMappingURL=bb-components-generate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bb-components-generate.js","sourceRoot":"","sources":["../src/bb-components-generate.ts"],"names":[],"mappings":";AAAA,sBAAsB;;;;;;;;;;;;;;AAEtB,0DAAqD;AACrD,kDAA0B;AAC1B,uCAAkD;AAElD,uEAAuE;AACvE,uBAAuB;AAEvB,mBAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAE3E,MAA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