Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async run ( options : LoadArtworkOptions ) {
const repository = this.server.repositories.get( options.repository );
for ( let record of JSON.parse( await fs.readFile( options.input, 'utf8' ) ) ) {
this.log( record.id, record.title, record.art.poster );
const match = await this.server.media.get( options.kind, record.id );
for ( let property of options.properties ) {
if ( match.art[ property ] != record.art[ property ] ) {
repository.setPreferredMediaArt( match.kind, match.id, property, record.art[ property ] );
match.art[ property ] = record.art[ property ];
}
}
// if ( match.art.poster != show.art.poster ) {
// repository.setPreferredMediaArt( match.kind, match.id, 'poster', show.art.poster );
// }
function readAuthToken(authFile) {
if (!authFile) {
authFile = expandHomeDir('~/.appreciate');
}
return fs.readFile(authFile).then(tokenBuffer => {
// Convert the buffer to string
return tokenBuffer.toString('utf8').trim();
});
}
it('should export inventories to file as csv', async () => {
const csvFilePath = tmp.fileSync().name
const [stdout, stderr] = await exec(
`${binPath} -p ${projectKey} -o ${csvFilePath} -f csv`
)
expect(stdout && stderr).toBeFalsy()
const data = await fs.readFile(csvFilePath, { encoding: 'utf8' })
const expectedData = `12345,20,inventory-custom-type,integration tests!! arrgggh,${new Date().getFullYear()}`
expect(data).toContain(expectedData)
})
})
function failReadFile () {
return fs.readFile('foo-bar')
}
function getProjectCreatedMessage(projectPath) {
return fs.readFile(path.join(__dirname, "assets", "webextension-logo.ascii"))
.then(asciiLogo => {
const PROJECT_CREATED_MSG = `\n
Congratulations!!! A new WebExtension has been created at:
${chalk.bold(chalk.green(projectPath))}`;
return `${asciiLogo} ${PROJECT_CREATED_MSG} ${MORE_INFO_MSG}`;
});
}
public async parseFile(filePath: string) {
const code = await fs.readFile(filePath, 'utf-8');
const config = this.vscodeService.getConfig(filePath);
if (!config) {
return [];
}
const ast = babelParser.parse(code, config.parserOptions);
const result: ModelReference[] = [];
traverse(ast, {
enter(path) {
const { node } = path;
if (!isCallExpression(node)) {
return;
}
const { callee } = node;
if (!isIdentifier(callee) || node.arguments.length !== 1) {
return;
}
function createSpecificityGraph(stats, filename) {
const tmpPath = path.resolve(__dirname, '../../../tmp');
const outputPath = path.resolve(tmpPath, `specificity.${filename}.html`);
const specificity = stats.selectors.getSpecificityGraph();
const selectors = stats.selectors.values;
const chartRows = specificity.map((val, index) => {
const tooltip = `<strong>${val}</strong><br><code>${selectors[index]}</code>`;
return [index, val, tooltip];
});
return fs
.readFile(path.resolve(__dirname, 'chart-template.html'), 'utf8')
.then(body => body.replace(/{{ROW_DATA}}/, JSON.stringify(chartRows)))
.then(body => {
if (!fs.existsSync(tmpPath)) {
fs.mkdir(tmpPath).then(() => body);
}
return body;
})
.then(body => fs.writeFile(outputPath, body, 'utf8'))
.then(() => {
dutil.logMessage('📈 ', `Specificity graph created: ${outputPath}`);
});
}
await concurrentForEach(assets, async asset => {
const assetContent = await readFile(join(rootPath, asset.path));
await this.s3Client
.putObject({
Bucket: this.s3Bucket,
Body: assetContent,
Key: this.getAssetS3Key(id, asset.path)
})
.promise();
});
_readCapacity(): Promise {
return fs.readFile('/sys/class/power_supply/battery/capacity')
.then((data) => Number(data.toString()));
}
async function copy(from, to) {
const data = await fs.readFile(from);
const dir = path.dirname(to);
await mkdirAll(dir);
await fs.writeFile(to, data);
}