-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpin.ts
52 lines (40 loc) · 1.51 KB
/
pin.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import {CliUx, Command, Flags} from '@oclif/core'
import chalk = require('chalk');
import {writeJson} from 'fs-extra'
import {join, resolve} from 'node:path'
import createDebug = require('debug')
import {lockfile} from '../../helpers/lockfile'
import {findRoot} from '../../helpers/workspace'
export default class WorkspacePin extends Command {
static description =
'Write a lock-file to pin module versions ({italic workspace-lock.json})';
static examples = [
'gooey-cli workspace:pin',
'gooey-cli workspace:pin --exact --lockfile=terasology.lock',
];
static flags = {
lockfile: Flags.string({
char: 'o',
description: 'the lockfile for pinning/restoring a workspace',
}),
exact: Flags.boolean({
description: 'pin the commit SHA instead of symbolic ref',
}),
};
static args = [];
public async run(): Promise<void> {
const debug = createDebug('workspace:load')
const {flags} = await this.parse(WorkspacePin)
const root = await findRoot(process.cwd())
const dest = flags.lockfile ?? join(root, 'workspace-lock.json')
CliUx.ux.action.start(chalk.dim`computing lockfile for workspace`)
const lock = await lockfile(root, {exact: flags.exact})
debug(JSON.stringify(lock, null, 2))
CliUx.ux.action.stop()
CliUx.ux.action.start(chalk.dim`writing workspace lockfile`)
this.debug(JSON.stringify(lock, null, 2))
await writeJson(dest, lock, {spaces: 2})
CliUx.ux.action.stop()
this.log('\tfile:' + resolve(process.cwd(), dest))
}
}