mirror of
https://github.com/serverless/serverless.git
synced 2025-12-08 19:46:03 +00:00
35 lines
823 B
JavaScript
35 lines
823 B
JavaScript
'use strict'
|
|
|
|
const path = require('path')
|
|
const fse = require('fs-extra')
|
|
|
|
// mock to test functionality bound to a serverless plugin
|
|
class ServerlessPlugin {
|
|
constructor(serverless, options, testSubject) {
|
|
this.options = options
|
|
this.serverless = serverless
|
|
|
|
Object.assign(this, testSubject)
|
|
}
|
|
}
|
|
|
|
function installPlugin(installDir, PluginClass) {
|
|
const pluginPkg = { name: path.basename(installDir), version: '0.0.0' }
|
|
const className = new PluginClass().constructor.name
|
|
fse.outputFileSync(
|
|
path.join(installDir, 'package.json'),
|
|
JSON.stringify(pluginPkg),
|
|
'utf8',
|
|
)
|
|
fse.outputFileSync(
|
|
path.join(installDir, 'index.js'),
|
|
`"use strict";\n${PluginClass.toString()}\nmodule.exports = ${className}`,
|
|
'utf8',
|
|
)
|
|
}
|
|
|
|
module.exports = {
|
|
ServerlessPlugin,
|
|
installPlugin,
|
|
}
|