Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
generatedCodeSourceFile.addVariableStatement({
declarationKind: VariableDeclarationKind.Const,
isExported: false,
declarations: [{
name: 'classesMap',
type: "object",
initializer: `{\n${Array.from(factoryClasses.entries())
.map(([alias, className]) =>
`${classToIntrinsic(className)}: ${alias},${className}: ${alias}`)
.join(',\n')}}`
}]
});
// for going from camelCase on vrExperienceHelper to VRExperienceHelper to locate generated classes.
generatedCodeSourceFile.addVariableStatement({
declarationKind: VariableDeclarationKind.Const,
isExported: true,
declarations: [{
name: 'intrinsicClassMap',
type: "object",
initializer: `{\n${Array.from(factoryClasses.entries())
.map(([alias, className]) =>
`${classToIntrinsic(className)}:'${className}'`)
.join(',\n')},
${createdMeshClasses.map(meshName =>
`${classToIntrinsic(meshName)}:'${meshName}'`)
.join(',\n')}
}`
}]
});
const functionDeclaration:FunctionDeclaration = generatedCodeSourceFile.addFunction({
}
])
// generate reducers const
const reducerRootName = 'reducers'
const reducersVarStatement =
reducerRootSourceFile.getVariableStatement(reducerRootName) ||
reducerRootSourceFile.addVariableStatement({
isExported: true,
declarations: [
{
name: reducerRootName,
initializer: `combineReducers({})`
}
],
declarationKind: VariableDeclarationKind.Const
})
const reducers = reducersVarStatement.getDescendantsOfKind(
SyntaxKind.ObjectLiteralExpression
)[0]
if (!reducers) {
throw new Error('Invalid reducer file.')
}
reducers.addPropertyAssignment({
name,
initializer: reducerName
})
// generate root action types
folder,
filesystem: { cwd },
strings: { camelCase, kebabCase },
print: { spin, colors }
} = this.context
const spinner = spin('Generating...')
const { name, filePath, base } = this.qa.result
const themeFile = this.project.createSourceFile(filePath)
ReactUtils.addNamedImport(themeFile, base.path, base.name)
themeFile.addVariableStatement({
isExported: true,
declarationKind: VariableDeclarationKind.Const,
declarations: [
{
name,
initializer: `${base.name}.extend(
{
// override default theme variables
},
vars => ({
// override default theme styles
})
)`
}
]
})
const stylesFile = this.project.addExistingSourceFile(
alias: fileModuleDeclaration.moduleDeclaration.importAlias
})
if (fileModuleDeclaration.hostComponent && !factoryClasses.has(fileModuleDeclaration.moduleDeclaration.importAlias)) {
factoryClasses.set(fileModuleDeclaration.moduleDeclaration.importAlias, fileModuleDeclaration.moduleDeclaration.className);
}
})
})
})
// we can do this as long as there are no classes with the same name across imports
// otherwise we can just use a Set with importalias, but need to generate more metadata.
// ie: classseMap = { BabylonjsCoreBox, BabylonjsCoreSphere, ... };
// We generate both IntrinsicType (ie: arcRotateCamera) and "component" (ie: ArcRotateCamera), but will remove "component" when local JSX is ready.
generatedCodeSourceFile.addVariableStatement({
declarationKind: VariableDeclarationKind.Const,
isExported: false,
declarations: [{
name: 'classesMap',
type: "object",
initializer: `{\n${Array.from(factoryClasses.entries())
.map(([alias, className]) =>
`${classToIntrinsic(className)}: ${alias},${className}: ${alias}`)
.join(',\n')}}`
}]
});
// for going from camelCase on vrExperienceHelper to VRExperienceHelper to locate generated classes.
generatedCodeSourceFile.addVariableStatement({
declarationKind: VariableDeclarationKind.Const,
isExported: true,
declarations: [{
path.dirname(screenToAttach.sourceFile.getFilePath()),
'nav.ts'
)
: folder.navigator(kebabCase(name) + '.ts')
this.project = new Project()
this.sourceFile = this.project.createSourceFile(filePath)
this.sourceFile.addImportDeclaration({
namedImports: [this.navigatorFn, 'createAppContainer'],
moduleSpecifier: 'react-navigation'
})
this.sourceFile.addVariableStatement({
isExported: true,
declarationKind: VariableDeclarationKind.Const,
declarations: [
{
name,
initializer: this.generateNavigator()
}
]
})
const screenAttached = this.attachToScreen()
const source = tools.source()
await source.prettifySoureFile(this.sourceFile)
if (screenToAttach) {
await source.prettifySoureFile(this.screenFile)
}
type: `Reducer<${reducerStateName}, ${reducerActionTypeName}>`,
initializer: `(state = {
${stateInitializer}
},
action
) => {
switch (action.type) {
${body || ''}
default:
return state
}
}`
}
],
isExported: true,
declarationKind: VariableDeclarationKind.Const
})
await this.source.prettifySoureFile(reducerFile)
}
}
operationGroupDetails.operations.forEach(operation => {
const operationName = normalizeName(operation.name, NameType.Property);
const operationSpec = transformOperationSpec(operation);
file.addVariableStatement({
declarationKind: VariableDeclarationKind.Const,
declarations: [
{
name: `${operationName}OperationSpec`,
type: "coreHttp.OperationSpec",
initializer: buildSpec(operationSpec)
}
]
});
});
}
export function getVariableKind(kind: VariableDeclarationKind): VariableKind {
switch (kind) {
case VariableDeclarationKind.Const:
return VariableKind.Const;
case VariableDeclarationKind.Let:
return VariableKind.Let;
case VariableDeclarationKind.Var:
return VariableKind.Var;
}
}
export function addVariableDeclaration(
node: StatementedNode,
name: string,
type: string,
isConst: boolean,
hasDeclareKeyword?: boolean,
jsdocs?: JSDoc[]
): VariableStatement {
return node.addVariableStatement({
declarationKind: isConst
? VariableDeclarationKind.Const
: VariableDeclarationKind.Let,
declarations: [{ name, type }],
docs: jsdocs && jsdocs.map(jsdoc => jsdoc.getText()),
hasDeclareKeyword
});
}
namedImports: ["assertNever"],
moduleSpecifier: "../utils"
}, {
kind: StructureKind.TypeAlias,
isExported: true,
name: "CompilerVersions",
type: versions.map(v => `"${v.version}"`).join(" | ")
}, {
kind: StructureKind.TypeAlias,
isExported: true,
name: "CompilerPackageNames",
type: versions.map(v => `"${v.name}"`).join(" | ")
}, {
kind: StructureKind.VariableStatement,
isExported: true,
declarationKind: VariableDeclarationKind.Const,
declarations: [{
name: "compilerVersionCollection",
initializer: writer => {
writer.write("[").newLine();
writer.indent(() => {
for (let i = 0; i < versions.length; i++) {
const version = versions[i];
writer.write(`{ version: "${version.version}", packageName: "${version.name}" }`);
if (i < versions.length - 1)
writer.write(",");
writer.newLine();
}
});
writer.write("]");
},
type: "{ version: CompilerVersions; packageName: CompilerPackageNames; }[]"