How to use the @serverless/core.utils.dirExists function in @serverless/core

To help you get started, we’ve selected a few @serverless/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github serverless-components / tencent-cos / serverless.js View on Github external
const appId = await this.getAppid(tencent)
      this.context.credentials.tencent.AppId = appId.AppId
    }

    const bucket = this.state.bucket || inputs.bucket
    const region = this.state.region || inputs.region || 'ap-guangzhou'

    if (!bucket) {
      throw Error('Unable to upload. Bucket name not found in state.')
    }

    this.context.debug(`Starting upload to bucket ${bucket} in region ${region}`)

    const clients = getSdk(this.context.credentials.tencent)

    if (inputs.dir && (await utils.dirExists(inputs.dir))) {
      this.context.debug(`Uploading directory ${inputs.dir} to bucket ${bucket}`)
      // upload directory contents

      const options = { keyPrefix: inputs.keyPrefix }

      const items = await new Promise((resolve, reject) => {
        try {
          resolve(klawSync(inputs.dir))
        } catch (error) {
          reject(error)
        }
      })

      let handler
      let key
      const uploadItems = []
github serverless-components / aws-lambda / serverless.js View on Github external
service: 'lambda.amazonaws.com',
        policy: {
          arn: 'arn:aws:iam::aws:policy/AdministratorAccess'
        },
        region: config.region
      })
      config.role = { arn: outputsAwsIamRole.arn }
    } else {
      outputsAwsIamRole = await awsIamRole(config.role)
      config.role = { arn: outputsAwsIamRole.arn }
    }

    if (
      config.bucket &&
      config.runtime === 'nodejs10.x' &&
      (await utils.dirExists(path.join(config.code, 'node_modules')))
    ) {
      this.context.debug(`Bucket ${config.bucket} is provided for lambda ${config.name}.`)

      const layer = await this.load('@serverless/aws-lambda-layer')

      const layerInputs = {
        description: `${config.name} Dependencies Layer`,
        code: path.join(config.code, 'node_modules'),
        runtimes: ['nodejs10.x'],
        prefix: 'nodejs/node_modules',
        bucket: config.bucket,
        region: config.region
      }

      this.context.status('Deploying Dependencies')
      this.context.debug(`Packaging lambda code from ${config.code}.`)