Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const writeFiles = (
directory: string,
files: {[filename: string]: string},
) => {
createDirectory(directory);
Object.keys(files).forEach(fileOrPath => {
const dirname = path.dirname(fileOrPath);
if (dirname !== '/') {
createDirectory(path.join(directory, dirname));
}
fs.writeFileSync(
path.resolve(directory, ...fileOrPath.split('/')),
files[fileOrPath],
);
});
};
Object.keys(files).forEach(fileOrPath => {
const dirname = path.dirname(fileOrPath);
if (dirname !== '/') {
createDirectory(path.join(directory, dirname));
}
fs.writeFileSync(
path.resolve(directory, ...fileOrPath.split('/')),
files[fileOrPath],
);
});
};
Object.keys(files).forEach(fileOrPath => {
const dirname = path.dirname(fileOrPath);
if (dirname !== '/') {
createDirectory(path.join(directory, dirname));
}
fs.writeFileSync(
path.resolve(directory, ...fileOrPath.split('/')),
files[fileOrPath],
);
});
};
export const createEmptyPackage = (
directory: Config.Path,
packageJson?: {[keys: string]: any},
) => {
const DEFAULT_PACKAGE_JSON = {
description: 'THIS IS AN AUTOGENERATED FILE AND SHOULD NOT BE ADDED TO GIT',
jest: {
testEnvironment: 'node',
},
};
createDirectory(directory);
packageJson || (packageJson = DEFAULT_PACKAGE_JSON);
fs.writeFileSync(
path.resolve(directory, 'package.json'),
JSON.stringify(packageJson, null, 2),
);
};
async setup() {
await super.setup();
const tmpDir = os.tmpdir();
const localTestDir = path.join(tmpDir, 'hubspot-cms-tools-command-tests');
const configFilePath = path.join(tmpDir, 'hubspot.config.yml');
const hsPath = path.join(__dirname, binPaths.hs);
const hscmsPath = path.join(__dirname, binPaths.hscms);
this.global.hsPath = hsPath;
this.global.hscmsPath = hscmsPath;
this.global.localTestDir = localTestDir;
this.global.configFilePath = configFilePath;
this.global.configSource = configSourceTemplate(this.global);
createDirectory(localTestDir);
await fs.emptyDir(localTestDir);
await fs.ensureFile(configFilePath);
await fs.writeFile(configFilePath, configSourceTemplate(this.global));
}
configs.map(async (config, index) => {
createDirectory(config.cacheDirectory);
const hasteMapInstance = Runtime.createHasteMap(config, {
console: new CustomConsole(outputStream, outputStream),
maxWorkers: Math.max(
1,
Math.floor(globalConfig.maxWorkers / configs.length),
),
resetCache: !config.cache,
watch: globalConfig.watch || globalConfig.watchAll,
watchman: globalConfig.watchman,
});
hasteMapInstances[index] = hasteMapInstance;
return createContext(config, await hasteMapInstance.build());
}),
);
return new Promise((resolve, reject) => {
createDirectory(DIR);
const fileId = crypto.randomBytes(20).toString('hex');
fs.writeFileSync(path.join(DIR, fileId), 'teardown');
resolve();
});
};
return new Promise((resolve, reject: any) => {
createDirectory(DIR);
const fileId = crypto.randomBytes(20).toString('hex');
fs.writeFileSync(path.join(DIR, fileId), 'setup');
resolve();
});
};
return new Promise((resolve, reject) => {
createDirectory(DIR);
const fileId = crypto.randomBytes(20).toString('hex');
fs.writeFileSync(path.join(DIR, fileId), 'teardown');
resolve();
});
};
return new Promise((resolve, reject) => {
createDirectory(DIR);
const fileId = crypto.randomBytes(20).toString('hex');
fs.writeFileSync(path.join(DIR, fileId), 'teardown');
resolve();
});
};