async writeConfig(config) { const { cubeCloudConfigPath, configFile } = this.configFile(); await fs.mkdirp(cubeCloudConfigPath); await fs.writeJson(configFile, config); }
async function copyDir(baseSourceDir, sourcePath, baseDestDir) { await fs.mkdirp(`${baseDestDir}/${sourcePath}`); await fs.copy(`${baseSourceDir}/${sourcePath}`, `${baseDestDir}/${sourcePath}`); }
async function checkSourceZip(sourceZip, compiledZip) { const tmpDir = `${require('os').tmpdir()}/${Date.now()}`; console.info(`Checking source ZIP in ${tmpDir}`); const sourceDir = `${tmpDir}/source`; const compiledDir = `${tmpDir}/compiled`; await fs.mkdirp(sourceDir); await fs.mkdirp(compiledDir); process.chdir(sourceDir); console.info(await execCommand(`cp "${sourceZip}" .`)); console.info(await execCommand(`unzip "${sourceZip}"`)); process.chdir(`${sourceDir}/Clipper-source/popup`); console.info(await execCommand('npm install')); process.chdir(compiledDir); console.info(await execCommand(`cp "${compiledZip}" .`)); console.info(await execCommand(`unzip "${compiledZip}"`)); const areEqual = await compareDir(`${sourceDir}/Clipper-source/popup/build`, `${compiledDir}/popup/build`); if (areEqual) { await fs.remove(sourceDir); await fs.remove(compiledDir); } }
async function main() { await fs.mkdirp(blogDir); await fs.mkdirp(imageDir); await fs.mkdirp(tempDir); const fields = [ 'title', 'content', 'published_at', 'url', ]; let url = `https://www.patreon.com/api/oauth2/v2/campaigns/1818121/posts?fields%5Bpost%5D=${fields.join(',')}`; while (url) { console.info('Fetching ', url); const result = await fetchPosts(url); console.info(`Found ${result.data.length} posts`); await createPostFiles(result.data); url = result.nextUrl; } }
const distDir = `${clipperDir}/dist/${distName}`; await fs.remove(distDir); await fs.mkdirp(distDir); await copyToDist(distDir);
await fs.mkdirp(releaseDir);
async _createNestedFolders() { await Promise.all(this._folders.map(folder => fs.mkdirp(folder))); }
/** * Starts the build process */ async run() { await fs.remove(this._outputDir); await fs.mkdirp(this._outputDir); const srcDirs = await this.discoverDirs(); await this.processDirs(srcDirs); }
app.post('/_hads/upload', [multer({ storage: multer.diskStorage({ destination: (req, file, cb) => { cb(null, PATHS.images); }, filename: (req, file, cb) => { fs.mkdirp(PATHS.images).then(() => { cb(null, shortId.generate() + path.extname(file.originalname)); }); } }), onFileUploadStart: file => !file.mimetype.match(/^image\//), limits: { fileSize: 1024 * 1024 * 10 // 10 MB } }).single('file'), (req, res) => { res.json(path.sep + path.relative(PATHS.root, req.file.path)); }]);
/** * Given a source folder, this function minifies all the files in that folder * and sets a unique hash for each file and saves in the target location * * @param {string} src - Source directory path * @param {string} tgt - Target directory path * @returns {Promise} promise */ async moveFolder(src, tgt) { const parentFolder = path.dirname(tgt); const language = path.basename(tgt); const fileNames = await fs.readdir(src); const promises = fileNames.map(async fileName => { const srcFile = path.join(src, fileName); if (path.extname(srcFile) === '.json') { const namespace = this.getNamespace(fileName); const newTgtDir = path.join(parentFolder, namespace); await fs.mkdirp(newTgtDir); return await this.copyFile(srcFile, newTgtDir, true, language); } }); return await Promise.all(promises); }
const makeDir = path => fs.mkdirp(path)
/** * Starts the build process */ async run() { await fs.remove(this._outputDir); await fs.mkdirp(this._outputDir); const srcDirs = await this.discoverDirs(); await this.processDirs(srcDirs); }
async _createNestedFolders() { await Promise.all(this._folders.map(folder => fs.mkdirp(folder))); }
/** * Given a source folder, this function minifies all the files in that folder * and sets a unique hash for each file and saves in the target location * * @param {string} src - Source directory path * @param {string} tgt - Target directory path * @returns {Promise} promise */ async moveFolder(src, tgt) { const parentFolder = path.dirname(tgt); const language = path.basename(tgt); const fileNames = await fs.readdir(src); const promises = fileNames.map(async fileName => { const srcFile = path.join(src, fileName); if (path.extname(srcFile) === '.json') { const namespace = this.getNamespace(fileName); const newTgtDir = path.join(parentFolder, namespace); await fs.mkdirp(newTgtDir); return await this.copyFile(srcFile, newTgtDir, true, language); } }); return await Promise.all(promises); }