36 lines
839 B
JavaScript
36 lines
839 B
JavaScript
const State = require('../State')
|
|
|
|
class FileState extends State {
|
|
async apply() {
|
|
if ( !(await this.check()) ) {
|
|
const path = await this._path()
|
|
await path.touch()
|
|
|
|
if ( this._config.contents ) {
|
|
await path.echo(this._config.contents)
|
|
} else if ( this._config.template ) {
|
|
await path.copy_from(this._config.template)
|
|
}
|
|
}
|
|
}
|
|
|
|
async check() {
|
|
const path = await this._path()
|
|
await path.classify()
|
|
return path.is_file()
|
|
}
|
|
|
|
async reverse() {
|
|
if ( await this.check() ) {
|
|
const path = await this._path()
|
|
await path.unlink()
|
|
}
|
|
}
|
|
|
|
async _path() {
|
|
return this._host.get_path(this._config.path)
|
|
}
|
|
}
|
|
|
|
module.exports = exports = FileState
|