Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private registerPartials() {
const partialsPath = join(__dirname, `partials`);
const templates = new GlobSync('./*.handlebars', { cwd: partialsPath });
templates.found.forEach((path: string) => {
logger.debug("Adding new partial", path);
// tslint:disable-next-line:no-any
let name: any = basename(path).split('.');
if (name.length > 0) {
name = name[0];
}
const location = join(partialsPath, path);
const content = readFileSync(location, { encoding: "UTF8" });
handlebars.registerPartial(name, content);
});
}
}
public async dropDatabaseSchema() {
try {
if (this.client === 'sqlite3') {
const sqliteFile = new GlobSync('*.sqlite', { cwd: process.cwd() })
if (sqliteFile.found.length) {
unlinkSync(`${process.cwd()}/${sqliteFile.found[0]}`)
}
} else {
await this.getConnection().raw('DROP SCHEMA public CASCADE;')
// tslint:disable-next-line: await-promise
await this.getConnection().raw('CREATE SCHEMA public;')
}
} catch (err) {
this.handleError(err)
}
}
public getAdditionalTestAdapters(workspace: string): Array {
const globPattern = path.join(workspace, this.config.output, "**", "**.TestAdapter.dll");
const files = new GlobSync(globPattern, { matchBase: true }).found;
return files;
}
}
export function getAllTestFilesInDirectory(directory, globExp): Array {
let globPattern = path.join(directory, globExp);
const fileTestList = new GlobSync(globPattern, null).found;
return fileTestList;
}
export const createDBResources = async (config: ProjectConfig): Promise => {
let databaseOperations: any[];
try {
const { db: { database }, folders } = config;
const models = new GlobSync(`${folders.model}/*.graphql`)
if (models.found.length === 0) {
logError(`No graphql file found inside ${process.cwd()}/model folder.`)
process.exit(0)
}
if (database === 'sqlite3') {
await execa('touch', ['db.sqlite'])
}
const dbConfig = {
client: config.db.database,
connection: config.db.dbConfig
}
const schemaText = loadSchema(folders.model);
export async function generateBackend(): Promise {
try {
const models = new GlobSync('model/*.graphql', { cwd: process.cwd() })
if (models.found.length === 0) {
logError(`No graphql file found inside ${process.cwd()}/model folder.`)
process.exit(0)
}
const configPath = `${process.cwd()}/config.json`
const { database, generation } = JSON.parse(readFileSync(configPath, "utf8"))
const { templateType } = JSON.parse(readFileSync(`${process.cwd()}/.template.json`, 'utf8'))
const path: string = process.cwd()
const schemaText: string = models.found.map((m: string) => readFileSync(`${path}/${m}`, 'utf8')).join('\n')
const outputSchemaPath: string = `${process.cwd()}/src/schema/generated.ts`
const outputResolverPath: string = `${process.cwd()}/src/resolvers`
export const transformOpenApiSpec = async () => {
const configInstance = new ConfigBuilder();
checkDirectory(configInstance);
const { folders, openApi } = configInstance.config;
const models = new GlobSync(`${folders.model}/*.yaml`)
const jsonModels = new GlobSync(`${folders.model}/*.json`)
if (models.found.length === 0 && jsonModels.found.length === 0) {
logError(`No OpenAPI file found inside model folder.`)
process.exit(0)
}
for (const model of jsonModels.found) {
await processSingleDefinition(model, false, openApi);
}
for (const model of models.found) {
await processSingleDefinition(model, true, openApi);
}
logInfo(`
Successfully generated GraphQL schema from OpenAPI definition.
public getRelativeModulesDirs(): string[] {
const list: string[] = [];
switch (this.type) {
case WorkspaceType.SFDX:
new GlobSync(`${this.sfdxPackageDirsPattern}/**/lwc/`, { cwd: this.workspaceRoot }).found.forEach(dirPath => {
list.push(dirPath);
});
break;
case WorkspaceType.CORE_ALL:
for (const project of fs.readdirSync(this.workspaceRoot)) {
const modulesDir = join(project, 'modules');
if (fs.existsSync(join(this.workspaceRoot, modulesDir))) {
list.push(modulesDir);
}
}
break;
case WorkspaceType.CORE_SINGLE_PROJECT:
list.push('modules');
break;
public findFilesAsUris(globPattern: string): string[] {
return new GlobSync(normalize(globPattern)).found.map((f) =>
URI.file(f).toString()
);
}