1 | ;
|
2 | /*
|
3 | * @adonisjs/sink
|
4 | *
|
5 | * (c) Harminder Virk <virk@adonisjs.com>
|
6 | *
|
7 | * For the full copyright and license information, please view the LICENSE
|
8 | * file that was distributed with this source code.
|
9 | */
|
10 | Object.defineProperty(exports, "__esModule", { value: true });
|
11 | exports.File = void 0;
|
12 | /**
|
13 | * Base file exposes the API to add action and `cd` in/out from
|
14 | * the application base directory.
|
15 | */
|
16 | class File {
|
17 | constructor(basePath) {
|
18 | this.basePath = basePath;
|
19 | }
|
20 | /**
|
21 | * Add a new action to the actions stack. The action workings
|
22 | * are independent on the user adding the action
|
23 | */
|
24 | addAction(action, body) {
|
25 | this.actions.push({ action, body });
|
26 | }
|
27 | /**
|
28 | * Returns an array of actions to commit
|
29 | */
|
30 | getCommitActions() {
|
31 | return this.actions;
|
32 | }
|
33 | /**
|
34 | * Returns an array of actions for performing revert. Since
|
35 | * reverts are done in reverse, this method will reverse
|
36 | * the actions array.
|
37 | */
|
38 | getRevertActions() {
|
39 | return this.actions.slice().reverse();
|
40 | }
|
41 | /**
|
42 | * `cd` to the application base path
|
43 | */
|
44 | cdIn() {
|
45 | this.currentDir = process.cwd();
|
46 | process.chdir(this.basePath);
|
47 | }
|
48 | /**
|
49 | * `cd` out from the application base path
|
50 | */
|
51 | cdOut() {
|
52 | process.chdir(this.currentDir);
|
53 | }
|
54 | }
|
55 | exports.File = File;
|