Skip to content
Closed
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: 2 additions & 1 deletion dist/commands/generate.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ export default class Generate extends Command {
static description: string;
static flags: {
help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
features: flags.IOptionFlag<string | undefined>;
features: flags.IOptionFlag<string>;
outputDir: flags.IOptionFlag<string>;
};
run(): Promise<void>;
}
54 changes: 32 additions & 22 deletions dist/commands/generate.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const command_1 = require("@oclif/command");
const fs = require("fs");
const generator_1 = require("../generator");
'use strict'
Object.defineProperty(exports, '__esModule', { value: true })
const tslib_1 = require('tslib')
const command_1 = require('@oclif/command')
const fs = require('fs')
const html_ui_prototyper_1 = require('../html-ui-prototyper')
class Generate extends command_1.Command {
run() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const { flags } = this.parse(Generate);
if (flags.features) {
const processResult = JSON.parse(flags.features);
const generator = new generator_1.default(fs);
const result = yield generator.generate(processResult.features);
this.log(JSON.stringify(result));
}
});
}
run() {
return tslib_1.__awaiter(this, void 0, void 0, function*() {
const { flags } = this.parse(Generate)
if (flags.features) {
const processResult = JSON.parse(flags.features)
const generator = new html_ui_prototyper_1.default(
fs,
flags.outputDir
)
const result = yield generator.generate(processResult.features)
this.log(result.join('\n'))
}
})
}
}
Generate.description = 'Generate html files';
Generate.description = 'Generate html files'
Generate.flags = {
help: command_1.flags.help({ char: 'h' }),
features: command_1.flags.string({ description: 'processed features from ast' })
};
exports.default = Generate;
help: command_1.flags.help({ char: 'h' }),
features: command_1.flags.string({
description: 'processed features from ast',
required: true,
}),
outputDir: command_1.flags.string({
description: 'location where output files will be saved',
required: true,
}),
}
exports.default = Generate
41 changes: 0 additions & 41 deletions dist/generator.js

This file was deleted.

