@travetto/scaffold 3.0.4 → 3.1.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/scaffold",
3
- "version": "3.0.4",
3
+ "version": "3.1.0-rc.0",
4
4
  "description": "App Scaffold for the Travetto framework",
5
5
  "keywords": [
6
6
  "generator",
@@ -27,9 +27,9 @@
27
27
  "trv-scaffold": "./bin/trv-scaffold.js"
28
28
  },
29
29
  "dependencies": {
30
- "@travetto/base": "^3.0.3",
31
- "@travetto/compiler": "^3.0.3",
32
- "@travetto/cli": "^3.0.3",
30
+ "@travetto/base": "^3.1.0-rc.0",
31
+ "@travetto/compiler": "^3.1.0-rc.0",
32
+ "@travetto/cli": "^3.1.0-rc.0",
33
33
  "enquirer": "^2.3.6",
34
34
  "mustache": "^4.2.0"
35
35
  },
@@ -7,7 +7,6 @@
7
7
  // {{#dependencies}}
8
8
  "{{{.}}}": "^{{{frameworkVersion}}}",
9
9
  // {{/dependencies}}
10
- "@travetto/app": "^{{{frameworkVersion}}}",
11
10
  "@travetto/cli": "^{{{frameworkVersion}}}"
12
11
  },
13
12
  "devDependencies": {
@@ -1,37 +1,25 @@
1
1
  import enquirer from 'enquirer';
2
2
 
3
3
  import { path } from '@travetto/manifest';
4
- import { CliCommand, cliTpl, OptionConfig } from '@travetto/cli';
4
+ import { CliCommandShape, CliCommand, cliTpl } from '@travetto/cli';
5
5
  import { GlobalTerminal } from '@travetto/terminal';
6
6
 
7
7
  import { Context } from './bin/context';
8
8
  import { Feature, FEATURES } from './bin/features';
9
9
 
10
- type Options = {
11
- template: OptionConfig<string>;
12
- cwd: OptionConfig<string>;
13
- dir: OptionConfig<string>;
14
- force: OptionConfig<boolean>;
15
- };
16
-
17
10
  /**
18
11
  * Command to run scaffolding
19
12
  */
20
- export class ScaffoldCommand extends CliCommand<Options> {
21
- name = 'scaffold';
22
-
23
- getOptions(): Options {
24
- return {
25
- template: this.option({ def: 'todo', desc: 'Template' }),
26
- cwd: this.option({ desc: 'Current Working Directory override' }),
27
- dir: this.option({ desc: 'Target Directory' }),
28
- force: this.boolOption({ desc: 'Force writing into an existing directory', def: false })
29
- };
30
- }
31
-
32
- getArgs(): string {
33
- return '[name]';
34
- }
13
+ @CliCommand()
14
+ export class ScaffoldCommand implements CliCommandShape {
15
+ /** Template */
16
+ template = 'todo';
17
+ /** Current Working Directory override */
18
+ cwd: string = path.cwd();
19
+ /** Target Directory */
20
+ dir?: string;
21
+ /** Force writing into an existing directory */
22
+ force = false;
35
23
 
36
24
  async #getName(name?: string): Promise<string> {
37
25
  if (!name) {
@@ -88,42 +76,25 @@ export class ScaffoldCommand extends CliCommand<Options> {
88
76
  }
89
77
  }
90
78
 
91
- async action(name?: string): Promise<void> {
92
- try {
93
- name = await this.#getName(name);
94
- } catch (err) {
95
- if (err instanceof Error) {
96
- console.error('Failed to provide correct input', err.message);
97
- }
98
- return this.exit(1);
99
- }
100
-
101
- this.cmd.cwd ??= path.cwd();
79
+ async main(name?: string): Promise<void> {
80
+ name = await this.#getName(name);
102
81
 
103
- if (!name && this.cmd.dir) {
104
- name = path.basename(this.cmd.dir);
105
- } else if (name && !this.cmd.dir) {
106
- this.cmd.dir = path.resolve(this.cmd.cwd, name);
107
- } else if (!name && !this.cmd.dir) {
108
- console.error('Either a name or a target directory are required');
109
- return this.exit(1);
82
+ if (!name && this.dir) {
83
+ name = path.basename(this.dir);
84
+ } else if (name && !this.dir) {
85
+ this.dir = path.resolve(this.cwd, name);
86
+ } else if (!name && !this.dir) {
87
+ throw new Error('Either a name or a target directory are required');
110
88
  }
111
89
 
112
- const ctx = new Context(name, this.cmd.template, path.resolve(this.cmd.cwd, this.cmd.dir));
90
+ const ctx = new Context(name, this.template, path.resolve(this.cwd, this.dir!));
113
91
 
114
- if (!this.cmd.force) {
92
+ if (!this.force) {
115
93
  await ctx.initialize();
116
94
  }
117
95
 
118
- try {
119
- for await (const feature of this.#resolveFeatures(FEATURES)) {
120
- await ctx.resolveFeature(feature);
121
- }
122
- } catch (err) {
123
- if (err instanceof Error) {
124
- console.error('Failed to provide correct input', err.message);
125
- }
126
- return this.exit(1);
96
+ for await (const feature of this.#resolveFeatures(FEATURES)) {
97
+ await ctx.resolveFeature(feature);
127
98
  }
128
99
 
129
100
  console.log(cliTpl`\n${{ title: 'Creating Application' }}\n${'-'.repeat(30)}`);