@basketry/sorbet
Advanced tools
Comparing version 0.0.15 to 0.0.16
@@ -8,2 +8,3 @@ "use strict"; | ||
const name_factory_1 = require("./name-factory"); | ||
const utils_1 = require("./utils"); | ||
const warning_1 = require("./warning"); | ||
@@ -82,3 +83,3 @@ const generateTypes = (service, options) => { | ||
yield* this.comment(int.description); | ||
yield* block(`module ${(0, name_factory_1.buildInterfaceNamespace)(this.service, this.options)}`, block(`module ${(0, name_factory_1.buildInterfaceName)(int)}`, function* () { | ||
yield* (0, utils_1.block)(`module ${(0, name_factory_1.buildInterfaceNamespace)(this.service, this.options)}`, (0, utils_1.block)(`module ${(0, name_factory_1.buildInterfaceName)(int)}`, function* () { | ||
yield 'extend T::Sig'; | ||
@@ -106,7 +107,7 @@ yield 'extend T::Helpers'; | ||
if (method.parameters.length) { | ||
yield* block('sig do', function* () { | ||
yield* (0, utils_1.block)('sig do', function* () { | ||
yield 'abstract.params('; | ||
yield* self.buildSignatureParameters(method); | ||
yield `).returns(`; | ||
yield* indent(typeName); | ||
yield* (0, utils_1.indent)(typeName); | ||
yield `)`; | ||
@@ -121,3 +122,3 @@ }); | ||
if (method.parameters.length) { | ||
yield* block('sig do', function* () { | ||
yield* (0, utils_1.block)('sig do', function* () { | ||
yield 'abstract.params('; | ||
@@ -134,3 +135,3 @@ yield* self.buildSignatureParameters(method); | ||
*buildSignatureParameters(method) { | ||
yield* indent(sortParameters(method.parameters).map((param, i) => { | ||
yield* (0, utils_1.indent)(sortParameters(method.parameters).map((param, i) => { | ||
const comma = i === method.parameters.length - 1 ? '' : ','; | ||
@@ -154,3 +155,3 @@ const typeName = (0, name_factory_1.buildTypeName)({ | ||
: ''; | ||
yield* block(`def ${(0, name_factory_1.buildMethodName)(method)}${parameters}`, []); | ||
yield* (0, utils_1.block)(`def ${(0, name_factory_1.buildMethodName)(method)}${parameters}`, []); | ||
} | ||
@@ -177,5 +178,5 @@ buildTypeFile(type) { | ||
} | ||
yield* block(`module ${(0, name_factory_1.buildTypeNamespace)(this.service, this.options)}`, function* () { | ||
yield* (0, utils_1.block)(`module ${(0, name_factory_1.buildTypeNamespace)(this.service, this.options)}`, function* () { | ||
yield* self.comment(type.description); | ||
yield* block(`class ${(0, case_1.pascal)(type.name.value)} < T::Struct`, function* () { | ||
yield* (0, utils_1.block)(`class ${(0, case_1.pascal)(type.name.value)} < T::Struct`, function* () { | ||
let isFirst = true; | ||
@@ -217,3 +218,3 @@ for (const property of type.properties) { | ||
} | ||
yield* block(`module ${(0, name_factory_1.buildEnumNamespace)(this.service, this.options)}`, block(`class ${(0, case_1.pascal)(e.name.value)} < T::Enum`, block(`enums do`, function* () { | ||
yield* (0, utils_1.block)(`module ${(0, name_factory_1.buildEnumNamespace)(this.service, this.options)}`, (0, utils_1.block)(`class ${(0, case_1.pascal)(e.name.value)} < T::Enum`, (0, utils_1.block)(`enums do`, function* () { | ||
for (const value of e.values) { | ||
@@ -245,4 +246,4 @@ yield `${(0, case_1.constant)(value.value)} = new('${(0, case_1.snake)(value.value)}')`; | ||
const versionedModule = (0, _1.buildServiceLocatorNamespace)(this.service, this.options); | ||
yield* block(`module ${versionedModule}`, function* () { | ||
yield* block(`module ${(0, _1.buildServiceLocatorName)()}`, function* () { | ||
yield* (0, utils_1.block)(`module ${versionedModule}`, function* () { | ||
yield* (0, utils_1.block)(`module ${(0, _1.buildServiceLocatorName)()}`, function* () { | ||
yield `extend T::Sig`; | ||
@@ -267,4 +268,4 @@ yield `extend T::Helpers`; | ||
yield ''; | ||
yield* comment(function* () { | ||
yield* block(`class TemplateServiceLocator`, function* () { | ||
yield* (0, utils_1.comment)(function* () { | ||
yield* (0, utils_1.block)(`class TemplateServiceLocator`, function* () { | ||
yield `extend T::Sig`; | ||
@@ -278,3 +279,3 @@ yield ''; | ||
yield `def ${(0, case_1.snake)(interfaceName)}`; | ||
yield* indent(`raise NotImplementedError`); | ||
yield* (0, utils_1.indent)(`raise NotImplementedError`); | ||
yield 'end'; | ||
@@ -293,30 +294,2 @@ } | ||
} | ||
let indentCount = 0; | ||
function* block(line, body) { | ||
yield line; | ||
yield* indent(body); | ||
yield 'end'; | ||
} | ||
function* indent(lines) { | ||
try { | ||
indentCount++; | ||
for (const line of typeof lines === 'function' | ||
? lines() | ||
: typeof lines === 'string' | ||
? [lines] | ||
: lines) { | ||
yield line.trim().length | ||
? `${' '.repeat(indentCount)}${line.trim()}` | ||
: ''; | ||
} | ||
} | ||
finally { | ||
indentCount--; | ||
} | ||
} | ||
function* comment(lines) { | ||
for (const line of typeof lines === 'function' ? lines() : lines) { | ||
yield line.length ? `# ${line}` : '#'; | ||
} | ||
} | ||
//# sourceMappingURL=interface-factory.js.map |
@@ -5,6 +5,5 @@ "use strict"; | ||
const basketry_1 = require("basketry"); | ||
const warning = (service, pkg, options) => Array.from((0, basketry_1.warning)(service, pkg, options || {})) | ||
.map((x) => `# ${x}`.trim()) | ||
.join('\n'); | ||
const utils_1 = require("./utils"); | ||
const warning = (service, pkg, options) => (0, utils_1.from)((0, utils_1.comment)((0, basketry_1.warning)(service, pkg, options || {}))); | ||
exports.warning = warning; | ||
//# sourceMappingURL=warning.js.map |
{ | ||
"name": "@basketry/sorbet", | ||
"version": "0.0.15", | ||
"version": "0.0.16", | ||
"description": "Basketry generator for generating Sorbet types and interfaces", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
53477
24
580