6 changes: 4 additions & 2 deletions dist/generator.d.ts → dist/html-ui-prototyper.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Feature, Prototyper } from 'concordialang-ui-core';
export default class Generator implements Prototyper {
export default class HtmlUIPrototyper implements Prototyper {
private _fs;
constructor(_fs?: any);
private _outputDir;
constructor(_fs: any, _outputDir: string);
generate(features: Feature[]): Promise<string[]>;
private createHtmlFile;
private getAppConfig;
}
62 changes: 62 additions & 0 deletions dist/html-ui-prototyper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
'use strict'
Object.defineProperty(exports, '__esModule', { value: true })
const tslib_1 = require('tslib')
const fs = require('fs')
const util_1 = require('util')
const path_1 = require('path')
const prettier = require('prettier')
const cosmiconfig = require('cosmiconfig')
const widget_factory_1 = require('./widgets/widget-factory')
class HtmlUIPrototyper {
constructor(_fs = fs, _outputDir) {
this._fs = _fs
this._outputDir = _outputDir
}
generate(features) {
return tslib_1.__awaiter(this, void 0, void 0, function*() {
const appConfig = this.getAppConfig()
const factory = new widget_factory_1.default(appConfig)
if (features.length === 0)
return Promise.resolve(['No features found'])
const createFilePromises = []
for (let feature of features) {
const elements = feature.uiElements.map(uiElement =>
factory.create(uiElement)
)
createFilePromises.push(
this.createHtmlFile(feature.name, elements)
)
}
return Promise.all(createFilePromises)
})
}
createHtmlFile(fileName, widgets) {
return tslib_1.__awaiter(this, void 0, void 0, function*() {
let content = widgets.reduce((result, widget) => {
return result + widget.renderToString()
}, '')
content = prettier.format(`<form>${content}</form>`, {
parser: 'html',
htmlWhitespaceSensitivity: 'ignore',
})
const path = path_1.format({
dir: this._outputDir,
name: fileName,
ext: '.html',
})
yield util_1.promisify(fs.writeFile)(path, content)
return path
})
}
getAppConfig() {
try {
const explorer = cosmiconfig()
const configFile = explorer.loadSync('concordialang-ui-html.json')
const appConfig = configFile.config
return appConfig
} catch (e) {
throw new Error('Config file not found')
}
}
}
exports.default = HtmlUIPrototyper
2 changes: 1 addition & 1 deletion dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './generator';
export * from './html-ui-prototyper';
2 changes: 1 addition & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict'
Object.defineProperty(exports, '__esModule', { value: true })
const tslib_1 = require('tslib')
tslib_1.__exportStar(require('./generator'), exports)
tslib_1.__exportStar(require('./html-ui-prototyper'), exports)
23 changes: 23 additions & 0 deletions dist/interfaces/app-config.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export interface AppConfig {
widgets?: {
input?: WidgetConfig;
radio?: WidgetConfig;
checkbox?: WidgetConfig;
select?: WidgetConfig;
label?: LabelConfig;
};
}
export interface WidgetConfig {
opening: string;
closure?: string;
optionOpening?: string;
optionClosure?: string;
wrapperOpening?: string;
wrapperClosure?: string;
label?: LabelConfig;
}
interface LabelConfig {
opening: string;
closure: string;
}
export {};
2 changes: 2 additions & 0 deletions dist/interfaces/app-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
'use strict'
Object.defineProperty(exports, '__esModule', { value: true })
1 change: 1 addition & 0 deletions dist/widgets/prop.d.ts → dist/utils/prop.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export declare const PROPS_INJECTION_POINT = "%s";
export declare function formatProperties(props: any, validProperties: string[]): string;
27 changes: 27 additions & 0 deletions dist/utils/prop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict'
Object.defineProperty(exports, '__esModule', { value: true })
const case_1 = require('case')
exports.PROPS_INJECTION_POINT = '%s'
function formatProperties(props, validProperties) {
const translateProp = key => {
switch (key) {
case 'format':
return 'pattern'
default:
return key
}
}
const getFormattedProp = key => {
let value = case_1.camel(props[key].toString())
return `${translateProp(key)}="${value}"`
}
const formatValid = (result, prop) => {
return validProperties.includes(prop)
? result + getFormattedProp(prop) + ' '
: result
}
return Object.keys(props)
.reduce(formatValid, '')
.trimRight()
}
exports.formatProperties = formatProperties
6 changes: 4 additions & 2 deletions dist/widgets/button.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Widget } from 'concordialang-ui-core';
export declare class Button extends Widget {
import { WidgetConfig } from '../interfaces/app-config';
export default class Button extends Widget {
private _config;
private readonly VALID_PROPERTIES;
constructor(props: any, name?: string);
constructor(props: any, name: string, _config: WidgetConfig);
renderToString(): string;
private getType;
}
45 changes: 27 additions & 18 deletions dist/widgets/button.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const concordialang_ui_core_1 = require("concordialang-ui-core");
const prop_1 = require("./prop");
'use strict'
Object.defineProperty(exports, '__esModule', { value: true })
const concordialang_ui_core_1 = require('concordialang-ui-core')
const prop_1 = require('../utils/prop')
class Button extends concordialang_ui_core_1.Widget {
constructor(props, name) {
super(props, name);
// private readonly DATA_TYPES = ['button', 'submit', 'reset']
this.VALID_PROPERTIES = ['id', 'disabled', 'value'];
}
renderToString() {
const inputType = this.getType(this.props.datatype);
const properties = prop_1.formatProperties(this.props, this.VALID_PROPERTIES);
return `<button ${inputType} ${properties}>${this.name}</button>`;
}
getType(datatype) {
return `type="${datatype || 'button'}"`;
}
constructor(props, name, _config) {
super(props, name || '')
this._config = _config
this.VALID_PROPERTIES = ['id', 'disabled', 'value']
}
renderToString() {
const buttonType = this.getType(this.props.datatype)
let properties = prop_1.formatProperties(
this.props,
this.VALID_PROPERTIES
)
properties = `${buttonType} ${properties}`
const buttonOpening = this._config.opening.replace(
prop_1.PROPS_INJECTION_POINT,
properties
)
const buttonClosure = this._config.closure
return buttonOpening + this.name + buttonClosure
}
getType(datatype) {
return `type="${datatype || 'button'}"`
}
}
exports.Button = Button;
exports.default = Button
7 changes: 5 additions & 2 deletions dist/widgets/checkbox.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Widget } from 'concordialang-ui-core';
export declare class Checkbox extends Widget {
constructor(props: any, name?: string);
import { WidgetConfig } from '../interfaces/app-config';
export default class Checkbox extends Widget {
private _config;
private readonly VALID_PROPERTIES;
constructor(props: any, name: string, _config: WidgetConfig);
renderToString(): string;
}
24 changes: 21 additions & 3 deletions dist/widgets/checkbox.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
'use strict'
Object.defineProperty(exports, '__esModule', { value: true })
const concordialang_ui_core_1 = require('concordialang-ui-core')
const prop_1 = require('../utils/prop')
const wrapper_1 = require('./wrapper')
class Checkbox extends concordialang_ui_core_1.Widget {
constructor(props, name) {
constructor(props, name, _config) {
super(props, name)
this._config = _config
this.VALID_PROPERTIES = ['value', 'required']
}
renderToString() {
return `<input type="checkbox">TESTE`
const inputType = 'type="checkbox"'
let properties = prop_1.formatProperties(
this.props,
this.VALID_PROPERTIES
)
properties = `${inputType} ${properties}`
const inputOpening = this._config.opening.replace(
prop_1.PROPS_INJECTION_POINT,
properties
)
const inputClosure = this._config.closure || ''
return wrapper_1.wrap(
inputOpening + this.name + inputClosure,
this._config
)
}
}
exports.Checkbox = Checkbox
exports.default = Checkbox
4 changes: 0 additions & 4 deletions dist/widgets/index.d.ts

This file was deleted.

7 changes: 0 additions & 7 deletions dist/widgets/index.js

This file was deleted.

7 changes: 4 additions & 3 deletions dist/widgets/input.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Widget } from 'concordialang-ui-core';
export declare class Input extends Widget {
import { WidgetConfig } from '../interfaces/app-config';
export default class Input extends Widget {
private _config;
private readonly VALID_PROPERTIES;
constructor(props: any, name?: string);
constructor(props: any, name: string, _config: WidgetConfig);
renderToString(): string;
private getType;
private typeForDataType;
}
Loading