Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
for (const depType of ['dependencies', 'devDependencies', 'optionalDependencies']) {
if (this.pkg[depType] && this.pkg[depType][packageName]) {
depEntry = depType
required = this.pkg[depType][packageName]
break
}
}
if (!required) {
throw new Error(`Can't find ${chalk.yellow(packageName)} in ${chalk.yellow('package.json')}`)
}
let targetVersion = options.to || 'latest'
// if the targetVersion is not an exact version
if (!/\d+\.\d+\.\d+/.test(targetVersion)) {
if (targetVersion === 'latest') {
logWithSpinner(`Getting latest version of ${packageName}`)
} else {
logWithSpinner(`Getting max satisfying version of ${packageName}@${options.to}`)
}
targetVersion = await this.pm.getRemoteVersion(packageName, targetVersion)
if (!options.to && options.next) {
const next = await this.pm.getRemoteVersion(packageName, 'next')
if (next) {
targetVersion = semver.gte(targetVersion, next) ? targetVersion : next
}
}
stopSpinner()
}
const installed = this.pm.getInstalledVersion(packageName)
if (targetVersion === installed) {
async resolvePreset (name, clone) {
let preset
const savedPresets = loadOptions().presets || {}
if (name in savedPresets) {
preset = savedPresets[name]
} else if (name.endsWith('.json') || /^\./.test(name) || path.isAbsolute(name)) {
preset = await loadLocalPreset(path.resolve(name))
} else if (name.includes('/')) {
logWithSpinner(`Fetching remote preset ${chalk.cyan(name)}...`)
this.emit('creation', { event: 'fetch-remote-preset' })
try {
preset = await loadRemotePreset(name, clone)
stopSpinner()
} catch (e) {
stopSpinner()
error(`Failed fetching remote preset ${chalk.cyan(name)}:`)
throw e
}
}
// use default preset if user has not overwritten it
if (name === 'default' && !preset) {
preset = defaults.presets.default
}
if (!preset) {
}
pkg.devDependencies[dep] = (
preset.plugins[dep].version ||
((/^@vue/.test(dep) && latest[dep]) ? `^${latest[dep]}` : `latest`)
)
})
// write package.json
await writeFileTree(context, {
'package.json': JSON.stringify(pkg, null, 2)
})
// intilaize git repository before installing deps
// so that vue-cli-service can setup git hooks.
const shouldInitGit = await this.shouldInitGit(cliOptions)
if (shouldInitGit) {
logWithSpinner(`π`, `Initializing git repository...`)
this.emit('creation', { event: 'git-init' })
await run('git init')
}
// install plugins
stopSpinner()
log(`β Installing CLI plugins. This might take a while...`)
log()
this.emit('creation', { event: 'plugins-install' })
if (isTestOrDebug) {
// in development, avoid installation process
await require('./util/setupDevProject')(context) // @vue/cli-service/bin/vue-cli-service
} else {
await installDeps(context, packageManager, cliOptions.registry)
}
const newDeps = generator.pkg.dependencies
const newDevDeps = generator.pkg.devDependencies
const depsChanged =
JSON.stringify(newDeps) !== JSON.stringify(pkg.dependencies) ||
JSON.stringify(newDevDeps) !== JSON.stringify(pkg.devDependencies)
if (!isTestOrDebug && depsChanged) {
log(`π¦ Installing additional dependencies...`)
log()
const packageManager =
loadOptions().packageManager || (hasProjectYarn(context) ? 'yarn' : 'npm')
await installDeps(context, packageManager, plugin.options && plugin.options.registry)
}
if (createCompleteCbs.length) {
logWithSpinner('β', `Running completion hooks...`)
for (const cb of createCompleteCbs) {
await cb()
}
stopSpinner()
log()
}
log(`${chalk.green('β')} Successfully invoked generator for plugin: ${chalk.cyan(plugin.id)}`)
// εεΊεͺδΊζδ»ΆεηδΊζΉε
if (!process.env.VUE_CLI_TEST && hasProjectGit(context)) {
const { stdout } = await execa('git', [
'ls-files',
'--exclude-standard',
'--modified',
'--others'
], {
} = require('@vue/cli-shared-utils')
log()
const mode = api.service.mode
if (args.target === 'app') {
const bundleTag = args.modern
? args.modernBuild
? `modern bundle `
: `legacy bundle `
: ``
logWithSpinner(`Building ${bundleTag}for ${mode}...`)
} else {
const buildMode = buildModes[args.target]
if (buildMode) {
const additionalParams = buildMode === 'library' ? ` (${args.formats})` : ``
logWithSpinner(`Building for ${mode} as ${buildMode}${additionalParams}...`)
} else {
throw new Error(`Unknown build target: ${args.target}`)
}
}
if (args.dest) {
// Override outputDir before resolving webpack config as config relies on it (#2327)
options.outputDir = args.dest
}
const targetDir = api.resolve(options.outputDir)
const isLegacyBuild = args.target === 'app' && args.modern && !args.modernBuild
// resolve raw webpack config
let webpackConfig
if (args.target === 'lib') {
async function invalidateDistribution (options) {
const cloudfront = new AWS.CloudFront()
const invalidationItems = options.cloudfrontMatchers.split(',')
let params = {
DistributionId: options.cloudfrontId,
InvalidationBatch: {
CallerReference: `vue-cli-plugin-s3-deploy-${Date.now().toString()}`,
Paths: {
Quantity: invalidationItems.length,
Items: invalidationItems
}
}
}
logWithSpinner(`Invalidating CloudFront distribution: ${options.cloudfrontId}`)
try {
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.`)
} catch (err) {
error('Cloudfront Error!')
error(`Code: ${err.code}`)
error(`Message: ${err.message}`)
error(`AWS Request ID: ${err.requestId}`)
}
stopSpinner()
const newDeps = generator.pkg.dependencies
const newDevDeps = generator.pkg.devDependencies
const depsChanged =
JSON.stringify(newDeps) !== JSON.stringify(pkg.dependencies) ||
JSON.stringify(newDevDeps) !== JSON.stringify(pkg.devDependencies)
if (!isTestOrDebug && depsChanged) {
log(`π¦ Installing additional dependencies...`)
log()
const pm = new PackageManager({ context })
await pm.install()
}
if (afterInvokeCbs.length || afterAnyInvokeCbs.length) {
logWithSpinner('β', `Running completion hooks...`)
for (const cb of afterInvokeCbs) {
await cb()
}
for (const cb of afterAnyInvokeCbs) {
await cb()
}
stopSpinner()
log()
}
log(`${chalk.green('β')} Successfully invoked generator for plugin: ${chalk.cyan(plugin.id)}`)
if (!process.env.VUE_CLI_TEST && hasProjectGit(context)) {
const { stdout } = await execa('git', [
'ls-files',
'--exclude-standard',
'--modified',
const cloudfront = new AWS.CloudFront()
const invalidationItems = this.config.options.cloudfrontMatchers.split(',')
let params = {
DistributionId: this.config.options.cloudfrontId,
InvalidationBatch: {
CallerReference: `vue-cli-plugin-s3-deploy-${Date.now().toString()}`,
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}`)
WebsiteConfiguration: {
ErrorDocument: {
Key: this.options.staticErrorPage
},
IndexDocument: {
Suffix: this.options.staticIndexPage
}
}
}
if (this.options.staticWebsiteConfiguration) {
params.WebsiteConfiguration = this.options.staticWebsiteConfiguration
}
try {
logWithSpinner('Bucket: enabling static hosting...')
await this.connection.putBucketWebsite(params).promise()
stopSpinner()
} catch (e) {
error(`Static hosting could not be enabled on bucket: ${this.name}`)
throw new Error(`AWS Error: ${e.toString()}`)
}
}