Add yarn install state
This commit is contained in:
parent
ba8119903e
commit
1511ec76fb
43
app/classes/state/node/YarnInstallState.js
Normal file
43
app/classes/state/node/YarnInstallState.js
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
const State = require('../State')
|
||||||
|
|
||||||
|
class YarnInstallState extends State {
|
||||||
|
#ran_once = false
|
||||||
|
|
||||||
|
static get services() {
|
||||||
|
return [...super.services, 'output']
|
||||||
|
}
|
||||||
|
|
||||||
|
async apply() {
|
||||||
|
const cmd = `cd "${this._config.path}" && yarn install`
|
||||||
|
await this._host.run(cmd)
|
||||||
|
this.#ran_once = true
|
||||||
|
}
|
||||||
|
|
||||||
|
async check() {
|
||||||
|
if ( this._config.force ) return this.#ran_once
|
||||||
|
else {
|
||||||
|
const node_modules = this._host.get_path(`${this._config.path}/node_modules`)
|
||||||
|
await node_modules.classify()
|
||||||
|
return node_modules.is_directory()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async reverse() {
|
||||||
|
const node_modules = this._host.get_path(`${this._config.path}/node_modules`)
|
||||||
|
await node_modules.unlink()
|
||||||
|
}
|
||||||
|
|
||||||
|
failure_message() {
|
||||||
|
return `The Yarn packages at ${this._config.path} need to be installed.`
|
||||||
|
}
|
||||||
|
|
||||||
|
check_message() {
|
||||||
|
return this.failure_message()
|
||||||
|
}
|
||||||
|
|
||||||
|
display() {
|
||||||
|
return `Ensure that the Yarn packages at ${this._config.path} are installed...`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = exports = YarnInstallState
|
@ -41,6 +41,8 @@ class StatesService extends Service {
|
|||||||
'service.daemon.reloaded': require('../classes/state/os/ServiceDaemonReloadState'),
|
'service.daemon.reloaded': require('../classes/state/os/ServiceDaemonReloadState'),
|
||||||
|
|
||||||
'web.download': require('../classes/state/fs/DownloadState'),
|
'web.download': require('../classes/state/fs/DownloadState'),
|
||||||
|
|
||||||
|
'node.yarn.installed': require('../classes/state/node/YarnInstallState'),
|
||||||
}
|
}
|
||||||
|
|
||||||
static get services() {
|
static get services() {
|
||||||
|
@ -152,6 +152,13 @@ const example_routine = {
|
|||||||
source: 'https://static.garrettmills.dev/assets/flitter/flitter_f.png',
|
source: 'https://static.garrettmills.dev/assets/flitter/flitter_f.png',
|
||||||
path: '/tmp/flitter_f.png',
|
path: '/tmp/flitter_f.png',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
// State: the packages for the given path are installed via Yarn
|
||||||
|
type: 'node.yarn.installed',
|
||||||
|
host: 'localhost',
|
||||||
|
path: '/home/user/path/to/project',
|
||||||
|
force: true, // default: false
|
||||||
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user