How to use code-block-writer - 10 common examples

To help you get started, we’ve selected a few code-block-writer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dsherret / ts-morph / code-generation / createFillNodeFromMixinStructuresFunctions.ts View on Github external
export function createFillNodeFromMixinStructuresFunctions(opts: Options) {
    const {classVMs, fillOnlyFunctionVMs, overloadStructureVMs} = opts;
    classVMs.forEach(c => removeNotAllowedMixins(c));

    const writer = new CodeBlockWriter();
    const mixinsOfMixins = getMixinsOfMixins(classVMs);

    writer.writeLine("/* tslint:disable */");
    writer.writeLine("// DO NOT MANUALLY EDIT!! File generated via: npm run code-generate").newLine();
    writer.writeLine(`import * as compiler from "./../compiler";`);
    writer.writeLine(`import * as structures from "./../structures";`);
    writer.writeLine(`import * as fillFuncs from "./fillMixinFunctions";`);
    writer.writeLine(`import * as fillOnlyFuncs from "./fillOnlyFunctions";`);

    for (const vm of [...classVMs.filter(c => isAllowedClass(c) && c.mixins.length > 0), ...mixinsOfMixins.filter(m => m.mixins.length > 0)]) {
        writer.newLine();
        write(writer, vm, fillOnlyFunctionVMs);
    }

    for (const vm of overloadStructureVMs) {
        writer.newLine();
github wane / wane / src / compiler / codegen / codegen.ts View on Github external
private generateMainJsFile (): CodeBlockWriter {
    const writer = new CodeBlockWriter(this.writerOptions)
    writer
      .writeLine(`import app from './bootstrap'`)
      .writeLine(`app.__wane__init()`)
    return writer
  }
github wane / wane / src / integration / view-bindings.spec.ts View on Github external
it(`prints an empty string for {{ greeting }} and {{ someone }} because it is already initialized when dom is created`, () => {
        const wr = new CodeBlockWriter()
        greeting.printInit(wr, greeting.getResponsibleFactory())
        expect(wr.toString()).toBe(``)
        const wr2 = new CodeBlockWriter()
        someone.printInit(wr, greeting.getResponsibleFactory())
        expect(wr2.toString()).toBe(``)
      })
    })
github wane / wane / src / integration / factory-analyzer.spec.ts View on Github external
it(`prints assembling logic`, () => {
          const string = stripIndent`
            util.__wane__appendChildren(this.__wane__root, [
              util.__wane__appendChildren(this.__wane__domNodes[0], [
              ])
              util.__wane__appendChildren(this.__wane__domNodes[1], [
              ])
              util.__wane__appendChildren(this.__wane__domNodes[2], [
              ])
              util.__wane__appendChildren(this.__wane__domNodes[3], [
              ])
              util.__wane__appendChildren(this.__wane__domNodes[4], [
              ])
            ])
          `
          const wr = new CodeBlockWriter({ indentNumberOfSpaces: 2 })
          app.printAssemblingDomNodes(wr)
          expect((stripIndent as any)(wr.toString())).toEqual(string)
        })
      })
github dsherret / ts-type-info / src / factories / MainFactory.ts View on Github external
static createWriter(writeOptions: WriteOptions | undefined) {
        return new CodeBlockWriter(writeOptions);
    }
github wane / wane / src / integration / factory-analyzer.spec.ts View on Github external
function expectWriter (spy: (wr: CodeBlockWriter) => void, expectation: string): void {
  const wr = new CodeBlockWriter({ indentNumberOfSpaces: 2 })
  spy(wr)
  expect(wr.toString().trim()).toBe(expectation.trim())
}
github dsherret / ts-morph / src / utils / getCodeBlockWriter.ts View on Github external
export function getCodeBlockWriter(manipulationSettings: ManipulationSettingsContainer) {
    const indentationText = manipulationSettings.getIndentationText();
    return new CodeBlockWriter({
        newLine: manipulationSettings.getNewLineKindAsString(),
        indentNumberOfSpaces: indentationText === IndentationText.Tab ? undefined : indentationText.length,
        useTabs: indentationText === IndentationText.Tab,
        useSingleQuote: manipulationSettings.getQuoteType() === QuoteType.Single
    });
}
github dsherret / server-bridge / src / code-generator / get-code-from-classes.ts View on Github external
export function getCodeFromClasses(options: Options) {
    const importWriter = new CodeBlockWriter();
    const writer = new CodeBlockWriter();
    const types = new TypesDictionary();
    const {libraryName, classes, importMapping} = options;

    classes.forEach((c, classIndex) => {
        if (classIndex > 0) {
            writer.newLine();
        }

        const classWriter = new ClassWriter(c, types, options.classMapping[c.name] || c.name);
        classWriter.writeToWriter(writer);
    });

    importWriter.writeLine(`import {${CLIENT_BASE_NAME}} from "${libraryName}";`);

    Object.keys(types.getTypes()).forEach(typeName => {
github dsherret / server-bridge / dist / code-generator / get-code-from-classes.js View on Github external
function getCodeFromClasses(options) {
    var importWriter = new code_block_writer_1.default();
    var writer = new code_block_writer_1.default();
    var types = new types_dictionary_1.TypesDictionary();
    var libraryName = options.libraryName, classes = options.classes, importMapping = options.importMapping;
    classes.forEach(function (c, classIndex) {
        if (classIndex > 0) {
            writer.newLine();
        }
        var classWriter = new class_writer_1.ClassWriter(c, types, options.classMapping[c.name] || c.name);
        classWriter.writeToWriter(writer);
    });
    importWriter.writeLine("import {" + CLIENT_BASE_NAME + "} from \"" + libraryName + "\";");
    Object.keys(types.getTypes()).forEach(function (typeName) {
        if (typeName === CLIENT_BASE_NAME) {
            throw new Error("Having a type with the name ClientBase is currently not supported. Please use a different type name.");
        }
        else if (importMapping[typeName] == null) {
github dsherret / server-bridge / dist / code-generator / get-code-from-classes.js View on Github external
function getCodeFromClasses(options) {
    var importWriter = new code_block_writer_1.default();
    var writer = new code_block_writer_1.default();
    var types = new types_dictionary_1.TypesDictionary();
    var libraryName = options.libraryName, classes = options.classes, importMapping = options.importMapping;
    classes.forEach(function (c, classIndex) {
        if (classIndex > 0) {
            writer.newLine();
        }
        var classWriter = new class_writer_1.ClassWriter(c, types, options.classMapping[c.name] || c.name);
        classWriter.writeToWriter(writer);
    });
    importWriter.writeLine("import {" + CLIENT_BASE_NAME + "} from \"" + libraryName + "\";");
    Object.keys(types.getTypes()).forEach(function (typeName) {
        if (typeName === CLIENT_BASE_NAME) {
            throw new Error("Having a type with the name ClientBase is currently not supported. Please use a different type name.");
        }
        else if (importMapping[typeName] == null) {
            throw new Error("An import mapping needs to be specified on the options parameter for '" + typeName + "' when calling getGeneratedCode()");

code-block-writer

A simple code writer that assists with formatting and visualizing blocks of code.

MIT
Latest version published 3 months ago

Package Health Score

80 / 100
Full package analysis

Popular code-block-writer functions