Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const readSnippets = snippetsPath => {
const snippetFilenames = getFilesInDir(snippetsPath, false);
let snippets = {};
try {
for (let snippet of snippetFilenames)
snippets[snippet] = fs.readFileSync(path.join(snippetsPath, snippet), 'utf8');
} catch (err) {
console.log(`${chalk.red('ERROR!')} During snippet loading: ${err}`);
process.exit(1);
}
return snippets;
};
// Creates an object from pairs
function deleteAccessManagment(idApplication, urlComponent, urlModule, callback) {
// Write new data entity to access.json file, within module's context
var accessPath = __dirname + '/../workspace/' + idApplication + '/config/access.json';
var accessLockPath = __dirname + '/../workspace/' + idApplication + '/config/access.lock.json';
var accessObject = JSON.parse(fs.readFileSync(accessPath, 'utf8'));
if (accessObject[urlModule.toLowerCase()] && accessObject[urlModule.toLowerCase()].entities) {
var entities = accessObject[urlModule.toLowerCase()].entities;
var dataIndexToRemove = -1;
for (var i = 0; i < entities.length; i++) {
if (entities[i].name === urlComponent) {
dataIndexToRemove = i;
break;
}
}
if (dataIndexToRemove !== -1)
entities.splice(dataIndexToRemove, 1);
fs.writeFileSync(accessPath, JSON.stringify(accessObject, null, 4), "utf8");
fs.writeFileSync(accessLockPath, JSON.stringify(accessObject, null, 4), "utf8");
callback();
} else
callback();
async function getRocketSamSettings() {
try {
var doc = yaml.safeLoad(fs.readFileSync(`${process.cwd()}/rocketsam.yaml`, 'utf8'));
return doc
}
catch (e) {
console.log("rocketsam not found, is project configured?");
}
}
await fs.copy(src, dst)
if (!fs.existsSync(dst)) {
throw new Error(`${dst} does not exist`)
}
}
const targetIndexHtml = path.resolve(root, 'static/index.html')
if (!fs.existsSync(targetIndexHtml)) {
throw new Error(`${targetIndexHtml} does not exist`)
}
console.log(`> replace ${filename}.js -> ${newFileName} in html`)
{
let content = readFileSync(targetIndexHtml).toString()
if (!content.includes(`${filename}.js`)) {
throw new Error(`index.html is dirty and does\'t contain the text "${filename}.js"`)
}
content = content.replace(new RegExp(filename + '.(S+.)?js'), newFileName)
content = content.replace(/\s*/, '')
content = content + `\n\n`
writeFileSync(targetIndexHtml, content)
}
}
render() {
const {baseUrl, tutorialID} = this.props;
const htmlFile = `${CWD}/_tutorials/${tutorialID}.html`;
const normalizedHtmlFile = path.normalize(htmlFile);
return (
<div>
<div>
<div>
<a href="{`${baseUrl}files/${tutorialID}.ipynb`}" download="">
{renderDownloadIcon()}
{'Download Tutorial Jupyter Notebook'}
</a>
</div>
<div>
</div></div></div>
beforeRun (cb = () => {}) {
process.env.compilerType = this.$options.type;
let inputDir = this.$options.entry;
let outputDir = this.$options.dist;
let lifeCycles = this.$plugin.lifeCycles;
let self = this;
const packagePath = path.join(__dirname, '../..', 'package.json');
const packageJson = fs.readFileSync(packagePath);
const versionData = { version: JSON.parse(packageJson).version};
if (lifeCycles.defaultOptions.exclude) {
this.$options.exclude = this.$options.exclude.concat(lifeCycles.defaultOptions.exclude);
}
lifeCycles.$options = Object.assign(lifeCycles.defaultOptions, this.$options, versionData);
/**
* Setting compile env
*/
process.env.NODE_ENV = lifeCycles.$options.env;
lifeCycles.beforeParse(function () {
self.run(inputDir, outputDir, cb);
});
}
function cleanPackageJSON() {
const content = fs.readFileSync(pkgPath, "utf8")
process.once("exit", () => fs.outputFileSync(pkgPath, content))
const pkgJSON = JSON.parse(content)
for (const field of fieldsToRemove) {
Reflect.deleteProperty(pkgJSON, field)
}
pkgJSON.scripts = defaultScripts
fs.outputFileSync(pkgPath, fleece.patch(content, pkgJSON))
}
_loadTheme() {
if (Config.themeMainPath) {
const css = fs.readFileSync(Config.themeMainPath).toString();
Global.getMainWindow().webContents.send('load-theme-main', css);
} else {
Global.getMainWindow().webContents.send('load-theme-main', '');
}
}
}
fs.readdirSync(outputJSTemplatesPath).forEach((jsTemplate) => {
if (jsTemplate.endsWith("html")) {
templatePath = path.resolve(outputJSTemplatesPath, jsTemplate);
localizedTemplate = fs.readFileSync(
templatePath,
"utf8"
).replace(
jsTemplatesGettextRegex,
(match, capture) => {
return gt.gettext(capture);
}
);
fs.writeFileSync(
templatePath,
localizedTemplate,
"utf8"
);
}
});
function readYaml(yamlPath) {
return yaml.safeLoad(fs.readFileSync(yamlPath));
}