Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
global['module'].paths.map((x: string) => nodeModule.globalPaths.push(normalizePath(x)))
if (process.env.TERMINUS_DEV) {
nodeModule.globalPaths.unshift(path.dirname(require('electron').remote.app.getAppPath()))
}
const builtinPluginsPath = process.env.TERMINUS_DEV ? path.dirname(require('electron').remote.app.getAppPath()) : path.join((process as any).resourcesPath, 'builtin-plugins')
const userPluginsPath = path.join(
require('electron').remote.app.getPath('appData'),
'terminus',
'plugins',
)
if (!fs.existsSync(userPluginsPath)) {
fs.mkdir(userPluginsPath)
}
Object.assign(window, { builtinPluginsPath, userPluginsPath })
nodeModule.globalPaths.unshift(builtinPluginsPath)
nodeModule.globalPaths.unshift(path.join(userPluginsPath, 'node_modules'))
// nodeModule.globalPaths.unshift(path.join((process as any).resourcesPath, 'app.asar', 'node_modules'))
if (process.env.TERMINUS_PLUGINS) {
process.env.TERMINUS_PLUGINS.split(':').map(x => nodeModule.globalPaths.push(normalizePath(x)))
}
export type ProgressCallback = (current: number, total: number) => void // eslint-disable-line @typescript-eslint/no-type-alias
export interface PluginInfo {
name: string
description: string
packageName: string
async ensureNewDir(dir) {
if (fs.existsSync(dir)) rimraf.sync(dir);
// support Docker volume data
if (!fs.existsSync(dir)) {
await fs.mkdir(dir);
}
}
return co(function * () {
yield fs.mkdir(name);
yield Object.keys(node).map(key => {
if (node[key] === true) return fs.writeFile(`${name}/${key}`, '', 'utf-8');
if (typeof node[key] === 'object') folders.push([`${name}/${key}`, node[key]]);
});
});
}
public async write() {
const c = CacheType.encode(this.o);
const dir = path.dirname(CACHE_PATH);
if (!await fs.exists(dir)) {
await fs.mkdir(dir);
}
return fs.writeFile(CACHE_PATH, JSON.stringify(c));
}
}
async function buildDirectory(
srcDirPath: string,
outDirPath: string,
options: CLIOptions,
): Promise {
const extensions = options.sucraseOptions.transforms.includes("typescript")
? [".ts", ".tsx"]
: [".js", ".jsx"];
if (!(await exists(outDirPath))) {
await mkdir(outDirPath);
}
for (const child of await readdir(srcDirPath)) {
if (["node_modules", ".git"].includes(child) || options.excludeDirs.includes(child)) {
continue;
}
const srcChildPath = join(srcDirPath, child);
const outChildPath = join(outDirPath, child);
if ((await stat(srcChildPath)).isDirectory()) {
await buildDirectory(srcChildPath, outChildPath, options);
} else if (extensions.some((ext) => srcChildPath.endsWith(ext))) {
const outPath = outChildPath.replace(/\.\w+$/, `.${options.outExtension}`);
await buildFile(srcChildPath, outPath, options);
}
}
}
await elems.reduce(async (p, newPath) => {
const oldPath = await p;
const newDir = path.join(oldPath, newPath);
await fs.mkdir(newDir).catch(_ => {});
return newDir;
}, Promise.resolve(''));
}
async ensureDir ( folder : string ) : Promise {
if ( !( await fs.exists( folder ) ) ) {
await this.ensureDir( path.dirname( folder ) );
await fs.mkdir( folder );
}
}