Befor generating
This commit is contained in:
Generated
Vendored
+35
@@ -0,0 +1,35 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import { FunctionComponent } from "../types";
|
||||
export interface FileProps {
|
||||
/**
|
||||
* `name` prop describes the filename for which should be used when generating the file. If none is specified the filename for the template are used.
|
||||
*/
|
||||
name?: string;
|
||||
/**
|
||||
* `permissions` prop describes the permissions the file should be created with. This is interpreted as an octal number such as 0o777
|
||||
*/
|
||||
permissions?: number;
|
||||
}
|
||||
export declare const FilePropTypes: {
|
||||
/**
|
||||
* `name` prop describes the filename for which should be used when generating the file. If none is specified the filename for the template are used.
|
||||
*/
|
||||
name: PropTypes.Requireable<string>;
|
||||
/**
|
||||
* `permissions` prop describes the permissions the file should be created with. This is interpreted as an octal number such as 0o777
|
||||
*/
|
||||
permissions: PropTypes.Requireable<number>;
|
||||
};
|
||||
/**
|
||||
* Component is used to describe to the generator that you want a file to be created and rendered based on the defined children.
|
||||
*
|
||||
* @component
|
||||
* @example
|
||||
* const name = "test.js"
|
||||
* const permissions = 0o777
|
||||
* return (
|
||||
* <File name={name} permissions={permissions}>Test</File>
|
||||
* )
|
||||
*/
|
||||
declare const File: FunctionComponent<FileProps>;
|
||||
export default File;
|
||||
Generated
Vendored
+47
@@ -0,0 +1,47 @@
|
||||
"use strict";
|
||||
var __assign = (this && this.__assign) || function () {
|
||||
__assign = Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.FilePropTypes = void 0;
|
||||
var jsx_runtime_1 = require("react/jsx-runtime");
|
||||
var prop_types_1 = __importDefault(require("prop-types"));
|
||||
exports.FilePropTypes = {
|
||||
/**
|
||||
* `name` prop describes the filename for which should be used when generating the file. If none is specified the filename for the template are used.
|
||||
*/
|
||||
name: prop_types_1.default.string,
|
||||
/**
|
||||
* `permissions` prop describes the permissions the file should be created with. This is interpreted as an octal number such as 0o777
|
||||
*/
|
||||
permissions: prop_types_1.default.number,
|
||||
};
|
||||
/**
|
||||
* Component is used to describe to the generator that you want a file to be created and rendered based on the defined children.
|
||||
*
|
||||
* @component
|
||||
* @example
|
||||
* const name = "test.js"
|
||||
* const permissions = 0o777
|
||||
* return (
|
||||
* <File name={name} permissions={permissions}>Test</File>
|
||||
* )
|
||||
*/
|
||||
var File = function (_a) {
|
||||
var children = _a.children;
|
||||
return jsx_runtime_1.jsx(jsx_runtime_1.Fragment, { children: children }, void 0);
|
||||
};
|
||||
File.propTypes = __assign({}, exports.FilePropTypes);
|
||||
exports.default = File;
|
||||
//# sourceMappingURL=File.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"File.js","sourceRoot":"","sources":["../../src/components/File.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,0DAAmC;AAetB,QAAA,aAAa,GAAG;IAC3B;;OAEG;IACH,IAAI,EAAE,oBAAS,CAAC,MAAM;IACtB;;OAEG;IACH,WAAW,EAAE,oBAAS,CAAC,MAAM;CAC9B,CAAC;AAEF;;;;;;;;;;GAUG;AACH,IAAM,IAAI,GAAiC,UAAC,EAAY;QAAV,QAAQ,cAAA;IACpD,OAAO,sDAAG,QAAQ,WAAI,CAAC;AACzB,CAAC,CAAC;AAEF,IAAI,CAAC,SAAS,gBACT,qBAAa,CACjB,CAAC;AACF,kBAAe,IAAI,CAAC"}
|
||||
Generated
Vendored
+38
@@ -0,0 +1,38 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import { IndentationTypes } from "../utils";
|
||||
import { FunctionComponent } from "../types";
|
||||
export interface IndentProps {
|
||||
/**
|
||||
* `size` prop expects a string which format should be a number which represent the number of `type`'s to indent each content. Default to no indentation.
|
||||
*/
|
||||
size?: number;
|
||||
/**
|
||||
* `type` prop expects a string, you can use the `IndentationTypes` enum, as either `TABS` or `SPACES`. The `type` defaults to `SPACES`.
|
||||
*/
|
||||
type?: IndentationTypes;
|
||||
}
|
||||
export declare const IndentPropTypes: {
|
||||
/**
|
||||
* `size` prop expects a string which format should be a number which represent the number of `type`'s to indent each content. Default to no indentation.
|
||||
*/
|
||||
size: PropTypes.Requireable<number>;
|
||||
/**
|
||||
* `type` prop expects a string, you can use the `IndentationTypes` enum, as either `TABS` or `SPACES`. The `type` defaults to `SPACES`.
|
||||
*/
|
||||
type: PropTypes.Requireable<IndentationTypes>;
|
||||
};
|
||||
/**
|
||||
* Component is for wrapping multiple components and apply an indentation on those.
|
||||
*
|
||||
* It supports any form of nested components as well, meaning you can have as many nested `Indent` components as you would like.
|
||||
*
|
||||
* @component
|
||||
* @example
|
||||
* const size = 4
|
||||
* const type = IndentationTypes.SPACES
|
||||
* return (
|
||||
* <Indent size={size} type={type}>test</Indent>
|
||||
* )
|
||||
*/
|
||||
declare const Indent: FunctionComponent<IndentProps>;
|
||||
export default Indent;
|
||||
Generated
Vendored
+50
@@ -0,0 +1,50 @@
|
||||
"use strict";
|
||||
var __assign = (this && this.__assign) || function () {
|
||||
__assign = Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.IndentPropTypes = void 0;
|
||||
var jsx_runtime_1 = require("react/jsx-runtime");
|
||||
var prop_types_1 = __importDefault(require("prop-types"));
|
||||
var utils_1 = require("../utils");
|
||||
exports.IndentPropTypes = {
|
||||
/**
|
||||
* `size` prop expects a string which format should be a number which represent the number of `type`'s to indent each content. Default to no indentation.
|
||||
*/
|
||||
size: prop_types_1.default.number,
|
||||
/**
|
||||
* `type` prop expects a string, you can use the `IndentationTypes` enum, as either `TABS` or `SPACES`. The `type` defaults to `SPACES`.
|
||||
*/
|
||||
type: prop_types_1.default.oneOf(Object.values(utils_1.IndentationTypes)),
|
||||
};
|
||||
/**
|
||||
* Component is for wrapping multiple components and apply an indentation on those.
|
||||
*
|
||||
* It supports any form of nested components as well, meaning you can have as many nested `Indent` components as you would like.
|
||||
*
|
||||
* @component
|
||||
* @example
|
||||
* const size = 4
|
||||
* const type = IndentationTypes.SPACES
|
||||
* return (
|
||||
* <Indent size={size} type={type}>test</Indent>
|
||||
* )
|
||||
*/
|
||||
var Indent = function (_a) {
|
||||
var _b = _a.size, size = _b === void 0 ? 0 : _b, _c = _a.type, type = _c === void 0 ? utils_1.IndentationTypes.SPACES : _c, childrenContent = _a.childrenContent;
|
||||
return jsx_runtime_1.jsx(jsx_runtime_1.Fragment, { children: utils_1.withIndendation(childrenContent, size, type) }, void 0);
|
||||
};
|
||||
Indent.propTypes = __assign({}, exports.IndentPropTypes);
|
||||
exports.default = Indent;
|
||||
//# sourceMappingURL=Indent.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"Indent.js","sourceRoot":"","sources":["../../src/components/Indent.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,0DAAmC;AAEnC,kCAA6D;AAchD,QAAA,eAAe,GAAG;IAC7B;;OAEG;IACH,IAAI,EAAE,oBAAS,CAAC,MAAM;IACtB;;OAEG;IACH,IAAI,EAAE,oBAAS,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,wBAAgB,CAAC,CAAC;CACvD,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,IAAM,MAAM,GAAmC,UAAC,EAA6D;QAA3D,YAAQ,EAAR,IAAI,mBAAG,CAAC,KAAA,EAAE,YAA8B,EAA9B,IAAI,mBAAG,wBAAgB,CAAC,MAAM,KAAA,EAAE,eAAe,qBAAA;IACzG,OAAO,sDAAG,uBAAe,CAAC,eAAe,EAAE,IAAI,EAAE,IAAI,CAAC,WAAI,CAAC;AAC7D,CAAC,CAAC;AAEF,MAAM,CAAC,SAAS,gBACX,uBAAe,CACnB,CAAC;AACF,kBAAe,MAAM,CAAC"}
|
||||
Generated
Vendored
+45
@@ -0,0 +1,45 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import { IndentationTypes } from "../utils";
|
||||
import { FunctionComponent } from "../types";
|
||||
export interface TextProps {
|
||||
/**
|
||||
* `indent` prop represents the number of `type`'s to indent each content. Default to no indentation.
|
||||
*/
|
||||
indent?: number;
|
||||
/**
|
||||
* `type` prop expects a string, you can use the `IndentationTypes` enum, as either `TABS` or `SPACES`. The `type` defaults to `SPACES`.
|
||||
*/
|
||||
type?: IndentationTypes;
|
||||
/**
|
||||
* `newLines` prop represents the number of appended new lines. Default to one new line.
|
||||
*/
|
||||
newLines?: number;
|
||||
}
|
||||
export declare const TextPropTypes: {
|
||||
/**
|
||||
* `size` prop expects a string which format should be a number which represent the number of `type`'s to indent each content. Default to no indentation.
|
||||
*/
|
||||
size: PropTypes.Requireable<number>;
|
||||
/**
|
||||
* `type` prop expects a string, you can use the `IndentationTypes` enum, as either `TABS` or `SPACES`. The `type` defaults to `SPACES`.
|
||||
*/
|
||||
type: PropTypes.Requireable<IndentationTypes>;
|
||||
/**
|
||||
* `newLines` prop represents the number of appended new lines. Default to one new line.
|
||||
*/
|
||||
newLines: PropTypes.Requireable<number>;
|
||||
};
|
||||
/**
|
||||
* Component is for defining a group of text which should be rendered on the same line.
|
||||
*
|
||||
* @component
|
||||
* @example
|
||||
* const indent = 4
|
||||
* const type = IndentationTypes.SPACES
|
||||
* const newLines = 2
|
||||
* return (
|
||||
* <Text indent={size} type={type} newLines={newLines}>Test</Text>
|
||||
* )
|
||||
*/
|
||||
declare const Text: FunctionComponent<TextProps>;
|
||||
export default Text;
|
||||
Generated
Vendored
+54
@@ -0,0 +1,54 @@
|
||||
"use strict";
|
||||
var __assign = (this && this.__assign) || function () {
|
||||
__assign = Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.TextPropTypes = void 0;
|
||||
var jsx_runtime_1 = require("react/jsx-runtime");
|
||||
var prop_types_1 = __importDefault(require("prop-types"));
|
||||
var utils_1 = require("../utils");
|
||||
exports.TextPropTypes = {
|
||||
/**
|
||||
* `size` prop expects a string which format should be a number which represent the number of `type`'s to indent each content. Default to no indentation.
|
||||
*/
|
||||
size: prop_types_1.default.number,
|
||||
/**
|
||||
* `type` prop expects a string, you can use the `IndentationTypes` enum, as either `TABS` or `SPACES`. The `type` defaults to `SPACES`.
|
||||
*/
|
||||
type: prop_types_1.default.oneOf(Object.values(utils_1.IndentationTypes)),
|
||||
/**
|
||||
* `newLines` prop represents the number of appended new lines. Default to one new line.
|
||||
*/
|
||||
newLines: prop_types_1.default.number,
|
||||
};
|
||||
/**
|
||||
* Component is for defining a group of text which should be rendered on the same line.
|
||||
*
|
||||
* @component
|
||||
* @example
|
||||
* const indent = 4
|
||||
* const type = IndentationTypes.SPACES
|
||||
* const newLines = 2
|
||||
* return (
|
||||
* <Text indent={size} type={type} newLines={newLines}>Test</Text>
|
||||
* )
|
||||
*/
|
||||
var Text = function (_a) {
|
||||
var _b = _a.indent, indent = _b === void 0 ? 0 : _b, _c = _a.type, type = _c === void 0 ? utils_1.IndentationTypes.SPACES : _c, _d = _a.newLines, newLines = _d === void 0 ? 1 : _d, childrenContent = _a.childrenContent;
|
||||
var contentWithLines = utils_1.withNewLines(childrenContent, newLines);
|
||||
return jsx_runtime_1.jsx(jsx_runtime_1.Fragment, { children: utils_1.withIndendation(contentWithLines, indent, type) }, void 0);
|
||||
};
|
||||
Text.propTypes = __assign({}, exports.TextPropTypes);
|
||||
exports.default = Text;
|
||||
//# sourceMappingURL=Text.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"Text.js","sourceRoot":"","sources":["../../src/components/Text.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,0DAAmC;AAEnC,kCAA2E;AAkB9D,QAAA,aAAa,GAAG;IAC3B;;OAEG;IACH,IAAI,EAAE,oBAAS,CAAC,MAAM;IACtB;;OAEG;IACH,IAAI,EAAE,oBAAS,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,wBAAgB,CAAC,CAAC;IACtD;;OAEG;IACH,QAAQ,EAAE,oBAAS,CAAC,MAAM;CAC3B,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,IAAM,IAAI,GAAiC,UAAC,EAA6E;QAA3E,cAAU,EAAV,MAAM,mBAAG,CAAC,KAAA,EAAE,YAA8B,EAA9B,IAAI,mBAAG,wBAAgB,CAAC,MAAM,KAAA,EAAE,gBAAY,EAAZ,QAAQ,mBAAG,CAAC,KAAA,EAAE,eAAe,qBAAA;IACrH,IAAM,gBAAgB,GAAG,oBAAY,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC;IACjE,OAAO,sDAAG,uBAAe,CAAC,gBAAgB,EAAE,MAAM,EAAE,IAAI,CAAC,WAAI,CAAC;AAChE,CAAC,CAAC;AAEF,IAAI,CAAC,SAAS,gBACT,qBAAa,CACjB,CAAC;AACF,kBAAe,IAAI,CAAC"}
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
Generated
Vendored
+50
@@ -0,0 +1,50 @@
|
||||
"use strict";
|
||||
var __assign = (this && this.__assign) || function () {
|
||||
__assign = Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var jsx_runtime_1 = require("react/jsx-runtime");
|
||||
var utils_1 = require("../../utils");
|
||||
var __1 = require("../../");
|
||||
describe('<File />', function () {
|
||||
test('Should always render as is with default ptops', function () {
|
||||
var defaultProps = {};
|
||||
var wrapper = __1.render(jsx_runtime_1.jsx(__1.File, __assign({}, defaultProps, { children: "Test" }), void 0));
|
||||
expect(wrapper).toEqual('Test');
|
||||
});
|
||||
test('Should alwyas render as is with props', function () {
|
||||
var defaultProps = {
|
||||
fileName: 'test.ts',
|
||||
permissions: 511
|
||||
};
|
||||
var wrapper = __1.render(jsx_runtime_1.jsx(__1.File, __assign({}, defaultProps, { children: "Test" }), void 0));
|
||||
expect(wrapper).toEqual('Test');
|
||||
});
|
||||
test('Should always be able to render Indent', function () {
|
||||
var defaultProps = {};
|
||||
var indentProps = {
|
||||
size: 4,
|
||||
type: utils_1.IndentationTypes.SPACES
|
||||
};
|
||||
var wrapper = __1.render(jsx_runtime_1.jsx(__1.File, __assign({}, defaultProps, { children: jsx_runtime_1.jsx(__1.Indent, __assign({}, indentProps, { children: "Test" }), void 0) }), void 0));
|
||||
expect(wrapper).toEqual(' Test');
|
||||
});
|
||||
test('Should always be able to render Text', function () {
|
||||
var defaultProps = {};
|
||||
var textProps = {
|
||||
indent: 4,
|
||||
type: utils_1.IndentationTypes.SPACES
|
||||
};
|
||||
var wrapper = __1.render(jsx_runtime_1.jsx(__1.File, __assign({}, defaultProps, { children: jsx_runtime_1.jsx(__1.Text, __assign({}, textProps, { children: "Test" }), void 0) }), void 0));
|
||||
expect(wrapper).toEqual(' Test\n');
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=File.spec.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"File.spec.js","sourceRoot":"","sources":["../../../src/components/__tests__/File.spec.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;AACA,qCAA+C;AAC/C,4BAAoD;AAEpD,QAAQ,CAAC,UAAU,EAAE;IACnB,IAAI,CAAC,+CAA+C,EAAE;QACpD,IAAM,YAAY,GAAG,EAAE,CAAC;QACxB,IAAM,OAAO,GAAG,UAAM,CAAC,kBAAC,QAAI,eAAK,YAAY,gCAAa,CAAC,CAAC;QAC5D,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,uCAAuC,EAAE;QAC5C,IAAM,YAAY,GAAG;YACnB,QAAQ,EAAE,SAAS;YACnB,WAAW,EAAE,GAAK;SACnB,CAAC;QACF,IAAM,OAAO,GAAG,UAAM,CAAC,kBAAC,QAAI,eAAK,YAAY,gCAAa,CAAC,CAAC;QAC5D,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,wCAAwC,EAAE;QAC7C,IAAM,YAAY,GAAG,EAAE,CAAC;QACxB,IAAM,WAAW,GAAG;YAClB,IAAI,EAAE,CAAC;YACP,IAAI,EAAE,wBAAgB,CAAC,MAAM;SAC9B,CAAC;QACF,IAAM,OAAO,GAAG,UAAM,CAAC,kBAAC,QAAI,eAAK,YAAY,cAAE,kBAAC,UAAM,eAAK,WAAW,gCAAe,YAAO,CAAC,CAAC;QAC9F,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,sCAAsC,EAAE;QAC3C,IAAM,YAAY,GAAG,EAAE,CAAC;QACxB,IAAM,SAAS,GAAG;YAChB,MAAM,EAAE,CAAC;YACT,IAAI,EAAE,wBAAgB,CAAC,MAAM;SAC9B,CAAC;QACF,IAAM,OAAO,GAAG,UAAM,CAAC,kBAAC,QAAI,eAAK,YAAY,cAAE,kBAAC,QAAI,eAAK,SAAS,gCAAa,YAAO,CAAC,CAAC;QACxF,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
Generated
Vendored
+60
@@ -0,0 +1,60 @@
|
||||
"use strict";
|
||||
var __assign = (this && this.__assign) || function () {
|
||||
__assign = Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var jsx_runtime_1 = require("react/jsx-runtime");
|
||||
var utils_1 = require("../../utils");
|
||||
var __1 = require("../..");
|
||||
describe('<Indent />', function () {
|
||||
test('Should always render as is with default props', function () {
|
||||
var defaultProps = {};
|
||||
var wrapper = __1.render(jsx_runtime_1.jsx(__1.Indent, __assign({}, defaultProps, { children: "Test" }), void 0));
|
||||
expect(wrapper).toEqual('Test');
|
||||
});
|
||||
test('Should always render indentation with spaces', function () {
|
||||
var defaultProps = {
|
||||
size: 4,
|
||||
type: utils_1.IndentationTypes.SPACES
|
||||
};
|
||||
var wrapper = __1.render(jsx_runtime_1.jsx(__1.Indent, __assign({}, defaultProps, { children: "Test" }), void 0));
|
||||
expect(wrapper).toEqual(' Test');
|
||||
});
|
||||
test('Should always render indentation with tabs', function () {
|
||||
var defaultProps = {
|
||||
size: 2,
|
||||
type: utils_1.IndentationTypes.TABS
|
||||
};
|
||||
var wrapper = __1.render(jsx_runtime_1.jsx(__1.Indent, __assign({}, defaultProps, { children: "Test" }), void 0));
|
||||
expect(wrapper).toEqual(' Test');
|
||||
});
|
||||
test('Should be able to make nest indentation', function () {
|
||||
var defaultProps = {
|
||||
size: 4,
|
||||
type: utils_1.IndentationTypes.SPACES
|
||||
};
|
||||
var wrapper = __1.render(jsx_runtime_1.jsx(__1.Indent, __assign({}, defaultProps, { children: jsx_runtime_1.jsx(__1.Indent, __assign({}, defaultProps, { size: 2 }, { children: "Test" }), void 0) }), void 0));
|
||||
expect(wrapper).toEqual(' Test');
|
||||
});
|
||||
test('Should be able contain text component', function () {
|
||||
var defaultProps = {
|
||||
size: 4,
|
||||
type: utils_1.IndentationTypes.SPACES
|
||||
};
|
||||
var defaultTextProps = {
|
||||
indent: 4,
|
||||
type: utils_1.IndentationTypes.SPACES
|
||||
};
|
||||
var wrapper = __1.render(jsx_runtime_1.jsx(__1.Indent, __assign({}, defaultProps, { children: jsx_runtime_1.jsx(__1.Text, __assign({}, defaultTextProps, { children: "Test" }), void 0) }), void 0));
|
||||
expect(wrapper).toEqual(' Test\n');
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=Indent.spec.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"Indent.spec.js","sourceRoot":"","sources":["../../../src/components/__tests__/Indent.spec.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;AACA,qCAA+C;AAC/C,2BAA6C;AAE7C,QAAQ,CAAC,YAAY,EAAE;IACrB,IAAI,CAAC,+CAA+C,EAAE;QACpD,IAAM,YAAY,GAAG,EAAE,CAAC;QACxB,IAAM,OAAO,GAAG,UAAM,CAAC,kBAAC,UAAM,eAAK,YAAY,gCAAe,CAAC,CAAC;QAChE,MAAM,CAAC,OAAO,CAAC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gB,CAAC,MAAM;SAC9B,CAAC;QACF,IAAM,OAAO,GAAG,UAAM,CAAC,kBAAC,UAAM,eAAK,YAAY,cAAE,kBAAC,QAAI,eAAK,gBAAgB,gCAAa,YAAS,CAAC,CAAC;QACnG,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC5C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
Generated
Vendored
+45
@@ -0,0 +1,45 @@
|
||||
"use strict";
|
||||
var __assign = (this && this.__assign) || function () {
|
||||
__assign = Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var jsx_runtime_1 = require("react/jsx-runtime");
|
||||
var utils_1 = require("../../utils");
|
||||
var __1 = require("../..");
|
||||
describe('<Text />', function () {
|
||||
test('Should always render as is text with default props', function () {
|
||||
var defaultProps = {};
|
||||
var wrapper = __1.render(jsx_runtime_1.jsx(__1.Text, __assign({}, defaultProps, { children: "Test" }), void 0));
|
||||
expect(wrapper).toEqual('Test\n');
|
||||
});
|
||||
test('Should always render indentation with spaces', function () {
|
||||
var defaultProps = {
|
||||
indent: 4,
|
||||
type: utils_1.IndentationTypes.SPACES
|
||||
};
|
||||
var wrapper = __1.render(jsx_runtime_1.jsx(__1.Text, __assign({}, defaultProps, { children: "Test" }), void 0));
|
||||
expect(wrapper).toEqual(' Test\n');
|
||||
});
|
||||
test('Should always render indentation with tabs', function () {
|
||||
var defaultProps = {
|
||||
indent: 2,
|
||||
type: utils_1.IndentationTypes.TABS
|
||||
};
|
||||
var wrapper = __1.render(jsx_runtime_1.jsx(__1.Text, __assign({}, defaultProps, { children: "Test" }), void 0));
|
||||
expect(wrapper).toEqual(' Test\n');
|
||||
});
|
||||
test('Should be able to render nest texts', function () {
|
||||
var defaultProps = {};
|
||||
var wrapper = __1.render(jsx_runtime_1.jsx(__1.Text, __assign({}, defaultProps, { children: jsx_runtime_1.jsx(__1.Text, __assign({}, defaultProps, { children: "Test" }), void 0) }), void 0));
|
||||
expect(wrapper).toEqual('Test\n\n');
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=Text.spec.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"Text.spec.js","sourceRoot":"","sources":["../../../src/components/__tests__/Text.spec.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;AACA,qCAA+C;AAC/C,2BAAqC;AAErC,QAAQ,CAAC,UAAU,EAAE;IACnB,IAAI,CAAC,oDAAoD,EAAE;QACzD,IAAM,YAAY,GAAG,EAAE,CAAC;QACxB,IAAM,OAAO,GAAG,UAAM,CAAC,kBAAC,QAAI,eAAK,YAAY,gCAAa,CAAC,CAAC;QAC5D,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,8CAA8C,EAAE;QACnD,IAAM,YAAY,GAAG;YACnB,MAAM,EAAE,CAAC;YACT,IAAI,EAAE,wBAAgB,CAAC,MAAM;SAC9B,CAAC;QACF,IAAM,OAAO,GAAG,UAAM,CAAC,kBAAC,QAAI,eAAK,YAAY,gCAAa,CAAC,CAAC;QAC5D,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,4CAA4C,EAAE;QACjD,IAAM,YAAY,GAAG;YACnB,MAAM,EAAE,CAAC;YACT,IAAI,EAAE,wBAAgB,CAAC,IAAI;SAC5B,CAAC;QACF,IAAM,OAAO,GAAG,UAAM,CAAC,kBAAC,QAAI,eAAK,YAAY,gCAAa,CAAC,CAAC;QAC5D,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,qCAAqC,EAAE;QAC1C,IAAM,YAAY,GAAG,EAAE,CAAC;QACxB,IAAM,OAAO,GAAG,UAAM,CAAC,kBAAC,QAAI,eAAK,YAAY,cAAE,kBAAC,QAAI,eAAK,YAAY,gCAAa,YAAO,CAAC,CAAC;QAC3F,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
||||
Generated
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
export { default as File } from "./File";
|
||||
export type { FileProps } from "./File";
|
||||
export { default as Text } from "./Text";
|
||||
export type { TextProps } from "./Text";
|
||||
export { default as Indent } from "./Indent";
|
||||
export type { IndentProps } from "./Indent";
|
||||
Generated
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Indent = exports.Text = exports.File = void 0;
|
||||
var File_1 = require("./File");
|
||||
Object.defineProperty(exports, "File", { enumerable: true, get: function () { return __importDefault(File_1).default; } });
|
||||
var Text_1 = require("./Text");
|
||||
Object.defineProperty(exports, "Text", { enumerable: true, get: function () { return __importDefault(Text_1).default; } });
|
||||
var Indent_1 = require("./Indent");
|
||||
Object.defineProperty(exports, "Indent", { enumerable: true, get: function () { return __importDefault(Indent_1).default; } });
|
||||
//# sourceMappingURL=index.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":";;;;;;AAAA,+BAAyC;AAAhC,6GAAA,OAAO,OAAQ;AAGxB,+BAAyC;AAAhC,6GAAA,OAAO,OAAQ;AAGxB,mCAA6C;AAApC,iHAAA,OAAO,OAAU"}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
export * from "./components";
|
||||
export * from "./renderer";
|
||||
export * from "./transpiler";
|
||||
export * from "./types";
|
||||
export { IndentationTypes, withIndendation, withNewLines } from "./utils";
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.withNewLines = exports.withIndendation = exports.IndentationTypes = void 0;
|
||||
__exportStar(require("./components"), exports);
|
||||
__exportStar(require("./renderer"), exports);
|
||||
__exportStar(require("./transpiler"), exports);
|
||||
__exportStar(require("./types"), exports);
|
||||
var utils_1 = require("./utils");
|
||||
Object.defineProperty(exports, "IndentationTypes", { enumerable: true, get: function () { return utils_1.IndentationTypes; } });
|
||||
Object.defineProperty(exports, "withIndendation", { enumerable: true, get: function () { return utils_1.withIndendation; } });
|
||||
Object.defineProperty(exports, "withNewLines", { enumerable: true, get: function () { return utils_1.withNewLines; } });
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,6CAA2B;AAC3B,+CAA6B;AAC7B,0CAAwB;AACxB,iCAA0E;AAAjE,yGAAA,gBAAgB,OAAA;AAAE,wGAAA,eAAe,OAAA;AAAE,qGAAA,YAAY,OAAA"}
|
||||
Generated
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
declare function _exports(): Promise<React.FunctionComponentElement<import("../../..").PropsWithChildrenContent<import("../../../components").FileProps>>>;
|
||||
export = _exports;
|
||||
import React = require("react");
|
||||
Generated
Vendored
+48
@@ -0,0 +1,48 @@
|
||||
"use strict";
|
||||
/* eslint-disable */
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
var React = require('react');
|
||||
var File = require('../../../components').File;
|
||||
module.exports = function () {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
return [2 /*return*/, React.createElement(File, { name: 'file.html' }, ['Content'])];
|
||||
});
|
||||
});
|
||||
};
|
||||
//# sourceMappingURL=async-template.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"async-template.js","sourceRoot":"","sources":["../../../../src/renderer/__tests__/file-tests/async-template.js"],"names":[],"mappings":";AAAA,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEpB,IAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AACvB,IAAA,IAAI,GAAK,OAAO,CAAC,qBAAqB,CAAC,KAAnC,CAAoC;AAEhD,MAAM,CAAC,OAAO,GAAG;;;YACf,sBAAO,KAAK,CAAC,aAAa,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC,EAAC;;;CACtE,CAAC"}
|
||||
Generated
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
declare function _exports(): (React.FunctionComponentElement<import("../../..").PropsWithChildrenContent<import("../../../components").FileProps>> | undefined)[];
|
||||
export = _exports;
|
||||
import React = require("react");
|
||||
Generated
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
/* eslint-disable */
|
||||
var React = require('react');
|
||||
var File = require('../../../components').File;
|
||||
module.exports = function () {
|
||||
return [
|
||||
React.createElement(File, { name: 'file1.html' }, ['Content1']),
|
||||
undefined,
|
||||
React.createElement(File, { name: 'file2.html' }, ['Content2'])
|
||||
];
|
||||
};
|
||||
//# sourceMappingURL=file-templates.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"file-templates.js","sourceRoot":"","sources":["../../../../src/renderer/__tests__/file-tests/file-templates.js"],"names":[],"mappings":";AAAA,oBAAoB;AAEpB,IAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AACvB,IAAA,IAAI,GAAK,OAAO,CAAC,qBAAqB,CAAC,KAAnC,CAAoC;AAEhD,MAAM,CAAC,OAAO,GAAG;IACf,OAAO;QACL,KAAK,CAAC,aAAa,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC;QAC/D,SAAS;QACT,KAAK,CAAC,aAAa,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC;KAChE,CAAC;AACJ,CAAC,CAAC"}
|
||||
Generated
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
declare function _exports(): React.FunctionComponentElement<import("../../..").PropsWithChildrenContent<import("../../../components").FileProps>>;
|
||||
export = _exports;
|
||||
import React = require("react");
|
||||
Generated
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
/* eslint-disable */
|
||||
var React = require('react');
|
||||
var File = require('../../../components').File;
|
||||
module.exports = function () {
|
||||
return React.createElement(File, { name: 'file.html' }, ['Content']);
|
||||
};
|
||||
//# sourceMappingURL=single-template.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"single-template.js","sourceRoot":"","sources":["../../../../src/renderer/__tests__/file-tests/single-template.js"],"names":[],"mappings":";AAAA,oBAAoB;AAEpB,IAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AACvB,IAAA,IAAI,GAAK,OAAO,CAAC,qBAAqB,CAAC,KAAnC,CAAoC;AAEhD,MAAM,CAAC,OAAO,GAAG;IACf,OAAO,KAAK,CAAC,aAAa,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;AACvE,CAAC,CAAC"}
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
Generated
Vendored
+165
@@ -0,0 +1,165 @@
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
var __assign = (this && this.__assign) || function () {
|
||||
__assign = Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var jsx_runtime_1 = require("react/jsx-runtime");
|
||||
var react_1 = __importDefault(require("react"));
|
||||
var __1 = require("../..");
|
||||
describe('Renderer', function () {
|
||||
test('should render works when element is string', function () {
|
||||
var content = __1.render("Test 1");
|
||||
expect(content).toEqual("Test 1");
|
||||
});
|
||||
test('should render works when element is a Funcion Component', function () {
|
||||
function Test() {
|
||||
return jsx_runtime_1.jsx(jsx_runtime_1.Fragment, { children: "Test 2" }, void 0);
|
||||
}
|
||||
var content = __1.render(jsx_runtime_1.jsx(Test, {}, void 0));
|
||||
expect(content).toEqual("Test 2");
|
||||
});
|
||||
test('should render works when element is a Class Component', function () {
|
||||
var Test = /** @class */ (function (_super) {
|
||||
__extends(Test, _super);
|
||||
function Test(props) {
|
||||
return _super.call(this, props) || this;
|
||||
}
|
||||
Test.prototype.render = function () {
|
||||
return jsx_runtime_1.jsx(jsx_runtime_1.Fragment, { children: "Test 3" }, void 0);
|
||||
};
|
||||
return Test;
|
||||
}(react_1.default.Component));
|
||||
var content = __1.render(jsx_runtime_1.jsx(Test, {}, void 0));
|
||||
expect(content).toEqual("Test 3");
|
||||
});
|
||||
test('should render works with nested hierarchy', function () {
|
||||
function NestedComponent() {
|
||||
return jsx_runtime_1.jsx(jsx_runtime_1.Fragment, { children: "Nested Component" }, void 0);
|
||||
}
|
||||
function FunctionComponent() {
|
||||
return jsx_runtime_1.jsxs(jsx_runtime_1.Fragment, { children: ["Function Component ", jsx_runtime_1.jsx(NestedComponent, {}, void 0), "\n"] }, void 0);
|
||||
}
|
||||
var ClassComponent = /** @class */ (function (_super) {
|
||||
__extends(ClassComponent, _super);
|
||||
function ClassComponent(props) {
|
||||
return _super.call(this, props) || this;
|
||||
}
|
||||
ClassComponent.prototype.render = function () {
|
||||
return jsx_runtime_1.jsxs(jsx_runtime_1.Fragment, { children: ["Class Component", "\n"] }, void 0);
|
||||
};
|
||||
return ClassComponent;
|
||||
}(react_1.default.Component));
|
||||
var content = __1.render(jsx_runtime_1.jsxs(jsx_runtime_1.Fragment, { children: ["some inlined text", "\n", jsx_runtime_1.jsx(FunctionComponent, {}, void 0),
|
||||
jsx_runtime_1.jsx(ClassComponent, {}, void 0)] }, void 0));
|
||||
expect(content).toEqual("some inlined text\nFunction Component Nested Component\nClass Component\n");
|
||||
});
|
||||
test('should render works with props', function () {
|
||||
function Test(_a) {
|
||||
var someProp = _a.someProp;
|
||||
if (!someProp) {
|
||||
return jsx_runtime_1.jsx(Test, { someProp: "Nested prop" }, void 0);
|
||||
}
|
||||
return jsx_runtime_1.jsx(jsx_runtime_1.Fragment, { children: someProp }, void 0);
|
||||
}
|
||||
var content = __1.render(jsx_runtime_1.jsx(Test, {}, void 0));
|
||||
expect(content).toEqual("Nested prop");
|
||||
});
|
||||
test('should render works with null as returned value', function () {
|
||||
function Test() {
|
||||
return null;
|
||||
}
|
||||
var content = __1.render(jsx_runtime_1.jsx(Test, {}, void 0));
|
||||
expect(content).toEqual("");
|
||||
});
|
||||
test('should render works nested null value', function () {
|
||||
function NullComponent() {
|
||||
return null;
|
||||
}
|
||||
function NestedComponent() {
|
||||
return (jsx_runtime_1.jsxs(jsx_runtime_1.Fragment, { children: [jsx_runtime_1.jsx(NullComponent, {}, void 0), "some text"] }, void 0));
|
||||
}
|
||||
function Component() {
|
||||
return (jsx_runtime_1.jsxs(jsx_runtime_1.Fragment, { children: [jsx_runtime_1.jsx(NullComponent, {}, void 0),
|
||||
jsx_runtime_1.jsx(NestedComponent, {}, void 0),
|
||||
jsx_runtime_1.jsx(NullComponent, {}, void 0)] }, void 0));
|
||||
}
|
||||
var content = __1.render(jsx_runtime_1.jsx(Component, {}, void 0));
|
||||
expect(content).toEqual("some text");
|
||||
});
|
||||
test('should works with array as returned value', function () {
|
||||
function Component(_a) {
|
||||
var text = _a.text;
|
||||
return jsx_runtime_1.jsx(jsx_runtime_1.Fragment, { children: text }, void 0);
|
||||
}
|
||||
function Test() {
|
||||
return [
|
||||
jsx_runtime_1.jsx(Component, { text: 'some' }, void 0),
|
||||
jsx_runtime_1.jsx(Component, { text: ' text' }, void 0),
|
||||
jsx_runtime_1.jsx(Component, { text: ' is rendered' }, void 0),
|
||||
];
|
||||
}
|
||||
var content = __1.render(jsx_runtime_1.jsx(Test, {}, void 0));
|
||||
expect(content).toEqual("some text is rendered");
|
||||
});
|
||||
test('should throws error due to using React hooks', function () {
|
||||
function Component() {
|
||||
var _a = react_1.default.useState(), someState = _a[0], setSomeState = _a[1];
|
||||
return null;
|
||||
}
|
||||
var error = undefined;
|
||||
try {
|
||||
__1.render(jsx_runtime_1.jsx(Component, {}, void 0));
|
||||
}
|
||||
catch (err) {
|
||||
error = err;
|
||||
}
|
||||
// check substring of the desired error
|
||||
expect(error.message).toContain('Invalid hook call.');
|
||||
});
|
||||
test('should skips internal React components', function () {
|
||||
function Component() {
|
||||
return (jsx_runtime_1.jsx(react_1.default.Suspense, __assign({ fallback: '...loading' }, { children: "some text" }), void 0));
|
||||
}
|
||||
var content = __1.render(jsx_runtime_1.jsx(Component, {}, void 0));
|
||||
expect(content).toEqual("some text");
|
||||
});
|
||||
test('should throws error due to using HTML tags', function () {
|
||||
function Component() {
|
||||
return (jsx_runtime_1.jsx("div", { children: "some text" }, void 0));
|
||||
}
|
||||
var error = undefined;
|
||||
try {
|
||||
__1.render(jsx_runtime_1.jsx(Component, {}, void 0));
|
||||
}
|
||||
catch (err) {
|
||||
error = err;
|
||||
}
|
||||
// check substring of the desired error
|
||||
expect(error.message).toEqual('HTML tags is not supported yet.');
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=renderer.spec.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"renderer.spec.js","sourceRoot":"","sources":["../../../src/renderer/__tests__/renderer.spec.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAA0B;AAC1B,2BAA+B;AAE/B,QAAQ,CAAC,UAAU,EAAE;IACnB,IAAI,CAAC,4CAA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,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,4CAA4C,EAAE;QACjD,SAAS,SAAS;YAChB,OAAO,CACL,2DAEM,CACP,CAAA;QACH,CAAC;QAED,IAAI,KAAK,GAAG,SAAS,CAAC;QACtB,IAAI;YACF,UAAM,CAAC,kBAAC,SAAS,aAAG,CAAC,CAAC;SACvB;QAAC,OAAM,GAAG,EAAE;YACX,KAAK,GAAG,GAAG,CAAC;SACb;QACD,uCAAuC;QACvC,MAAM,CAAE,KAAe,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,iCAAiC,CAAC,CAAC;IAC9E,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
Generated
Vendored
+98
@@ -0,0 +1,98 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var path_1 = __importDefault(require("path"));
|
||||
var template_1 = require("../template");
|
||||
describe('renderTemplate', function () {
|
||||
test('should render a single File template', function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var filePath, renderedContent;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
filePath = path_1.default.resolve(__dirname, './file-tests/single-template.js');
|
||||
return [4 /*yield*/, template_1.renderTemplate(filePath, {})];
|
||||
case 1:
|
||||
renderedContent = _a.sent();
|
||||
expect(typeof renderedContent).toEqual('object');
|
||||
expect(renderedContent.content).toEqual('Content');
|
||||
expect(renderedContent.metadata.fileName).toEqual('file.html');
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
test('should render an array of File templates', function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var filePath, renderedContent;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
filePath = path_1.default.resolve(__dirname, './file-tests/file-templates.js');
|
||||
return [4 /*yield*/, template_1.renderTemplate(filePath, {})];
|
||||
case 1:
|
||||
renderedContent = _a.sent();
|
||||
expect(Array.isArray(renderedContent)).toEqual(true);
|
||||
expect(typeof renderedContent[0]).toEqual('object');
|
||||
expect(renderedContent[0].content).toEqual('Content1');
|
||||
expect(renderedContent[0].metadata.fileName).toEqual('file1.html');
|
||||
expect(typeof renderedContent[1]).toEqual('object');
|
||||
expect(renderedContent[1].content).toEqual('Content2');
|
||||
expect(renderedContent[1].metadata.fileName).toEqual('file2.html');
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
test('should render a single async File template', function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var filePath, renderedContent;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
filePath = path_1.default.resolve(__dirname, './file-tests/async-template.js');
|
||||
return [4 /*yield*/, template_1.renderTemplate(filePath, {})];
|
||||
case 1:
|
||||
renderedContent = _a.sent();
|
||||
expect(typeof renderedContent).toEqual('object');
|
||||
expect(renderedContent.content).toEqual('Content');
|
||||
expect(renderedContent.metadata.fileName).toEqual('file.html');
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
});
|
||||
//# sourceMappingURL=template.spec.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"template.spec.js","sourceRoot":"","sources":["../../../src/renderer/__tests__/template.spec.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,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,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;oBACvD,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;;;;SACpE,CAAC,CAAC;IAEH,IAAI,CAAC,4CAA4C,EAAE;;;;;oBAC3C,QAAQ,GAAG,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,gCAAgC,CAAC,CAAC;oBACnD,qBAAM,yBAAc,CAAC,QAAQ,EAAE,EAAS,CAAC,EAAA;;oBAA3D,eAAe,GAAG,SAAiE;oBAEzF,MAAM,CAAC,OAAO,eAAe,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;oBACjD,MAAM,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;oBACnD,MAAM,CAAC,eAAe,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;;;;SAChE,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
||||
Generated
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
export * from "./renderer";
|
||||
export * from "./template";
|
||||
Generated
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
__exportStar(require("./renderer"), exports);
|
||||
__exportStar(require("./template"), exports);
|
||||
//# sourceMappingURL=index.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/renderer/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAA2B;AAC3B,6CAA2B"}
|
||||
Generated
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
/// <reference types="react" />
|
||||
/**
|
||||
* Renders given component to string
|
||||
*
|
||||
* @param {ReactNode} component a given component to rendering
|
||||
* @example
|
||||
* function Component({ textProp }) {
|
||||
* return <>{textProp}</>
|
||||
* }
|
||||
* render(<Component textProp="someText" />)
|
||||
* @returns {string}
|
||||
*/
|
||||
export declare function render(component: React.ReactNode): string;
|
||||
Generated
Vendored
+87
@@ -0,0 +1,87 @@
|
||||
"use strict";
|
||||
var __assign = (this && this.__assign) || function () {
|
||||
__assign = Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.render = void 0;
|
||||
/**
|
||||
* Normalizes given props with render children to string and save value to `childrenContent` prop
|
||||
* @private
|
||||
* @param {Any} props
|
||||
* @returns {Any} normalized props.
|
||||
*/
|
||||
function normalizeProps(props) {
|
||||
return __assign(__assign({}, props), { childrenContent: render(props.children) });
|
||||
}
|
||||
/**
|
||||
* Executes a `render` method on a given component (in the case of a class component)
|
||||
* or executes the component itself (a functional component) to get pure string or complex value for the next operations
|
||||
* @private
|
||||
* @param {React.ReactElement} element a given component or complex form
|
||||
* @returns {(React.ReactElement | string)}
|
||||
*/
|
||||
function createElement(element) {
|
||||
if (!element) {
|
||||
return "";
|
||||
}
|
||||
var typeOf = typeof element.type;
|
||||
if (typeOf === 'string') {
|
||||
// HTML (also not standard) tags case
|
||||
throw new Error("HTML tags is not supported yet.");
|
||||
}
|
||||
else if (typeOf === 'symbol') {
|
||||
// internal React types like Fragments, Portal etc. We skip them.
|
||||
return render(element.props.children);
|
||||
}
|
||||
else if (typeOf === 'function') {
|
||||
// custom components case
|
||||
var type = element.type;
|
||||
var prototype = type.prototype;
|
||||
// Class component case
|
||||
if (prototype && typeof prototype.isReactComponent === "object") {
|
||||
var clazzComp = new type(normalizeProps(element.props));
|
||||
return createElement(clazzComp.render());
|
||||
}
|
||||
// Function component case
|
||||
return createElement(type(normalizeProps(element.props)));
|
||||
}
|
||||
return render(element) || "";
|
||||
}
|
||||
/**
|
||||
* Renders given component to string
|
||||
*
|
||||
* @param {ReactNode} component a given component to rendering
|
||||
* @example
|
||||
* function Component({ textProp }) {
|
||||
* return <>{textProp}</>
|
||||
* }
|
||||
* render(<Component textProp="someText" />)
|
||||
* @returns {string}
|
||||
*/
|
||||
function render(component) {
|
||||
var content = "";
|
||||
var typeOf = typeof component;
|
||||
if (typeOf === 'string') {
|
||||
content += component;
|
||||
}
|
||||
else if (Array.isArray(component)) {
|
||||
content += component.map(function (child) {
|
||||
var childValue = createElement(child);
|
||||
return render(childValue);
|
||||
}).join("");
|
||||
}
|
||||
else if (typeOf === "object") {
|
||||
content += createElement(component);
|
||||
}
|
||||
return content;
|
||||
}
|
||||
exports.render = render;
|
||||
//# sourceMappingURL=renderer.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"renderer.js","sourceRoot":"","sources":["../../src/renderer/renderer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAEA;;;;;GAKG;AACH,SAAS,cAAc,CAAU,KAAU;IACzC,6BACK,KAAK,KACR,eAAe,EAAE,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,IACxC;AACH,CAAC;AAED;;;;;;GAMG;AACH,SAAS,aAAa,CAAC,OAA2B;IAChD,IAAI,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,UAAU,GAAG,aAAa,CAAC,KAA2B,CAAC,CAAC;YAC9D,OAAO,MAAM,CAAC,UAAU,CAAC,CAAC;QAC5B,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;KACb;SAAM,IAAI,MAAM,KAAK,QAAQ,EAAE;QAC9B,OAAO,IAAI,aAAa,CAAC,SAA+B,CAAC,CAAC;KAC3D;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAdD,wBAcC"}
|
||||
Generated
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
import { TemplateContext, TemplateRenderResult } from "../types";
|
||||
/**
|
||||
* render a file with react. This function automatically transforms jsx to js before importing the component.
|
||||
*
|
||||
* @param filepath the path to file to render
|
||||
*/
|
||||
export declare function renderTemplate(filepath: string, context: TemplateContext): Promise<TemplateRenderResult[] | TemplateRenderResult | undefined>;
|
||||
Generated
Vendored
+136
@@ -0,0 +1,136 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.renderTemplate = void 0;
|
||||
var renderer_1 = require("./renderer");
|
||||
var utils_1 = require("../utils");
|
||||
/**
|
||||
* render a file with react. This function automatically transforms jsx to js before importing the component.
|
||||
*
|
||||
* @param filepath the path to file to render
|
||||
*/
|
||||
function renderTemplate(filepath, context) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var data, component, err_1;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
if (!utils_1.isJsFile(filepath)) {
|
||||
return [2 /*return*/, undefined];
|
||||
}
|
||||
data = undefined;
|
||||
_a.label = 1;
|
||||
case 1:
|
||||
_a.trys.push([1, 4, , 5]);
|
||||
return [4 /*yield*/, importComponent(filepath)];
|
||||
case 2:
|
||||
component = _a.sent();
|
||||
if (component === undefined) {
|
||||
return [2 /*return*/, undefined];
|
||||
}
|
||||
return [4 /*yield*/, component(context)];
|
||||
case 3:
|
||||
data = _a.sent();
|
||||
return [3 /*break*/, 5];
|
||||
case 4:
|
||||
err_1 = _a.sent();
|
||||
throw err_1;
|
||||
case 5:
|
||||
// undefined, null etc. cases
|
||||
if (!data) {
|
||||
return [2 /*return*/, undefined];
|
||||
}
|
||||
if (Array.isArray(data)) {
|
||||
return [2 /*return*/, data.map(function (file) { return file && renderFile(file); }).filter(Boolean)];
|
||||
}
|
||||
return [2 /*return*/, renderFile(data)];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.renderTemplate = renderTemplate;
|
||||
/**
|
||||
* Imports a given file and return the imported component
|
||||
*
|
||||
* @private
|
||||
* @param filepath to import
|
||||
*/
|
||||
function importComponent(filepath) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
try {
|
||||
// we should import component only in NodeJS
|
||||
if (require === undefined)
|
||||
resolve(undefined);
|
||||
// remove from cache imported file
|
||||
delete require.cache[require.resolve(filepath)];
|
||||
var component = require(filepath);
|
||||
if (typeof component === "function")
|
||||
resolve(component);
|
||||
if (typeof component.default === "function")
|
||||
resolve(component.default);
|
||||
resolve(undefined);
|
||||
}
|
||||
catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Render a single File component.
|
||||
*
|
||||
* @private
|
||||
* @param {React.ReactElement} file to import
|
||||
*/
|
||||
function renderFile(file) {
|
||||
if (typeof file !== "object") {
|
||||
return undefined;
|
||||
}
|
||||
var type = file.type, _a = file.props, props = _a === void 0 ? {} : _a;
|
||||
// if no File component is found as root, don't render it.
|
||||
if (typeof type !== "function" || type.name !== "File") {
|
||||
return undefined;
|
||||
}
|
||||
return {
|
||||
content: renderer_1.render(props.children),
|
||||
metadata: {
|
||||
fileName: props.name,
|
||||
permissions: props.permissions,
|
||||
}
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=template.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"template.js","sourceRoot":"","sources":["../../src/renderer/template.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,uCAAoC;AACpC,kCAAoC;AAGpC;;;;GAIG;AACH,SAAsB,cAAc,CAAC,QAAgB,EAAE,OAAwB;;;;;;oBAC7E,IAAI,CAAC,gBAAQ,CAAC,QAAQ,CAAC,EAAE;wBACvB,sBAAO,SAAS,EAAC;qBAClB;oBAEG,IAAI,GAAG,SAAS,CAAC;;;;oBAED,qBAAM,eAAe,CAAC,QAAQ,CAAC,EAAA;;oBAA3C,SAAS,GAAG,SAA+B;oBACjD,IAAI,SAAS,KAAK,SAAS,EAAE;wBAC3B,sBAAO,SAAS,EAAC;qBAClB;oBACM,qBAAM,SAAS,CAAC,OAAO,CAAC,EAAA;;oBAA/B,IAAI,GAAG,SAAwB,CAAC;;;;oBAEhC,MAAM,KAAG,CAAC;;oBAGZ,6BAA6B;oBAC7B,IAAI,CAAC,IAAI,EAAE;wBACT,sBAAO,SAAS,EAAC;qBAClB;oBAED,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;wBACvB,sBAAO,IAAI,CAAC,GAAG,CAAC,UAAA,IAAI,IAAI,OAAA,IAAI,IAAI,UAAU,CAAC,IAAI,CAAC,EAAxB,CAAwB,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,EAAC;qBACnE;oBACD,sBAAO,UAAU,CAAC,IAAI,CAAC,EAAC;;;;CACzB;AAzBD,wCAyBC;AAED;;;;;GAKG;AACH,SAAS,eAAe,CAAC,QAAgB;IACvC,OAAO,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;QACjC,IAAI;YACF,4CAA4C;YAC5C,IAAI,OAAO,KAAK,SAAS;gBAAE,OAAO,CAAC,SAAS,CAAC,CAAC;YAC9C,kCAAkC;YAClC,OAAO,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;YAEhD,IAAM,SAAS,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;YACpC,IAAI,OAAO,SAAS,KAAK,UAAU;gBAAE,OAAO,CAAC,SAAS,CAAC,CAAC;YACxD,IAAI,OAAO,SAAS,CAAC,OAAO,KAAK,UAAU;gBAAE,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;YACxE,OAAO,CAAC,SAAS,CAAC,CAAC;SACpB;QAAC,OAAM,GAAG,EAAE;YACX,MAAM,CAAC,GAAG,CAAC,CAAC;SACb;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACH,SAAS,UAAU,CAAC,IAAwB;IAC1C,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,OAAO,SAAS,CAAC;KAClB;IACO,IAAA,IAAI,GAAiB,IAAI,KAArB,EAAE,KAAe,IAAI,MAAT,EAAV,KAAK,mBAAG,EAAE,KAAA,CAAU;IAElC,0DAA0D;IAC1D,IAAI,OAAO,IAAI,KAAK,UAAU,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE;QACtD,OAAO,SAAS,CAAC;KAClB;IAED,OAAO;QACL,OAAO,EAAE,iBAAM,CAAC,KAAK,CAAC,QAAQ,CAAC;QAC/B,QAAQ,EAAE;YACR,QAAQ,EAAE,KAAK,CAAC,IAAI;YACpB,WAAW,EAAE,KAAK,CAAC,WAAW;SAC/B;KACF,CAAC;AACJ,CAAC"}
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
Generated
Vendored
+256
@@ -0,0 +1,256 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var fs_1 = __importDefault(require("fs"));
|
||||
var path_1 = __importDefault(require("path"));
|
||||
var util_1 = require("util");
|
||||
var transpiler_1 = require("../transpiler");
|
||||
var renderer_1 = require("../../renderer");
|
||||
var readFile = util_1.promisify(fs_1.default.readFile);
|
||||
describe('Transpiler', function () {
|
||||
var testFiles = path_1.default.resolve(__dirname, './testfiles');
|
||||
var outputFiles = path_1.default.resolve(__dirname, './__transpiled_testfiles');
|
||||
beforeAll(function (done) { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var e_1;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
_a.trys.push([0, 2, , 3]);
|
||||
return [4 /*yield*/, transpiler_1.transpileFiles(testFiles, outputFiles, {
|
||||
recursive: true
|
||||
})];
|
||||
case 1:
|
||||
_a.sent();
|
||||
done();
|
||||
return [3 /*break*/, 3];
|
||||
case 2:
|
||||
e_1 = _a.sent();
|
||||
console.log(e_1);
|
||||
done(e_1);
|
||||
return [3 /*break*/, 3];
|
||||
case 3: return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
describe('should transpile CommonJS files', function () {
|
||||
describe('with a simple setup', function () {
|
||||
var commonjs_testFile = path_1.default.resolve(outputFiles, './CommonJS/simple.js');
|
||||
var commonjs_testFileMap = path_1.default.resolve(outputFiles, './CommonJS/simple.js.map');
|
||||
test('and import correctly', function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var content, mapContent, _a;
|
||||
return __generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0: return [4 /*yield*/, readFile(commonjs_testFile, 'utf8')];
|
||||
case 1:
|
||||
content = _b.sent();
|
||||
expect(switchToUnixLinebreaks(content)).toMatchSnapshot();
|
||||
return [4 /*yield*/, readFile(commonjs_testFileMap, 'utf8')];
|
||||
case 2:
|
||||
mapContent = _b.sent();
|
||||
expect(switchToUnixLinebreaks(mapContent)).toMatchSnapshot();
|
||||
_a = expect;
|
||||
return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require(commonjs_testFile)); })];
|
||||
case 3:
|
||||
_a.apply(void 0, [_b.sent()]).toBeDefined();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
test('and render correctly', function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var content;
|
||||
var _a;
|
||||
return __generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0: return [4 /*yield*/, renderer_1.renderTemplate(commonjs_testFile, { asyncapi: {}, originalAsyncAPI: "", params: {} })];
|
||||
case 1:
|
||||
content = _b.sent();
|
||||
expect((_a = content) === null || _a === void 0 ? void 0 : _a.content).toBe("hello Test");
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
});
|
||||
});
|
||||
describe('should transpile ES5 files', function () {
|
||||
describe('with a simple setup', function () {
|
||||
var es5_testFile = path_1.default.resolve(outputFiles, './ES5/simple.js');
|
||||
var es5_testFileMap = path_1.default.resolve(outputFiles, './ES5/simple.js.map');
|
||||
test('and import correctly', function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var content, mapContent, _a;
|
||||
return __generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0: return [4 /*yield*/, readFile(es5_testFile, 'utf8')];
|
||||
case 1:
|
||||
content = _b.sent();
|
||||
expect(switchToUnixLinebreaks(content)).toMatchSnapshot();
|
||||
return [4 /*yield*/, readFile(es5_testFileMap, 'utf8')];
|
||||
case 2:
|
||||
mapContent = _b.sent();
|
||||
expect(switchToUnixLinebreaks(mapContent)).toMatchSnapshot();
|
||||
_a = expect;
|
||||
return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require(es5_testFile)); })];
|
||||
case 3:
|
||||
_a.apply(void 0, [_b.sent()]).toBeDefined();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
test('and render correctly', function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var content;
|
||||
var _a;
|
||||
return __generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0: return [4 /*yield*/, renderer_1.renderTemplate(es5_testFile, { asyncapi: {}, originalAsyncAPI: "", params: {} })];
|
||||
case 1:
|
||||
content = _b.sent();
|
||||
expect((_a = content) === null || _a === void 0 ? void 0 : _a.content).toBe("hello Test");
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
});
|
||||
});
|
||||
describe('should transpile ES6 files', function () {
|
||||
describe('with a simple setup', function () {
|
||||
var es6_testFile = path_1.default.resolve(outputFiles, './ES6/simple.js');
|
||||
var es6_testFileMap = path_1.default.resolve(outputFiles, './ES6/simple.js.map');
|
||||
test('and import correctly', function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var content, mapContent, _a;
|
||||
return __generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0: return [4 /*yield*/, readFile(es6_testFile, 'utf8')];
|
||||
case 1:
|
||||
content = _b.sent();
|
||||
expect(switchToUnixLinebreaks(content)).toMatchSnapshot();
|
||||
return [4 /*yield*/, readFile(es6_testFileMap, 'utf8')];
|
||||
case 2:
|
||||
mapContent = _b.sent();
|
||||
expect(switchToUnixLinebreaks(mapContent)).toMatchSnapshot();
|
||||
_a = expect;
|
||||
return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require(es6_testFile)); })];
|
||||
case 3:
|
||||
_a.apply(void 0, [_b.sent()]).toBeDefined();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
test('and render correctly', function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var content;
|
||||
var _a;
|
||||
return __generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0: return [4 /*yield*/, renderer_1.renderTemplate(es6_testFile, { asyncapi: {}, originalAsyncAPI: "", params: {} })];
|
||||
case 1:
|
||||
content = _b.sent();
|
||||
expect((_a = content) === null || _a === void 0 ? void 0 : _a.content).toBe("hello Test");
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
});
|
||||
});
|
||||
describe('should keep names of files, even if special chars', function () {
|
||||
describe('with a simple setup', function () {
|
||||
var special_testFile = path_1.default.resolve(outputFiles, './SpecialChars/$$simple$$.js');
|
||||
var special_testFileMap = path_1.default.resolve(outputFiles, './SpecialChars/$$simple$$.js.map');
|
||||
test('and import correctly', function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var content, mapContent, _a;
|
||||
return __generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0: return [4 /*yield*/, readFile(special_testFile, 'utf8')];
|
||||
case 1:
|
||||
content = _b.sent();
|
||||
expect(switchToUnixLinebreaks(content)).toMatchSnapshot();
|
||||
return [4 /*yield*/, readFile(special_testFileMap, 'utf8')];
|
||||
case 2:
|
||||
mapContent = _b.sent();
|
||||
expect(switchToUnixLinebreaks(mapContent)).toMatchSnapshot();
|
||||
_a = expect;
|
||||
return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require(special_testFile)); })];
|
||||
case 3:
|
||||
_a.apply(void 0, [_b.sent()]).toBeDefined();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
test('and render correctly', function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var content;
|
||||
var _a;
|
||||
return __generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0: return [4 /*yield*/, renderer_1.renderTemplate(special_testFile, { asyncapi: {}, originalAsyncAPI: "", params: {} })];
|
||||
case 1:
|
||||
content = _b.sent();
|
||||
expect((_a = content) === null || _a === void 0 ? void 0 : _a.content).toBe("hello Test");
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
});
|
||||
});
|
||||
});
|
||||
/*
|
||||
It is a helper required for snapshot testing on windows. It can't be solved by editor configuration and the end line setting because snapshots are generated not created in the editor.
|
||||
We need to remove `\r` from files transpiled on windows before we can match them with the snapshot generated on unix
|
||||
*/
|
||||
function switchToUnixLinebreaks(str) {
|
||||
return str.replace(/\\r/g, "");
|
||||
}
|
||||
//# sourceMappingURL=transpiler.spec.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"transpiler.spec.js","sourceRoot":"","sources":["../../../src/transpiler/__tests__/transpiler.spec.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAAoB;AACpB,8CAAwB;AACxB,6BAAiC;AAGjC,4CAA+C;AAC/C,2CAAgD;AAGhD,IAAM,QAAQ,GAAG,gBAAS,CAAC,YAAE,CAAC,QAAQ,CAAC,CAAC;AAExC,QAAQ,CAAC,YAAY,EAAE;IACrB,IAAM,SAAS,GAAG,cAAI,CAAC,OAAO,CAAC,SAAS,E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ated
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
__exportStar(require("./transpiler"), exports);
|
||||
//# sourceMappingURL=index.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/transpiler/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+CAA6B"}
|
||||
Generated
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
import { TranspileFilesOptions } from '../types';
|
||||
/**
|
||||
* Transpile files in a given directory (and sub directory if recursive option are passed) and write it to an output directory, if no errors are thrown it completed successfully.
|
||||
*
|
||||
* @param directory to transpile.
|
||||
* @param outputDir to write the transpiled files to.
|
||||
* @param options any extra options that should be passed.
|
||||
*/
|
||||
export declare function transpileFiles(directory: string, outputDir: string, options?: TranspileFilesOptions): Promise<void>;
|
||||
Generated
Vendored
+121
@@ -0,0 +1,121 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.transpileFiles = void 0;
|
||||
var path_1 = __importDefault(require("path"));
|
||||
var rollup_1 = require("rollup");
|
||||
var plugin_babel_1 = __importDefault(require("@rollup/plugin-babel"));
|
||||
var utils_1 = require("../utils");
|
||||
var ROOT_DIR = path_1.default.resolve(__dirname, '../..');
|
||||
/**
|
||||
* Transpile files in a given directory (and sub directory if recursive option are passed) and write it to an output directory, if no errors are thrown it completed successfully.
|
||||
*
|
||||
* @param directory to transpile.
|
||||
* @param outputDir to write the transpiled files to.
|
||||
* @param options any extra options that should be passed.
|
||||
*/
|
||||
function transpileFiles(directory, outputDir, options) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var _a, files, dirs, bundles, _i, dirs_1, subdir, subdirPath;
|
||||
return __generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0: return [4 /*yield*/, utils_1.getStatsInDir(directory)];
|
||||
case 1:
|
||||
_a = _b.sent(), files = _a.files, dirs = _a.dirs;
|
||||
if (!files.length) return [3 /*break*/, 4];
|
||||
return [4 /*yield*/, rollup_1.rollup({
|
||||
input: files,
|
||||
onwarn: function () { },
|
||||
plugins: [
|
||||
plugin_babel_1.default({
|
||||
cwd: ROOT_DIR,
|
||||
babelHelpers: "bundled",
|
||||
plugins: [
|
||||
"source-map-support",
|
||||
],
|
||||
presets: [
|
||||
["@babel/preset-env", {
|
||||
targets: { node: "12.16" },
|
||||
}],
|
||||
["@babel/preset-react", {
|
||||
runtime: "automatic",
|
||||
}],
|
||||
],
|
||||
})
|
||||
],
|
||||
})];
|
||||
case 2:
|
||||
bundles = _b.sent();
|
||||
return [4 /*yield*/, bundles.write({
|
||||
format: "commonjs",
|
||||
sourcemap: true,
|
||||
dir: outputDir,
|
||||
exports: "auto",
|
||||
paths: {
|
||||
'react/jsx-runtime': 'react/cjs/react-jsx-runtime.production.min',
|
||||
},
|
||||
sanitizeFileName: false,
|
||||
})];
|
||||
case 3:
|
||||
_b.sent();
|
||||
_b.label = 4;
|
||||
case 4:
|
||||
if (!((options === null || options === void 0 ? void 0 : options.recursive) === true && dirs.length > 0)) return [3 /*break*/, 8];
|
||||
_i = 0, dirs_1 = dirs;
|
||||
_b.label = 5;
|
||||
case 5:
|
||||
if (!(_i < dirs_1.length)) return [3 /*break*/, 8];
|
||||
subdir = dirs_1[_i];
|
||||
subdirPath = path_1.default.parse(subdir);
|
||||
return [4 /*yield*/, transpileFiles(subdir, path_1.default.resolve(outputDir, subdirPath.base), options)];
|
||||
case 6:
|
||||
_b.sent();
|
||||
_b.label = 7;
|
||||
case 7:
|
||||
_i++;
|
||||
return [3 /*break*/, 5];
|
||||
case 8: return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.transpileFiles = transpileFiles;
|
||||
//# sourceMappingURL=transpiler.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"transpiler.js","sourceRoot":"","sources":["../../src/transpiler/transpiler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAAwB;AAExB,iCAAgC;AAChC,sEAAyC;AAEzC,kCAAyC;AAGzC,IAAM,QAAQ,GAAG,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;AAElD;;;;;;GAMG;AACH,SAAsB,cAAc,CAAC,SAAiB,EAAE,SAAiB,EAAE,OAA+B;;;;;wBAC9E,qBAAM,qBAAa,CAAC,SAAS,CAAC,EAAA;;oBAAhD,KAAkB,SAA8B,EAA9C,KAAK,WAAA,EAAE,IAAI,UAAA;yBACf,KAAK,CAAC,MAAM,EAAZ,wBAAY;oBAQI,qBAAM,eAAM,CAAC;4BACzB,KAAK,EAAE,KAAK;4BACZ,MAAM,EAAE,cAAO,CAAC;4BAChB,OAAO,EAAE;gCACL,sBAAK,CAAC;oCACF,GAAG,EAAE,QAAQ;oCACb,YAAY,EAAE,SAAS;oCACvB,OAAO,EAAE;wCACL,oBAAoB;qCACvB;oCACD,OAAO,EAAE;wCACL,CAAC,mBAAmB,EAAE;gDAClB,OAAO,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;6CAC7B,CAAC;wCACF,CAAC,qBAAqB,EAAE;gDACpB,OAAO,EAAE,WAAW;6CACvB,CAAC;qCACL;iCACJ,CAAC;6BACL;yBACJ,CAAC,EAAA;;oBApBI,OAAO,GAAG,SAoBd;oBACF,qBAAM,OAAO,CAAC,KAAK,CAAC;4BAChB,MAAM,EAAE,UAAU;4BAClB,SAAS,EAAE,IAAI;4BACf,GAAG,EAAE,SAAS;4BACd,OAAO,EAAE,MAAM;4BACf,KAAK,EAAE;gCACL,mBAAmB,EAAE,4CAA4C;6BAClE;4BACD,gBAAgB,EAAE,KAAK;yBAC1B,CAAC,EAAA;;oBATF,SASE,CAAA;;;yBAIF,CAAA,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,MAAK,IAAI,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,CAAA,EAA9C,wBAA8C;0BACrB,EAAJ,aAAI;;;yBAAJ,CAAA,kBAAI,CAAA;oBAAd,MAAM;oBACP,UAAU,GAAG,cAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;oBACtC,qBAAM,cAAc,CAAC,MAAM,EAAE,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,UAAU,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,EAAA;;oBAA/E,SAA+E,CAAC;;;oBAF/D,IAAI,CAAA;;;;;;CAKhC;AAlDD,wCAkDC"}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
import React from "react";
|
||||
import { AsyncAPIDocument } from "@asyncapi/parser";
|
||||
export declare type PropsWithChildrenContent<P> = P & {
|
||||
childrenContent?: string;
|
||||
};
|
||||
export declare type FC<P = {}> = FunctionComponent<P>;
|
||||
export declare type FunctionComponent<P = {}> = React.FunctionComponent<PropsWithChildrenContent<P>>;
|
||||
export declare class Component<P = {}> extends React.Component<PropsWithChildrenContent<P>> {
|
||||
}
|
||||
/**
|
||||
* Shape of the context passed to template
|
||||
*/
|
||||
export interface TemplateContext<P = Record<string, any>> {
|
||||
asyncapi: AsyncAPIDocument;
|
||||
params: P;
|
||||
originalAsyncAPI: string;
|
||||
[key: string]: any;
|
||||
}
|
||||
/**
|
||||
* Signature for template function
|
||||
*/
|
||||
export declare type TemplateFunction<R = React.ReactElement | undefined> = (context: TemplateContext) => R | Promise<R>;
|
||||
/**
|
||||
* Options for transpiling files.
|
||||
*/
|
||||
export declare type TranspileFilesOptions = {
|
||||
/**
|
||||
* Should all files in a directory including those in subdirectories be included
|
||||
*/
|
||||
recursive?: boolean;
|
||||
};
|
||||
export declare type TemplateRenderMetadata = {
|
||||
fileName?: string;
|
||||
permissions?: string;
|
||||
};
|
||||
export declare type TemplateRenderResult = {
|
||||
metadata: TemplateRenderMetadata;
|
||||
content: string;
|
||||
};
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Component = void 0;
|
||||
var react_1 = __importDefault(require("react"));
|
||||
var Component = /** @class */ (function (_super) {
|
||||
__extends(Component, _super);
|
||||
function Component() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
return Component;
|
||||
}(react_1.default.Component));
|
||||
exports.Component = Component;
|
||||
//# sourceMappingURL=types.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,gDAA0B;AAS1B;IAAuC,6BAA4C;IAAnF;;IAAqF,CAAC;IAAD,gBAAC;AAAD,CAAC,AAAtF,CAAuC,eAAK,CAAC,SAAS,GAAgC;AAAzE,8BAAS"}
|
||||
Generated
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
declare class GetFilesResponse {
|
||||
files: string[];
|
||||
dirs: string[];
|
||||
constructor(files: string[], dirs: string[]);
|
||||
}
|
||||
/**
|
||||
* Function which finds all the files and dirs in folders
|
||||
* @private
|
||||
* @param dir directory to find files and dirs in.
|
||||
* @param includeSubDirs should the function iterate through subdirectories to search for files and dirs?
|
||||
*/
|
||||
export declare function getStatsInDir(dir: string): Promise<GetFilesResponse>;
|
||||
export {};
|
||||
Generated
Vendored
+103
@@ -0,0 +1,103 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getStatsInDir = void 0;
|
||||
var path_1 = __importDefault(require("path"));
|
||||
var fs_1 = __importDefault(require("fs"));
|
||||
var util_1 = require("util");
|
||||
var _1 = require(".");
|
||||
var readdir = util_1.promisify(fs_1.default.readdir);
|
||||
var stat = util_1.promisify(fs_1.default.stat);
|
||||
var GetFilesResponse = /** @class */ (function () {
|
||||
function GetFilesResponse(files, dirs) {
|
||||
this.files = files;
|
||||
this.dirs = dirs;
|
||||
}
|
||||
return GetFilesResponse;
|
||||
}());
|
||||
/**
|
||||
* Function which finds all the files and dirs in folders
|
||||
* @private
|
||||
* @param dir directory to find files and dirs in.
|
||||
* @param includeSubDirs should the function iterate through subdirectories to search for files and dirs?
|
||||
*/
|
||||
function getStatsInDir(dir) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var allFiles, files, dirs, _i, allFiles_1, filename, res, stats, resolveFilenameCallback;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, readdir(dir)];
|
||||
case 1:
|
||||
allFiles = _a.sent();
|
||||
files = [];
|
||||
dirs = [];
|
||||
_i = 0, allFiles_1 = allFiles;
|
||||
_a.label = 2;
|
||||
case 2:
|
||||
if (!(_i < allFiles_1.length)) return [3 /*break*/, 5];
|
||||
filename = allFiles_1[_i];
|
||||
res = path_1.default.resolve(dir, filename);
|
||||
return [4 /*yield*/, stat(res)];
|
||||
case 3:
|
||||
stats = _a.sent();
|
||||
if (stats.isDirectory()) {
|
||||
dirs.push(res);
|
||||
}
|
||||
else if (_1.isJsFile(filename)) {
|
||||
files.push(res);
|
||||
}
|
||||
_a.label = 4;
|
||||
case 4:
|
||||
_i++;
|
||||
return [3 /*break*/, 2];
|
||||
case 5:
|
||||
resolveFilenameCallback = function (filename) {
|
||||
return path_1.default.resolve(dir, filename);
|
||||
};
|
||||
files = files.map(resolveFilenameCallback);
|
||||
dirs = dirs.map(resolveFilenameCallback);
|
||||
return [2 /*return*/, new GetFilesResponse(files, dirs)];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.getStatsInDir = getStatsInDir;
|
||||
//# sourceMappingURL=getStatsInDir.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"getStatsInDir.js","sourceRoot":"","sources":["../../src/utils/getStatsInDir.ts"],"names":[],"mappings":";;;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BAC3C,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;oBACzC,sBAAO,IAAI,gBAAgB,CAAC,KAAK,EAAE,IAAI,CAAC,EAAC;;;;CAC5C;AAnBD,sCAmBC"}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
export * from "./getStatsInDir";
|
||||
export * from "./isJsFile";
|
||||
export * from "./withIndendation";
|
||||
export * from "./withNewLines";
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
__exportStar(require("./getStatsInDir"), exports);
|
||||
__exportStar(require("./isJsFile"), exports);
|
||||
__exportStar(require("./withIndendation"), exports);
|
||||
__exportStar(require("./withNewLines"), exports);
|
||||
//# sourceMappingURL=index.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAAgC;AAChC,6CAA2B;AAC3B,oDAAkC;AAClC,iDAA+B"}
|
||||
Generated
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* Function which checks if file is JS file
|
||||
* @private
|
||||
* @param {string} filename
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export declare function isJsFile(filename?: string): boolean;
|
||||
Generated
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isJsFile = void 0;
|
||||
var ALLOWED_EXTS = ['js', 'jsx', 'cjs'];
|
||||
/**
|
||||
* Function which checks if file is JS file
|
||||
* @private
|
||||
* @param {string} filename
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function isJsFile(filename) {
|
||||
if (filename === void 0) { filename = ''; }
|
||||
var ext = filename.split('.').pop() || '';
|
||||
return ALLOWED_EXTS.includes(ext);
|
||||
}
|
||||
exports.isJsFile = isJsFile;
|
||||
//# sourceMappingURL=isJsFile.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"isJsFile.js","sourceRoot":"","sources":["../../src/utils/isJsFile.ts"],"names":[],"mappings":";;;AAAA,IAAM,YAAY,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;AAE1C;;;;;GAKG;AACH,SAAgB,QAAQ,CAAC,QAAqB;IAArB,yBAAA,EAAA,aAAqB;IAC5C,IAAM,GAAG,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC;IAC5C,OAAO,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;AACpC,CAAC;AAHD,4BAGC"}
|
||||
Generated
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Type of indentation to use
|
||||
* @readonly
|
||||
* @enum {string}
|
||||
* @property {string} TABS - indicate to use tabs as separator
|
||||
* @property {string} SPACES - indicate to use spaces as separator
|
||||
*/
|
||||
export declare enum IndentationTypes {
|
||||
TABS = "tabs",
|
||||
SPACES = "spaces"
|
||||
}
|
||||
/**
|
||||
* Ensures indentations are prepended to content.
|
||||
* @private
|
||||
* @param {string} content to prepend the indentation
|
||||
* @param {number} size the number of indendations to use
|
||||
* @param {IndentationTypes} type the type of indendations to use. SPACES by default.
|
||||
* @returns {string}
|
||||
*/
|
||||
export declare function withIndendation(content: string | undefined, size: number, type?: IndentationTypes): string;
|
||||
Generated
Vendored
+54
@@ -0,0 +1,54 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.withIndendation = exports.IndentationTypes = void 0;
|
||||
/**
|
||||
* Type of indentation to use
|
||||
* @readonly
|
||||
* @enum {string}
|
||||
* @property {string} TABS - indicate to use tabs as separator
|
||||
* @property {string} SPACES - indicate to use spaces as separator
|
||||
*/
|
||||
var IndentationTypes;
|
||||
(function (IndentationTypes) {
|
||||
IndentationTypes["TABS"] = "tabs";
|
||||
IndentationTypes["SPACES"] = "spaces";
|
||||
})(IndentationTypes = exports.IndentationTypes || (exports.IndentationTypes = {}));
|
||||
/**
|
||||
* Ensures indentations are prepended to content.
|
||||
* @private
|
||||
* @param {string} content to prepend the indentation
|
||||
* @param {number} size the number of indendations to use
|
||||
* @param {IndentationTypes} type the type of indendations to use. SPACES by default.
|
||||
* @returns {string}
|
||||
*/
|
||||
function withIndendation(content, size, type) {
|
||||
if (content === void 0) { content = ''; }
|
||||
if (type === void 0) { type = IndentationTypes.SPACES; }
|
||||
if (size < 1) {
|
||||
return content;
|
||||
}
|
||||
// if the content includes new lines ensure that they have the added indentation as well.
|
||||
if (content.includes('\n')) {
|
||||
var newLineArray = content.split('\n');
|
||||
return newLineArray.reduce(function (accumulator, value) {
|
||||
var newValue = value.trim() === '' ? value : "" + getIndentation(size, type) + value;
|
||||
return accumulator === "" ? newValue : accumulator + "\n" + newValue;
|
||||
}, "");
|
||||
}
|
||||
return "" + getIndentation(size, type) + content;
|
||||
}
|
||||
exports.withIndendation = withIndendation;
|
||||
/**
|
||||
* Get the indendation string based on how many and which type of indentation are requested.
|
||||
* @private
|
||||
* @param {number} size the number of indendations to use
|
||||
* @param {IndentationTypes} type the type of indendations to use. SPACES by default.
|
||||
* @returns {string}
|
||||
*/
|
||||
function getIndentation(size, type) {
|
||||
if (size === void 0) { size = 0; }
|
||||
if (type === void 0) { type = IndentationTypes.SPACES; }
|
||||
var whitespaceChar = type === IndentationTypes.SPACES ? ' ' : '\t';
|
||||
return Array(size).fill(whitespaceChar).join("");
|
||||
}
|
||||
//# sourceMappingURL=withIndendation.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"withIndendation.js","sourceRoot":"","sources":["../../src/utils/withIndendation.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,IAAY,gBAGX;AAHD,WAAY,gBAAgB;IAC1B,iCAAa,CAAA;IACb,qCAAiB,CAAA;AACnB,CAAC,EAHW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAG3B;AAED;;;;;;;GAOG;AACH,SAAgB,eAAe,CAAC,OAAoB,EAAE,IAAY,EAAE,IAAgD;IAApF,wBAAA,EAAA,YAAoB;IAAgB,qBAAA,EAAA,OAAyB,gBAAgB,CAAC,MAAM;IAClH,IAAI,IAAI,GAAG,CAAC,EAAE;QACZ,OAAO,OAAO,CAAC;KAChB;IAED,yFAAyF;IACzF,IAAI,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;QAC1B,IAAM,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACzC,OAAO,YAAY,CAAC,MAAM,CAAC,UAAC,WAAW,EAAE,KAAK;YAC5C,IAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAG,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,KAAO,CAAC;YACvF,OAAO,WAAW,KAAK,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAI,WAAW,UAAK,QAAU,CAAC;QACvE,CAAC,EAAE,EAAE,CAAC,CAAC;KACR;IACD,OAAO,KAAG,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,OAAS,CAAC;AACnD,CAAC;AAdD,0CAcC;AAED;;;;;;GAMG;AACH,SAAS,cAAc,CAAC,IAAgB,EAAE,IAAgD;IAAlE,qBAAA,EAAA,QAAgB;IAAE,qBAAA,EAAA,OAAyB,gBAAgB,CAAC,MAAM;IACxF,IAAM,cAAc,GAAG,IAAI,KAAK,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;IACrE,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACnD,CAAC"}
|
||||
Generated
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Prepend given number of the new lines to content.
|
||||
* @private
|
||||
* @param {string} content
|
||||
* @param {number} number
|
||||
* @returns {string}
|
||||
*/
|
||||
export declare function withNewLines(content?: string, number?: number): string;
|
||||
Generated
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.withNewLines = void 0;
|
||||
/**
|
||||
* Prepend given number of the new lines to content.
|
||||
* @private
|
||||
* @param {string} content
|
||||
* @param {number} number
|
||||
* @returns {string}
|
||||
*/
|
||||
function withNewLines(content, number) {
|
||||
if (content === void 0) { content = ''; }
|
||||
if (number === void 0) { number = 0; }
|
||||
var newLines = Array(number).fill('\n').join('');
|
||||
return content + newLines;
|
||||
}
|
||||
exports.withNewLines = withNewLines;
|
||||
//# sourceMappingURL=withNewLines.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"withNewLines.js","sourceRoot":"","sources":["../../src/utils/withNewLines.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,SAAgB,YAAY,CAAC,OAAoB,EAAE,MAAkB;IAAxC,wBAAA,EAAA,YAAoB;IAAE,uBAAA,EAAA,UAAkB;IACnE,IAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACnD,OAAO,OAAO,GAAG,QAAQ,CAAC;AAC5B,CAAC;AAHD,oCAGC"}
|
||||
Reference in New Issue
Block a user