Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const pages = options.pages || { index: '' }
Object.keys(pages).forEach(page => {
if (pages[page].filename) {
// If page is configured as an object, use the filename (without .html)
page = pages[page].filename.replace(/\.html$/, '')
}
fs.writeFileSync(
path.join(bundleOutputDir, `legacy-assets-${page}.html.json`),
'[]'
)
})
// Set the base url so that the app protocol is used
options.baseUrl = pluginOptions.customFileProtocol || 'app://./'
// Set publicPath as well (replaced baseUrl since @vue/cli 3.3.0)
options.publicPath = pluginOptions.customFileProtocol || 'app://./'
info('Bundling render process:')
// Build the render process with the custom args
try {
await api.service.run('build', vueArgs)
} catch (e) {
error(
'Vue CLI build failed. Please resolve any issues with your build and try again.'
)
process.exit(1)
}
// Copy package.json to output dir
const pkg = JSON.parse(
fs.readFileSync(api.resolve('./package.json'), 'utf8')
)
const externals = getExternals(api, pluginOptions)
// https://github.com/nklayman/vue-cli-plugin-electron-builder/issues/223
// Strip non-externals from dependencies so they won't be copied into app.asar
function launchElectron () {
firstBundleCompleted = true
// Don't exit process when electron is killed
if (child) {
child.removeListener('exit', onChildExit)
}
// Kill existing instances
killElectron()
// Don't launch if a new background file is being bundled
queuedBuilds--
if (queuedBuilds > 0) return
if (args.debug) {
// Do not launch electron and provide instructions on launching through debugger
info(
'Not launching electron as debug argument was passed. You must launch electron through your debugger.'
)
info(
`If you are using Spectron, make sure to set the IS_TEST env variable to true.`
)
info(
'Learn more about debugging the main process at https://nklayman.github.io/vue-cli-plugin-electron-builder/guide/testingAndDebugging.html#debugging.'
)
} else if (args.headless) {
// Log information for spectron
console.log(`$outputDir=${outputDir}`)
console.log(`$WEBPACK_DEV_SERVER_URL=${server.url}`)
} else {
// Launch electron with execa
if (mainProcessArgs.length > 0) {
info(
}
// Kill existing instances
killElectron()
// Don't launch if a new background file is being bundled
queuedBuilds--
if (queuedBuilds > 0) return
if (args.debug) {
// Do not launch electron and provide instructions on launching through debugger
info(
'Not launching electron as debug argument was passed. You must launch electron through your debugger.'
)
info(
`If you are using Spectron, make sure to set the IS_TEST env variable to true.`
)
info(
'Learn more about debugging the main process at https://nklayman.github.io/vue-cli-plugin-electron-builder/guide/testingAndDebugging.html#debugging.'
)
} else if (args.headless) {
// Log information for spectron
console.log(`$outputDir=${outputDir}`)
console.log(`$WEBPACK_DEV_SERVER_URL=${server.url}`)
} else {
// Launch electron with execa
if (mainProcessArgs.length > 0) {
info(
'Launching Electron with arguments: "' +
mainProcessArgs.join(' ') +
' ' +
rawArgs.join(' ') +
'" ...'
)
async function createBucket (options) {
let createParams = {
Bucket: options.bucket,
ACL: options.acl
}
// Create bucket
try {
await S3.createBucket(createParams).promise()
} catch (createErr) {
error(`Bucket: ${options.bucket} could not be created. AWS Error: ${createErr.toString()}.`)
return false
}
info(`Bucket: ${options.bucket} created.`)
return true
}
}, async function serve (args) {
info('Starting development server...')
// although this is primarily a dev server, it is possible that we
// are running it in a mode with a production env, e.g. in E2E tests.
const isInContainer = checkInContainer()
const isProduction = process.env.NODE_ENV === 'production'
const url = require('url')
const path = require('path')
const chalk = require('chalk')
const webpack = require('webpack')
const WebpackDevServer = require('webpack-dev-server')
const portfinder = require('portfinder')
const prepareURLs = require('../util/prepareURLs')
const prepareProxy = require('../util/prepareProxy')
const launchEditorMiddleware = require('launch-editor-middleware')
const validateWebpackConfig = require('../util/validateWebpackConfig')
info(`(${uploadCount}/${uploadTotal}) Uploaded ${fullFileKey}${pwaStr}`)
// resolve()
})
.catch((e) => {
error(`Upload failed: ${fullFileKey}`)
error(e.toString())
// reject(e)
})
}
const uploadPool = new PromisePool(nextFile, parseInt(options.uploadConcurrency, 10))
try {
await uploadPool.start()
info('Deployment complete.')
if (options.enableCloudfront) {
invalidateDistribution(options)
}
} catch (uploadErr) {
error(`Deployment completed with errors.`)
error(`${uploadErr.toString()}`)
}
}
// It's probably a permissions issue in AWS.
await this.bucket.createBucket()
if (this.options.staticHosting) await bucket.enableHosting()
}
info(`Deploying ${this.config.fileList.length} assets from ${this.config.fullAssetPath} to ${this.config.remotePath}`)
this.uploadCount = 0
this.uploadTotal = this.config.fileList.length
const uploadPool = new PromisePool(this.uploadNextFile.bind(this), parseInt(this.config.options.uploadConcurrency, 10))
try {
await uploadPool.start()
info('Deployment complete.')
if (this.config.options.enableCloudfront) {
this.invalidateDistribution()
}
} catch (uploadErr) {
error(`Deployment encountered errors.`)
throw new Error(`Upload error: ${uploadErr.toString()}`)
}
}
function buildApp () {
info('Building app with electron-builder:')
// Build the app using electron builder
builder
.build(
merge({
config: merge(
defaultBuildConfig,
// User-defined config overwrites defaults
userBuildConfig
),
// Args parsed with yargs
...builderArgs
})
)
.then(() => {
// handle result
done('Build complete!')
Paths: {
Quantity: invalidationItems.length,
Items: invalidationItems
}
}
}
try {
logWithSpinner(`Invalidating CloudFront distribution: ${this.config.options.cloudfrontId}`)
let data = await cloudfront.createInvalidation(params).promise()
info(`Invalidation ID: ${data['Invalidation']['Id']}`)
info(`Status: ${data['Invalidation']['Status']}`)
info(`Call Reference: ${data['Invalidation']['InvalidationBatch']['CallerReference']}`)
info(`See your AWS console for on-going status on this invalidation.`)
stopSpinner()
} catch (err) {
stopSpinner(false)
error('Cloudfront Error!!')
error(`Code: ${err.code}`)
error(`Message: ${err.message}`)
error(`AWS Request ID: ${err.requestId}`)
throw new Error('Cloudfront invalidation failed!')
}
}
}
async function bucketExists (options) {
let headParams = { Bucket: options.bucket }
let bucketExists = false
try {
bucketExists = await S3.headBucket(headParams).promise()
info(`Bucket: ${options.bucket} exists.`)
} catch (headErr) {
let errStr = headErr.toString().toLowerCase()
if (errStr.indexOf('forbidden') > -1) {
error(`Bucket: ${options.bucket} exists, but you do not have permission to access it.`)
} else if (errStr.indexOf('notfound') > -1) {
if (options.createBucket) {
info(`Bucket: ${options.bucket} does not exist, attempting to create.`)
bucketExists = await createBucket(options)
} else {
error(`Bucket: ${options.bucket} does not exist.`)
}
} else {
error(`Could not verify that bucket ${options.bucket} exists. AWS Error: ${headErr}.`)
}
}