本文整理汇总了TypeScript中fs.WriteStream.write方法的典型用法代码示例。如果您正苦于以下问题:TypeScript WriteStream.write方法的具体用法?TypeScript WriteStream.write怎么用?TypeScript WriteStream.write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fs.WriteStream
的用法示例。
在下文中一共展示了WriteStream.write方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: tsTypeToString
_.forEach(interf.properties, (prop) => {
var typename = tsTypeToString(prop.tsType, prop.option.associated !== null);
if (prop.option.associated === null) {
stream.write(` ${prop.name}?: ${typename};\n`);
}
else {
stream.write(` ${prop.name}Id?: number;\n`);
}
});
示例2: switch
_.forEach(interf.relationships, (rel) => {
const capitalizedName = _.upperFirst(rel.name);
const typeName = rel.targetName + "Interface";
switch(rel.type) {
case RelationshipType.OneToMany:
stream.write(`
get${capitalizedName}(): Promise<${typeName}[]>;
set${capitalizedName}(vals: ${typeName}[]): Promise<${typeName}[]>;
remove${capitalizedName}(val: ${typeName}): Promise<void>;
add${capitalizedName}(val: ${typeName}): Promise<void>;`);
break;
case RelationshipType.ManyToOne:
stream.write(`
get${capitalizedName}(): Promise<${typeName}>;
set${capitalizedName}(vals: ${typeName}): Promise<${typeName}>;`);
break;
}
});
示例3: relative
_.forEach(info.imports, (items: string[], moduleName: string) => {
if (moduleName[0] === ".") {
moduleName = relative(writeInfo.outDir,
join(dirname(writeInfo.srcPath), moduleName))
.replace(new RegExp("\\\\", "g"), "/");
}
const joinedItems = _.uniq(items).join(", ");
stream.write(`import { ${joinedItems} } from '${moduleName}';\n`);
});
示例4: writeInterface
function writeInterface(stream: WriteStream, interf: Interface, name: string) {
stream.write(`export interface ${name}Interface {\n`);
if (!interf.hasPrimaryKey) {
stream.write(` id?: number; // auto generated property\n`);
}
if (interf.createdAt) {
stream.write(` ${interf.createdAt}?: Date; // auto generated property\n`);
}
if (interf.updatedAt) {
stream.write(` ${interf.updatedAt}?: Date; // auto generated property\n`);
}
_.forEach(interf.properties, (prop) => {
var typename = tsTypeToString(prop.tsType, prop.option.associated !== null);
if (prop.option.associated === null) {
stream.write(` ${prop.name}?: ${typename};\n`);
}
else {
stream.write(` ${prop.name}Id?: number;\n`);
}
});
stream.write("}\n\n");
}
示例5: writeModelDef
function writeModelDef(stream: WriteStream, interf: Interface, name: string) {
stream.write(`export interface ${name}Instance extends sequelize.Instance<${name}Interface>, ${name}Interface {`);
_.forEach(interf.relationships, (rel) => {
const capitalizedName = _.upperFirst(rel.name);
const typeName = rel.targetName + "Interface";
switch(rel.type) {
case RelationshipType.OneToMany:
stream.write(`
get${capitalizedName}(): Promise<${typeName}[]>;
set${capitalizedName}(vals: ${typeName}[]): Promise<${typeName}[]>;
remove${capitalizedName}(val: ${typeName}): Promise<void>;
add${capitalizedName}(val: ${typeName}): Promise<void>;`);
break;
case RelationshipType.ManyToOne:
stream.write(`
get${capitalizedName}(): Promise<${typeName}>;
set${capitalizedName}(vals: ${typeName}): Promise<${typeName}>;`);
break;
}
});
stream.write("\n}\n\n");
stream.write(`interface ${name}Model extends sequelize.Model<${name}Instance, ${name}Interface> {}\n\n`);
stream.write(`var ${name}Initialized: boolean = false;\n`);
stream.write(`export var ${name}: ${name}Model;\n`);
stream.write(`export function init${name}(seq: sequelize.Sequelize): ${name}Model {
if (${name}Initialized) {
return ${name};
}
`);
stream.write(` ${name} = <${name}Model>seq.define<${name}Instance, ${name}Interface>('${name}', {\n`);
stream.write(
_.filter(_.map(interf.properties, (prop) => makeProperty(prop))).join(",\n"));
stream.write(" }, {");
stream.write("\n");
stream.write(" indexes: [\n");
stream.write(
_.map(interf.indexes, (index) => {
const fields = index.fields.map((d) => `"${d}"`).join(", ");
return ` {
fields: [${fields}]
}`;
}).join(",\n")
);
stream.write(" ]");
stream.write(" });\n");
_.forEach(interf.relationships, (rel) => {
let moduleName = "";
if (rel.targetModule != undefined) {
moduleName = `require('${rel.targetModule}_models').`;
}
stream.write(`
// for setup relation. can't use import in funcion scope
var ${rel.targetName} = ${moduleName}init${rel.targetName}(seq);`);
switch (rel.type) {
case RelationshipType.OneToMany:
stream.write(`
${name}.hasMany(${rel.targetName}, {as: '${rel.name}'});`);
break;
case RelationshipType.ManyToOne:
stream.write(`
${name}.belongsTo(${rel.targetName}, {as: '${rel.name}'});`);
}
});
stream.write(`
${name}Initialized = true;
return ${name};
}
`);
}