Best JavaScript code snippet using redwood
cycles.ts
Source:cycles.ts
...109 action$: S.UIO<UnclaimedLicensesAction>,110 state$: S.UIO<AppState>111): S.UIO<Action> =>112 pipe(113 zipSources(action$, state$),114 S.chain(([a, state]) =>115 UnclaimedLicensesAction.is.FetchUnclaimedLicenses(a)116 ? pipe(117 state.auth,118 filterAccessToken,119 S.mapM((accessToken) =>120 pipe(121 getUnclaimedLicenses(accessToken),122 T.map((unclaimedLicenses) =>123 pipe(124 unclaimedLicenses,125 payload,126 UnclaimedLicensesAction.of.FetchUnclaimedLicensesSuccess,127 ),128 ),129 T.catchAll((err) =>130 pipe(131 err,132 matchError,133 payload,134 UnclaimedLicensesAction.of.FetchUnclaimedLicensesFailure,135 T.succeed,136 ),137 ),138 ),139 ),140 S.merge(141 S.succeed(142 UnclaimedLicensesAction.of.FetchUnclaimedLicensesInflight({}),143 ),144 ),145 )146 : S.empty,147 ),148 )149export const fetchClaimedLicenses = (150 action$: S.UIO<ClaimedLicensesAction>,151 state$: S.UIO<AppState>152): S.UIO<Action> =>153 pipe(154 zipSources(action$, state$),155 S.chain(([a, state]) =>156 ClaimedLicensesAction.is.FetchClaimedLicenses(a)157 ? pipe(158 filterAccessToken(state.auth),159 S.mapM((accessToken) =>160 pipe(161 getClaimedLicenses(accessToken),162 T.map((unclaimedLicenses) =>163 pipe(164 unclaimedLicenses,165 payload,166 ClaimedLicensesAction.of.FetchClaimedLicensesSuccess,167 ),168 ),169 T.catchAll((err) =>170 pipe(171 err,172 matchError,173 payload,174 ClaimedLicensesAction.of.FetchClaimedLicensesFailure,175 T.succeed,176 ),177 ),178 ),179 ),180 S.merge(181 S.succeed(182 ClaimedLicensesAction.of.FetchClaimedLicensesInflight({}),183 ),184 ),185 )186 : S.empty,187 ),188 )189export const claimLicenseForm = (190 action$: S.UIO<ClaimLicenseFormAction>,191 state$: S.UIO<AppState>192): S.UIO<Action> =>193 pipe(194 zipSources(action$, state$),195 S.chain(([a, state]) =>196 ClaimLicenseFormAction.is.ClaimLicenseFormSubmit(a)197 ? pipe(198 filterAccessToken(state.auth),199 S.chain((accessToken) =>200 pipe(201 claimLicense(accessToken, a.payload),202 T.map((claimedLicense) =>203 [204 pipe(205 claimedLicense,206 payload,207 ClaimLicenseFormAction.of.ClaimLicenseFormSuccess,208 ),209 pipe(210 { claimedLicenses: [claimedLicense] },211 payload,212 ClaimedLicensesAction.of.FetchClaimedLicensesSuccess,213 )214 ]215 ),216 T.catchAll((err) =>217 pipe(218 err,219 matchError,220 payload,221 ClaimLicenseFormAction.of.ClaimLicenseFormFailure,222 Array.of,223 T.succeed,224 ),225 ),226 S.fromEffect,227 S.mapConcat((as) => as),228 ),229 ),230 S.merge(231 S.succeed(232 ClaimLicenseFormAction.of.ClaimLicenseFormInflight({}),233 ),234 ),235 )236 : S.empty,237 ),238 )239export const createLicenseForm = (240 action$: S.UIO<CreateLicenseFormAction>,241 state$: S.UIO<AppState>242): S.UIO<CreateLicenseFormAction | UnclaimedLicensesAction> =>243 pipe(244 zipSources(action$, state$),245 S.chain(([a, state]) =>246 CreateLicenseFormAction.is.CreateLicenseFormSubmit(a)247 ? pipe(248 filterAccessToken(state.auth),249 S.chain((accessToken) =>250 pipe(251 createUnlaimedLicense(accessToken, a.payload),252 T.map((unclaimedLicense) =>253 [254 pipe(255 unclaimedLicense,256 payload,257 CreateLicenseFormAction.of.CreateLicenseFormSuccess,258 ),...
sceneDownload.js
Source:sceneDownload.js
1/**2 * Created by zyg on 16/2/17.3 */4var ObjectId = require('mongodb').ObjectID;5var Scene = require('../models/Scene');6var buildMaterialZipSource = require('../services/buildMaterialZipSource');7var archiverZip = require('../services/archiverDownloadZip');8var MaterialZip = require('../models/MaterialZip');9module.exports = function (req,res,next) {10 var id = req.query.id || req.query._id;11 var sceneTitle = req.query.sceneTitle;12 var query = {};13 if(id){14 query = {15 _id:ObjectId(id)16 }17 }else if(sceneTitle){18 query = {19 sceneTitle20 }21 }else{22 return next(new Error('no id or title'));23 }24 var spriteNames = [];25 Scene.findOne(query).then((scene)=>{26 var viewData = scene.viewData;27 sceneTitle = scene.sceneTitle;28 viewData = JSON.parse(viewData);29 viewData = viewData.map(container=>{30 return container.children;31 }).reduce((pre,next)=>{32 return pre.concat(next);33 },[]);34 return Promise.all(viewData.map(sprite=>{35 spriteNames.push(sprite.name);36 return buildMaterialZipSource(sprite);37 }));38 }).then(zipSources=>{39 return Promise.all(zipSources.map((zipSource,i)=>{40 return archiverZip(`${spriteNames[i]}.zip`,zipSource);41 }));42 }).then(zipPaths=>{43 var sceneZipSource = zipPaths.map((zipPath,i)=>{44 return {45 [`${spriteNames[i]}.zip`]:zipPath46 }47 }).reduce((pre,next)=>{48 return Object.assign(pre,next);49 },{});50 return archiverZip(`${sceneTitle}.zip`,sceneZipSource)51 }).then(sceneZipPath=>{52 res.download(53 sceneZipPath,54 `${sceneTitle}.zip`55 )56 }).catch((e)=>{57 next(e);58 });...
ZipSources.js
Source:ZipSources.js
1import JSZip from 'jszip';2import FileSaver from 'file-saver';3const ZipSources = async (files, name) => {4 const withoutLeadingSlash = (file) => {5 return file.replace(/^\//, '')6 };7 const zip = new JSZip();8 for (const file in files) {9 const d = files[file];10 if (typeof(d) === "string") {11 zip.file(withoutLeadingSlash(file), d);12 }13 }14 const content = await zip.generateAsync({ type: "blob" });15 FileSaver.saveAs(content, `${name}.zip`);16}17export {18 ZipSources19}...
Using AI Code Generation
1import { zipSources } from '@redwoodjs/api'2export const handler = async () => {3 const sources = await zipSources({4 })5 return {6 headers: {7 'Content-Disposition': 'attachment; filename="redwood-app.zip"',8 },9 }10}11import archiver from 'archiver'12import fs from 'fs'13import glob from 'glob'14import path from 'path'15const zipSources = async ({ include = [], exclude = [] }) => {16 const archive = archiver('zip', { zlib: { level: 9 } })17 archive.on('error', (err) => {18 })19 const files = await Promise.all(20 include.map((dir) => {21 return new Promise((resolve, reject) => {22 glob(23 path.join(process.cwd(), dir, '/**/*'),24 { ignore: exclude },25 (err, files) => {26 if (err) {27 reject(err)28 } else {29 resolve(files)30 }31 }32 })33 })34 files.flat().forEach((file) => {35 const relativePath = path.relative(process.cwd(), file)36 archive.file(file, { name: relativePath })37 })38 archive.finalize()39 return new Promise((resolve) => {40 archive.on('data', (d) => {41 bufs.push(d)42 })43 archive.on('end', () => {44 const buf = Buffer.concat(bufs)45 resolve(buf.toString('base64'))46 })47 })48}49export { zipSources }50export const zipSources = () => {51 return async (context) => {52 }53}54 type Query {55 }
Using AI Code Generation
1import { zipSources } from '@redwoodjs/api'2export const handler = async (event, context) => {3 const source = await zipSources({4 })5 return {6 headers: {7 'Content-Disposition': 'attachment; filename="source.zip"',8 },9 }10}
Using AI Code Generation
1import { zipSources } from '@redwoodjs/api/dist/zipSources'2import path from 'path'3export const handler = async (event, context) => {4 const zipPath = path.join('/tmp', 'test.zip')5 await zipSources(zipPath, ['src'])6 return {7 body: JSON.stringify({8 }),9 }10}11 "scripts": {12 },13import { zipSources } from '@redwoodjs/api/dist/zipSources'14import path from 'path'15export const handler = async (event, context) => {16 const zipPath = path.join('/tmp', 'test.zip')17 await zipSources(zipPath, ['src'])18 return {19 body: JSON.stringify({20 }),21 }22}23import { zipSources } from '@redwoodjs/api/dist/zipSources'24import path from 'path'25export const handler = async (event, context) => {26 const zipPath = path.join('/tmp', 'test.zip')27 await zipSources(zipPath, ['src'])28 return {29 body: JSON.stringify({30 }),31 }32}33import { zipSources } from '@redwoodjs/api/dist/zipSources'34import path from 'path'
Using AI Code Generation
1import { zipSources } from '@redwoodjs/api'2import path from 'path'3export const handler = async (event, context) => {4 const srcPath = path.join(__dirname, '../api/src')5 const zip = await zipSources(srcPath)6 return {7 headers: {8 'Content-Disposition': 'attachment; filename=sources.zip',9 },10 body: zip.toString('base64'),11 }12}13import { createWriteStream } from 'fs'14import archiver from 'archiver'15const zip = archiver('zip', {16})17const output = createWriteStream('sources.zip')18output.on('close', () => {19 console.log(`Zip file created with ${zip.pointer()} total bytes`)20})21zip.on('error', (err) => {22})23zip.pipe(output)24zip.directory(srcPath, false)25zip.finalize()26import { createWriteStream } from 'fs'27import archiver from 'archiver'28const zip = archiver('zip', {
Using AI Code Generation
1const { zipSources } = require('@redwoodjs/internal')2const main = async () => {3 const zip = await zipSources({4 })5 console.log(zip)6}7main()
Using AI Code Generation
1const { zipSources } = require('@redwoodjs/api/dist/zip')2const fs = require('fs')3const zip = await zipSources({4 onFile: (filePath) => {5 console.log(`Zipping ${filePath}`)6 },7})8fs.writeFileSync('dist.zip', zip)
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!