Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private async _initialize() {
const levelupOptions: any = { valueEncoding: "binary" };
const store = this.options.db;
let db;
if (store) {
db = await levelup(store as any, levelupOptions);
} else {
let directory = this.options.dbPath;
if (!directory) {
const dirInfo = await dir(tmpOptions);
directory = dirInfo.path;
this._cleanupDirectory = dirInfo.cleanup;
// don't continue if we closed while we were waiting for the dir
if (this.closed) return this._cleanup();
}
this.directory = directory;
const store = encode(leveldown(directory), levelupOptions);
db = await levelup(store, {});
}
// don't continue if we closed while we were waiting for the db
if (this.closed) return this._cleanup();
const open = db.open();
this.trie = sub(db, "trie", levelupOptions);
task: async (ctx, task) => {
// Create temporary directory
if (!publishDir) {
const { path: tmpDir } = await tmp.dir()
publishDir = tmpDir
}
await prepareFilesForPublishing(publishDir, files, ignore)
ctx.pathToPublish = publishDir
return `Files copied to temporary directory: ${ctx.pathToPublish}`
},
},
beforeEach(async () => {
tmpDir = await tmp.dir({ unsafeCleanup: true });
});
export default async function shoutemPack(dir, options) {
const packedDirectories = ['app', 'server'].map(d => path.join(dir, d));
if (!await hasExtensionsJson(dir)) {
throw new Error(`${dir} cannot be packed because it has no extension.json file.`);
}
await await offerDevNameSync(dir);
const tmpDir = (await tmp.dir()).path;
const packageDir = path.join(tmpDir, 'package');
await fs.mkdir(packageDir);
const dirsToPack = await Promise.filter(packedDirectories, hasPackageJson);
if (options.nobuild) {
console.error('Skipping build step due to --nobuild flag.');
} else {
await spinify(buildNodeProject(path.join(dir, 'server')), 'Building the server part...', 'OK');
await spinify(buildNodeProject(path.join(dir, 'app')), 'Building the app part...', 'OK');
}
return await spinify(async () => {
for (const partDir of dirsToPack) {
await npmPack(partDir, packageDir);
async function processRepository(
repository: GitHubRepository,
updateCallback: Function,
branch: string,
message: string,
comment: string,
reviewers: string[]
) {
const tmpDir = await tmp.dir({unsafeCleanup: true});
const cloneUrl = repository.getRepository().ssh_url;
await exec(`git clone ${cloneUrl} ${tmpDir.path}`);
let filesToUpdate;
try {
filesToUpdate = await updateCallback(tmpDir.path);
} catch (err) {
console.warn(
' callback function threw an exception, skipping this repository',
err ? err.stack : ''
);
return;
}
if (filesToUpdate === undefined) {
async setupHome() {
this.home = await tmp.dir({ unsafeCleanup: true });
}
public async directoryFor(owner: string, repo: string, branch: string, opts: CloneOptions): Promise {
this.initialize();
const fromTmp = await tmp.dir({ keep: opts.keep, prefix: this.prefix });
return {
...fromTmp,
type: "empty-directory",
release: () => this.cleanup(fromTmp.path, opts.keep),
invalidate: () => Promise.resolve(),
transient: opts.keep === false,
provenance: `created with tmp, keep = ${opts.keep}`,
};
}
export async function createTmpDir(): Promise {
const { path: tmpPathDir } = await dir({ prefix: SHARED_PREFIX });
debug(`Created tmp dir:`, tmpPathDir);
return tmpPathDir;
}
export const buildTmpDirectory = async (sourceFiles) => {
const filesMap = new Map();
const tmpDir = await tmp.dir();
await Promise.all(
sourceFiles.map(async (sourceFile) => {
const { url, localPath } = sourceFile;
const tmpPath = path.join(tmpDir.path, localPath);
await ensureDir(path.dirname(tmpPath));
const tmpFile = await streamS3UrlToFile(url, tmpPath);
filesMap.set(localPath, tmpFile);
}),
);
return {
getTmpPathByLocalPath: (localPath) => filesMap.get(localPath),
tmpDir: tmpDir,
};
};
async downloadById(extensionId: IExtension['id']) {
const tempDir = await dir({ prefix: 'ecx-', unsafeCleanup: true });
this.downloads.set(extensionId, tempDir);
const path = await downloadById(extensionId, tempDir.path, extensionId);
return {
id: extensionId,
location: new Location(path),
};
}