Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function read(path: string): Promise {
const contents = await readFile(path, 'utf8');
const doc = et.parse(contents);
return doc;
}
async readPem(p: string): Promise {
try {
return await readFile(p, { encoding: 'utf8' });
} catch (e) {
process.stderr.write(String(e.stack ? e.stack : e) + '\n');
throw new Error(`Error encountered with ${p}`);
}
}
}
async detected() {
const indexHtml = await readFile(path.resolve(await this.project.getSourceDir(), 'index.html'), { encoding: 'utf8' });
const m = indexHtml.match(/\/);
return !Boolean(m);
}
export async function createDevServerHandler(options: DevServerOptions): Promise {
const devServerConfig = {
consolelogs: options.consolelogs,
wsPort: options.devPort,
};
const devServerJs = await readFile(path.join(__dirname, '..', '..', 'assets', 'dev-server.js'), { encoding: 'utf8' });
return (req, res) => {
res.set('Content-Type', 'application/javascript');
res.send(
`window.Ionic = window.Ionic || {}; window.Ionic.DevServerConfig = ${JSON.stringify(devServerConfig)};\n\n` +
`${devServerJs}`.trim()
);
};
}
export async function readINI(p: string, guard: INIGuard = (o: any): o is T => true): Promise {
const ini = await import('ini');
try {
const contents = await readFile(p, { encoding: 'utf8' });
const config = ini.decode(contents);
if (!guard(config)) {
throw new Error(
`Invalid ini configuration file: ${p}\n` +
`The following guard was used: ${guard.toString()}\n` +
`INI config parsed as: ${util.inspect(config)}`
);
}
return { __filename: p, ...config as any };
} catch (e) {
debug(e);
}
}
req.key(await Promise.all(keyfiles.map(p => readFile(p, { encoding: 'utf8' }))));
}
protected async reload(): Promise {
const configXml = await readFile(this.configXmlPath, { encoding: 'utf8' });
if (!configXml) {
throw new Error(`Cannot load empty config.xml file.`);
}
try {
this._doc = et.parse(configXml);
this._sessionid = shortid();
} catch (e) {
throw new Error(`Cannot parse config.xml file: ${e.stack ? e.stack : e}`);
}
const packageJson = await readPackageJsonFile(this.packageJsonPath);
if (isCordovaPackageJson(packageJson)) {
this._pkg = packageJson;