@quenty/nevermore-cli 1.2.0 → 1.2.1-canary.314.3173efb.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/CHANGELOG.md CHANGED
@@ -3,6 +3,22 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.2.1-canary.314.3173efb.0](https://github.com/Quenty/Nevermore/compare/@quenty/nevermore-cli@1.2.0...@quenty/nevermore-cli@1.2.1-canary.314.3173efb.0) (2022-12-27)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * Ignore distribution from nevermore-cli folder ([02a2297](https://github.com/Quenty/Nevermore/commit/02a2297065478bf0d457463cdf46719fe564efcc))
12
+
13
+
14
+ ### Features
15
+
16
+ * Add ability to generate new Nevermore library packages ([e0e8e44](https://github.com/Quenty/Nevermore/commit/e0e8e44a21692d4c383274985d01a965dcfe389c))
17
+
18
+
19
+
20
+
21
+
6
22
  # [1.2.0](https://github.com/Quenty/Nevermore/compare/@quenty/nevermore-cli@1.1.0...@quenty/nevermore-cli@1.2.0) (2022-11-21)
7
23
 
8
24
 
@@ -14,7 +14,6 @@ export declare class InitGameCommand<T> implements CommandModule<T, InitGameArgs
14
14
  describe: string;
15
15
  builder(args: Argv<T>): Argv<InitGameArgs>;
16
16
  handler(args: InitGameArgs): Promise<void>;
17
- private static _createDirectoryContentsAsync;
18
17
  private static _runCommandAsync;
19
18
  private static _ensureGameName;
20
19
  private static _validateGameName;
@@ -1 +1 @@
1
- {"version":3,"file":"init-game-command.d.ts","sourceRoot":"","sources":["../../src/commands/init-game-command.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAK5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAM1D,MAAM,WAAW,YAAa,SAAQ,mBAAmB;IACvD,QAAQ,EAAE,MAAM,CAAC;CAClB;AAaD;;GAEG;AACH,qBAAa,eAAe,CAAC,CAAC,CAAE,YAAW,aAAa,CAAC,CAAC,EAAE,YAAY,CAAC;IAChE,OAAO,SAAsB;IAC7B,QAAQ,SACiE;IAEzE,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IAef,OAAO,CAAC,IAAI,EAAE,YAAY;mBA8DlB,6BAA6B;mBA6D7B,gBAAgB;mBA+BhB,eAAe;IAYpC,OAAO,CAAC,MAAM,CAAC,iBAAiB;CAKjC"}
1
+ {"version":3,"file":"init-game-command.d.ts","sourceRoot":"","sources":["../../src/commands/init-game-command.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAI5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAG1D,MAAM,WAAW,YAAa,SAAQ,mBAAmB;IACvD,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,qBAAa,eAAe,CAAC,CAAC,CAAE,YAAW,aAAa,CAAC,CAAC,EAAE,YAAY,CAAC;IAChE,OAAO,SAAsB;IAC7B,QAAQ,SACiE;IAEzE,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IASf,OAAO,CAAC,IAAI,EAAE,YAAY;mBA8DlB,gBAAgB;mBA+BhB,eAAe;IAYpC,OAAO,CAAC,MAAM,CAAC,iBAAiB;CASjC"}
@@ -37,22 +37,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
38
  exports.InitGameCommand = void 0;
39
39
  const path = __importStar(require("path"));
40
- const fs = __importStar(require("fs"));
41
- const Handlebars = __importStar(require("handlebars"));
42
- const helper_1 = require("../helper");
40
+ const cli_output_helpers_1 = require("@quenty/cli-output-helpers");
41
+ const nevermore_template_helpers_1 = require("@quenty/nevermore-template-helpers");
43
42
  const execa = require("execa");
44
- const util = __importStar(require("util"));
45
- const existsAsync = util.promisify(fs.exists);
46
- /**
47
- * Makes the string upper camel case
48
- */
49
- function camelize(str) {
50
- return str
51
- .replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
52
- return word.toUpperCase();
53
- })
54
- .replace(/\s+/g, '');
55
- }
56
43
  /**
57
44
  * Creates a new game with Nevermore dependencies
58
45
  */
@@ -67,26 +54,20 @@ class InitGameCommand {
67
54
  demandOption: false,
68
55
  type: 'string',
69
56
  });
70
- args.option('dryrun', {
71
- describe: 'Whether this run should be a dryrun.',
72
- demandOption: false,
73
- type: 'boolean',
74
- default: false,
75
- });
76
57
  return args;
77
58
  }
78
59
  handler(args) {
79
60
  return __awaiter(this, void 0, void 0, function* () {
80
61
  const rawGameName = yield InitGameCommand._ensureGameName(args);
81
- const gameName = camelize(rawGameName).toLowerCase();
82
- const gameNameProper = camelize(rawGameName);
62
+ const gameName = nevermore_template_helpers_1.TemplateHelper.camelize(rawGameName).toLowerCase();
63
+ const gameNameProper = nevermore_template_helpers_1.TemplateHelper.camelize(rawGameName);
83
64
  const srcRoot = process.cwd();
84
65
  const templatePath = path.join(__dirname, '..', '..', 'templates', 'game-template');
85
- helper_1.OutputHelper.info(`Creating a new game at '${srcRoot}' with template '${templatePath}'`);
86
- yield InitGameCommand._createDirectoryContentsAsync(templatePath, srcRoot, {
66
+ cli_output_helpers_1.OutputHelper.info(`Creating a new game at '${srcRoot}' with template '${templatePath}'`);
67
+ yield nevermore_template_helpers_1.TemplateHelper.createDirectoryContentsAsync(templatePath, srcRoot, {
87
68
  gameName: gameName,
88
69
  gameNameProper: gameNameProper,
89
- }, args);
70
+ }, args.dryrun);
90
71
  const packages = [
91
72
  '@quenty/loader',
92
73
  '@quenty/servicebag',
@@ -103,66 +84,17 @@ class InitGameCommand {
103
84
  });
104
85
  }
105
86
  catch (_a) {
106
- helper_1.OutputHelper.info('Failed to run `selene generate-roblox-std`, is selene installed?');
107
- }
108
- });
109
- }
110
- static _createDirectoryContentsAsync(templatePath, targetPath, input, args) {
111
- return __awaiter(this, void 0, void 0, function* () {
112
- // read all files/folders (1 level) from template folder
113
- const filesToCreate = yield fs.promises.readdir(templatePath);
114
- for (const originalName of filesToCreate) {
115
- const origFilePath = path.join(templatePath, originalName);
116
- if (originalName == 'ENSURE_FOLDER_CREATED') {
117
- continue;
118
- }
119
- const compiledName = Handlebars.default.compile(originalName);
120
- const newName = compiledName(input);
121
- const stats = yield fs.promises.stat(origFilePath);
122
- if (stats.isFile()) {
123
- // read file content and transform it using template engine
124
- const contents = yield fs.promises.readFile(origFilePath, 'utf8');
125
- const compiled = Handlebars.default.compile(contents);
126
- const result = compiled(input);
127
- const newFilePath = path.join(targetPath, newName);
128
- if (args.dryrun) {
129
- helper_1.OutputHelper.info(`[DRYRUN]: Write file ${newFilePath}`);
130
- console.log(`${result}`);
131
- }
132
- else {
133
- if (!(yield existsAsync(newFilePath))) {
134
- yield fs.promises.writeFile(newFilePath, result, 'utf8');
135
- helper_1.OutputHelper.info(`Created '${newFilePath}'`);
136
- }
137
- else {
138
- helper_1.OutputHelper.error(`File already exists ${newFilePath} will not overwrite`);
139
- }
140
- }
141
- }
142
- else if (stats.isDirectory()) {
143
- const newDirPath = path.join(targetPath, originalName);
144
- if (args.dryrun) {
145
- helper_1.OutputHelper.info(`[DRYRUN]: Write folder ${newDirPath}`);
146
- }
147
- else {
148
- // create folder in destination folder
149
- if (!(yield existsAsync(newDirPath))) {
150
- yield fs.promises.mkdir(newDirPath);
151
- }
152
- }
153
- // copy files/folder inside current folder recursively
154
- yield InitGameCommand._createDirectoryContentsAsync(path.join(templatePath, originalName), path.join(targetPath, newName), input, args);
155
- }
87
+ cli_output_helpers_1.OutputHelper.info('Failed to run `selene generate-roblox-std`, is selene installed?');
156
88
  }
157
89
  });
158
90
  }
159
91
  static _runCommandAsync(initGameArgs, command, args, options) {
160
92
  return __awaiter(this, void 0, void 0, function* () {
161
93
  if (initGameArgs.dryrun) {
162
- helper_1.OutputHelper.info(`[DRYRUN]: Would have ran \`${command} ${args.join(' ')}\``);
94
+ cli_output_helpers_1.OutputHelper.info(`[DRYRUN]: Would have ran \`${command} ${args.join(' ')}\``);
163
95
  }
164
96
  else {
165
- helper_1.OutputHelper.info(`Running \`${command} ${args.join(' ')}\``);
97
+ cli_output_helpers_1.OutputHelper.info(`Running \`${command} ${args.join(' ')}\``);
166
98
  const commandExec = execa(command, args, options);
167
99
  if (commandExec.stdout) {
168
100
  commandExec.stdout.pipe(process.stdout);
@@ -171,7 +103,7 @@ class InitGameCommand {
171
103
  commandExec.stderr.pipe(process.stderr);
172
104
  }
173
105
  const result = yield commandExec;
174
- helper_1.OutputHelper.info(`Finished running '${result.command}'`);
106
+ cli_output_helpers_1.OutputHelper.info(`Finished running '${result.command}'`);
175
107
  return result;
176
108
  }
177
109
  });
@@ -187,6 +119,9 @@ class InitGameCommand {
187
119
  });
188
120
  }
189
121
  static _validateGameName(name) {
122
+ if (!name) {
123
+ throw new Error('The project name is required.');
124
+ }
190
125
  if (name.length === 0) {
191
126
  throw new Error('The project name cannot be empty string.');
192
127
  }
@@ -1 +1 @@
1
- {"version":3,"file":"init-game-command.js","sourceRoot":"","sources":["../../src/commands/init-game-command.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGH,2CAA6B;AAC7B,uCAAyB;AACzB,uDAAyC;AACzC,sCAAyC;AAEzC,+BAAgC;AAChC,2CAA6B;AAE7B,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;AAM9C;;GAEG;AACH,SAAS,QAAQ,CAAC,GAAW;IAC3B,OAAO,GAAG;SACP,OAAO,CAAC,qBAAqB,EAAE,UAAU,IAAY,EAAE,KAAa;QACnE,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;IAC5B,CAAC,CAAC;SACD,OAAO,CAAC,MAA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AAI,CAAC,qBAAqB,MAAM,CAAC,OAAO,GAAG,CAAC,CAAC;gBAE1D,OAAO,MAAM,CAAC;aACf;QACH,CAAC;KAAA;IAEO,MAAM,CAAO,eAAe,CAAC,IAAkB;;YACrD,IAAI,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;YAExB,IAAI,CAAC,QAAQ,EAAE;gBACb,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;aACzC;YAED,eAAe,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;YAE5C,OAAO,QAAQ,CAAC;QAClB,CAAC;KAAA;IAEO,MAAM,CAAC,iBAAiB,CAAC,IAAY;QAC3C,IAAI,CAAC,IAAI,EAAE;YACT,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;SAClD;QAED,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;YACrB,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;SAC7D;IACH,CAAC;CACF;AAhID,0CAgIC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Initialize a new game command
3
+ */
4
+ import { Argv, CommandModule } from 'yargs';
5
+ import { NevermoreGlobalArgs } from '../args/global-args';
6
+ export interface InitPackageArgs extends NevermoreGlobalArgs {
7
+ packageName: string;
8
+ description: string;
9
+ }
10
+ /**
11
+ * Creates a new package within Nevermore
12
+ */
13
+ export declare class InitPackageCommand<T> implements CommandModule<T, InitPackageArgs> {
14
+ command: string;
15
+ describe: string;
16
+ builder(args: Argv<T>): Argv<InitPackageArgs>;
17
+ handler(args: InitPackageArgs): Promise<void>;
18
+ private static _ensurePackageName;
19
+ private static validatePackageName;
20
+ private static _ensureDescription;
21
+ private static validateDescription;
22
+ }
23
+ //# sourceMappingURL=init-package-command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init-package-command.d.ts","sourceRoot":"","sources":["../../src/commands/init-package-command.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAI5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1D,MAAM,WAAW,eAAgB,SAAQ,mBAAmB;IAC1D,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,qBAAa,kBAAkB,CAAC,CAAC,CAC/B,YAAW,aAAa,CAAC,CAAC,EAAE,eAAe,CAAC;IAErC,OAAO,SAA+C;IACtD,QAAQ,SAAiD;IAEzD,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IAcf,OAAO,CAAC,IAAI,EAAE,eAAe;mBAgCrB,kBAAkB;IAcvC,OAAO,CAAC,MAAM,CAAC,mBAAmB;mBAUb,kBAAkB;IAUvC,OAAO,CAAC,MAAM,CAAC,mBAAmB;CASnC"}
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ /**
3
+ * Initialize a new game command
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || function (mod) {
22
+ if (mod && mod.__esModule) return mod;
23
+ var result = {};
24
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
+ __setModuleDefault(result, mod);
26
+ return result;
27
+ };
28
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
+ return new (P || (P = Promise))(function (resolve, reject) {
31
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
32
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
33
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
34
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
35
+ });
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.InitPackageCommand = void 0;
39
+ const path = __importStar(require("path"));
40
+ const cli_output_helpers_1 = require("@quenty/cli-output-helpers");
41
+ const nevermore_template_helpers_1 = require("@quenty/nevermore-template-helpers");
42
+ /**
43
+ * Creates a new package within Nevermore
44
+ */
45
+ class InitPackageCommand {
46
+ constructor() {
47
+ this.command = 'init-package [package-name] [description]';
48
+ this.describe = 'Initializes a new package within Nevermore.';
49
+ }
50
+ builder(args) {
51
+ args.positional('package-name', {
52
+ describe: 'Name of the new package folder.',
53
+ demandOption: true,
54
+ type: 'string',
55
+ });
56
+ args.positional('description', {
57
+ describe: 'The description of the package.',
58
+ demandOption: true,
59
+ type: 'string',
60
+ });
61
+ return args;
62
+ }
63
+ handler(args) {
64
+ return __awaiter(this, void 0, void 0, function* () {
65
+ const rawPackageName = yield InitPackageCommand._ensurePackageName(args);
66
+ const packageName = nevermore_template_helpers_1.TemplateHelper.camelize(rawPackageName).toLowerCase();
67
+ const packageNameProper = nevermore_template_helpers_1.TemplateHelper.camelize(rawPackageName);
68
+ const description = yield InitPackageCommand._ensureDescription(args);
69
+ const srcRoot = process.cwd();
70
+ const templatePath = path.join(__dirname, '..', '..', 'templates', 'nevermore-library-package-template');
71
+ cli_output_helpers_1.OutputHelper.info(`Initializing a new package at '${srcRoot}' with template '${templatePath}'`);
72
+ yield nevermore_template_helpers_1.TemplateHelper.createDirectoryContentsAsync(templatePath, srcRoot, {
73
+ packageName: packageName,
74
+ packageNameProper: packageNameProper,
75
+ description: description,
76
+ }, args.dryrun);
77
+ });
78
+ }
79
+ static _ensurePackageName(args) {
80
+ return __awaiter(this, void 0, void 0, function* () {
81
+ let { packageName } = args;
82
+ if (!packageName) {
83
+ packageName = path.basename(process.cwd());
84
+ }
85
+ InitPackageCommand.validatePackageName(packageName);
86
+ return packageName;
87
+ });
88
+ }
89
+ static validatePackageName(name) {
90
+ if (!name) {
91
+ throw new Error('The project name is required.');
92
+ }
93
+ if (name.length === 0) {
94
+ throw new Error('The project name cannot be empty string.');
95
+ }
96
+ }
97
+ static _ensureDescription(args) {
98
+ return __awaiter(this, void 0, void 0, function* () {
99
+ let { description } = args;
100
+ InitPackageCommand.validateDescription(description);
101
+ return description;
102
+ });
103
+ }
104
+ static validateDescription(description) {
105
+ if (!description) {
106
+ throw new Error('The description is required.');
107
+ }
108
+ if (description.length === 0) {
109
+ throw new Error('The description cannot be empty string.');
110
+ }
111
+ }
112
+ }
113
+ exports.InitPackageCommand = InitPackageCommand;
114
+ //# sourceMappingURL=init-package-command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init-package-command.js","sourceRoot":"","sources":["../../src/commands/init-package-command.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGH,2CAA6B;AAC7B,mEAA0D;AAC1D,mFAAoE;AAQpE;;GAEG;AACH,MAAa,kBAAkB;IAA/B;QAGS,YAAO,GAAG,2CAA2C,CAAC;QACtD,aAAQ,GAAG,6CAA6C,CAAC;IA2FlE,CAAC;IAzFQ,OAAO,CAAC,IAAa;QAC1B,IAAI,CAAC,UAAU,CAAC,cAAc,EAAE;YAC9B,QAAQ,EAAE,iCAAiC;YAC3C,YAAY,EAAE,IAAI;YAClB,IAAI,EAAE,QAAQ;SACf,CAAC,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YAEpD,OAAO,WAAW,CAAC;QACrB,CAAC;KAAA;IAEO,MAAM,CAAC,mBAAmB,CAAC,IAAY;QAC7C,IAAI,CAAC,IAAI,EAAE;YACT,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;SAClD;QAED,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;YACrB,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;SAC7D;IACH,CAAC;IAEO,MAAM,CAAO,kBAAkB,CACrC,IAAqB;;YAErB,IAAI,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;YAE3B,kBAAkB,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC;YAEpD,OAAO,WAAW,CAAC;QACrB,CAAC;KAAA;IAEO,MAAM,CAAC,mBAAmB,CAAC,WAAmB;QACpD,IAAI,CAAC,WAAW,EAAE;YAChB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;SACjD;QAED,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE;YAC5B,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;SAC5D;IACH,CAAC;CACF;AA/FD,gDA+FC"}
package/dist/nevermore.js CHANGED
@@ -9,8 +9,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  const yargs_1 = __importDefault(require("yargs"));
11
11
  const helpers_1 = require("yargs/helpers");
12
+ const cli_output_helpers_1 = require("@quenty/cli-output-helpers");
12
13
  const init_game_command_1 = require("./commands/init-game-command");
13
- const helper_1 = require("./helper");
14
+ const init_package_command_1 = require("./commands/init-package-command");
14
15
  (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
15
16
  .scriptName('nevermore')
16
17
  .version()
@@ -26,10 +27,11 @@ const helper_1 = require("./helper");
26
27
  global: true,
27
28
  type: 'boolean',
28
29
  })
29
- .usage(helper_1.OutputHelper.formatInfo('Usage: $0 <command> [options]'))
30
+ .usage(cli_output_helpers_1.OutputHelper.formatInfo('Usage: $0 <command> [options]'))
30
31
  .command(new init_game_command_1.InitGameCommand())
32
+ .command(new init_package_command_1.InitPackageCommand())
31
33
  .recommendCommands()
32
- .demandCommand(1, helper_1.OutputHelper.formatHint("Hint: See 'raven help' for more help"))
34
+ .demandCommand(1, cli_output_helpers_1.OutputHelper.formatHint("Hint: See 'raven help' for more help"))
33
35
  .wrap(null)
34
36
  .strict().argv;
35
37
  //# sourceMappingURL=nevermore.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"nevermore.js","sourceRoot":"","sources":["../src/nevermore.ts"],"names":[],"mappings":";;AAEA;;GAEG;;;;;AAEH,kDAA0B;AAC1B,2CAAwC;AACxC,oEAA+D;AAC/D,qCAAwC;AAExC,IAAA,eAAK,EAAC,IAAA,iBAAO,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC;KACzB,UAAU,CAAC,WAAW,CAAC;KACvB,OAAO,EAAE;KACT,MAAM,CAAC,KAAK,EAAE;IACb,WAAW,EAAE,wDAAwD;IACrE,OAAO,EAAE,KAAK;IACd,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE,SAAS;CAChB,CAAC;KACD,MAAM,CAAC,QAAQ,EAAE;IAChB,WAAW,EACT,mEAAmE;IACrE,OAAO,EAAE,KAAK;IACd,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE,SAAS;CAChB,CAAC;KACD,KAAK,CAAC,qBAAY,CAAC,UAAU,CAAC,+BAA+B,CAAC,CAAC;KAC/D,OAAO,CAAC,IAAI,mCAAe,EAAE,CAAC;KAC9B,iBAAiB,EAAE;KACnB,aAAa,CACZ,CAAC,EACD,qBAAY,CAAC,UAAU,CAAC,sCAAsC,CAAC,CAChE;KACA,IAAI,CAAC,IAAI,CAAC;KACV,MAAM,EAAE,CAAC,IAAI,CAAC"}
1
+ {"version":3,"file":"nevermore.js","sourceRoot":"","sources":["../src/nevermore.ts"],"names":[],"mappings":";;AAEA;;GAEG;;;;;AAEH,kDAA0B;AAC1B,2CAAwC;AACxC,mEAA0D;AAE1D,oEAA+D;AAC/D,0EAAqE;AAErE,IAAA,eAAK,EAAC,IAAA,iBAAO,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC;KACzB,UAAU,CAAC,WAAW,CAAC;KACvB,OAAO,EAAE;KACT,MAAM,CAAC,KAAK,EAAE;IACb,WAAW,EAAE,wDAAwD;IACrE,OAAO,EAAE,KAAK;IACd,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE,SAAS;CAChB,CAAC;KACD,MAAM,CAAC,QAAQ,EAAE;IAChB,WAAW,EACT,mEAAmE;IACrE,OAAO,EAAE,KAAK;IACd,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE,SAAS;CAChB,CAAC;KACD,KAAK,CAAC,iCAAY,CAAC,UAAU,CAAC,+BAA+B,CAAC,CAAC;KAC/D,OAAO,CAAC,IAAI,mCAAe,EAAE,CAAC;KAC9B,OAAO,CAAC,IAAI,yCAAkB,EAAE,CAAC;KACjC,iBAAiB,EAAE;KACnB,aAAa,CACZ,CAAC,EACD,iCAAY,CAAC,UAAU,CAAC,sCAAsC,CAAC,CAChE;KACA,IAAI,CAAC,IAAI,CAAC;KACV,MAAM,EAAE,CAAC,IAAI,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/nevermore-cli",
3
- "version": "1.2.0",
3
+ "version": "1.2.1-canary.314.3173efb.0",
4
4
  "description": "CLI interface for Nevermore",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -24,10 +24,10 @@
24
24
  "Quenty"
25
25
  ],
26
26
  "dependencies": {
27
- "chalk": "^4.1.2",
27
+ "@quenty/cli-output-helpers": "1.0.1-canary.314.3173efb.0",
28
+ "@quenty/nevermore-template-helpers": "1.0.1-canary.314.3173efb.0",
28
29
  "execa": "v5.1.1",
29
30
  "find-git-root": "^1.0.4",
30
- "handlebars": "^4.7.7",
31
31
  "inquirer": "^8.2.4",
32
32
  "read-package-json": "^6.0.0",
33
33
  "typescript-memoize": "^1.1.1",
@@ -51,5 +51,5 @@
51
51
  "engines": {
52
52
  "node": ">=16"
53
53
  },
54
- "gitHead": "91d080c93cc2c0fbd873bc4b0f77720b2add7ea8"
54
+ "gitHead": "3173efbed0b3bc478e8258ffbbd15accc9bce2ac"
55
55
  }
@@ -4,30 +4,15 @@
4
4
 
5
5
  import { Argv, CommandModule } from 'yargs';
6
6
  import * as path from 'path';
7
- import * as fs from 'fs';
8
- import * as Handlebars from 'handlebars';
9
- import { OutputHelper } from '../helper';
7
+ import { OutputHelper } from '@quenty/cli-output-helpers';
8
+ import { TemplateHelper } from '@quenty/nevermore-template-helpers';
10
9
  import { NevermoreGlobalArgs } from '../args/global-args';
11
10
  import execa = require('execa');
12
- import * as util from 'util';
13
-
14
- const existsAsync = util.promisify(fs.exists);
15
11
 
16
12
  export interface InitGameArgs extends NevermoreGlobalArgs {
17
13
  gameName: string;
18
14
  }
19
15
 
20
- /**
21
- * Makes the string upper camel case
22
- */
23
- function camelize(str: string) {
24
- return str
25
- .replace(/(?:^\w|[A-Z]|\b\w)/g, function (word: string, index: number) {
26
- return word.toUpperCase();
27
- })
28
- .replace(/\s+/g, '');
29
- }
30
-
31
16
  /**
32
17
  * Creates a new game with Nevermore dependencies
33
18
  */
@@ -42,20 +27,14 @@ export class InitGameCommand<T> implements CommandModule<T, InitGameArgs> {
42
27
  demandOption: false,
43
28
  type: 'string',
44
29
  });
45
- args.option('dryrun', {
46
- describe: 'Whether this run should be a dryrun.',
47
- demandOption: false,
48
- type: 'boolean',
49
- default: false,
50
- });
51
30
  return args as Argv<InitGameArgs>;
52
31
  }
53
32
 
54
33
  public async handler(args: InitGameArgs) {
55
34
  const rawGameName = await InitGameCommand._ensureGameName(args);
56
35
 
57
- const gameName = camelize(rawGameName).toLowerCase();
58
- const gameNameProper = camelize(rawGameName);
36
+ const gameName = TemplateHelper.camelize(rawGameName).toLowerCase();
37
+ const gameNameProper = TemplateHelper.camelize(rawGameName);
59
38
 
60
39
  const srcRoot = process.cwd();
61
40
  const templatePath = path.join(
@@ -70,14 +49,14 @@ export class InitGameCommand<T> implements CommandModule<T, InitGameArgs> {
70
49
  `Creating a new game at '${srcRoot}' with template '${templatePath}'`
71
50
  );
72
51
 
73
- await InitGameCommand._createDirectoryContentsAsync(
52
+ await TemplateHelper.createDirectoryContentsAsync(
74
53
  templatePath,
75
54
  srcRoot,
76
55
  {
77
56
  gameName: gameName,
78
57
  gameNameProper: gameNameProper,
79
58
  },
80
- args
59
+ args.dryrun
81
60
  );
82
61
 
83
62
  const packages = [
@@ -113,67 +92,6 @@ export class InitGameCommand<T> implements CommandModule<T, InitGameArgs> {
113
92
  }
114
93
  }
115
94
 
116
- private static async _createDirectoryContentsAsync(
117
- templatePath: string,
118
- targetPath: string,
119
- input: any,
120
- args: InitGameArgs
121
- ) {
122
- // read all files/folders (1 level) from template folder
123
- const filesToCreate = await fs.promises.readdir(templatePath);
124
- for (const originalName of filesToCreate) {
125
- const origFilePath = path.join(templatePath, originalName);
126
-
127
- if (originalName == 'ENSURE_FOLDER_CREATED') {
128
- continue;
129
- }
130
-
131
- const compiledName = (Handlebars as any).default.compile(originalName);
132
- const newName = compiledName(input);
133
- const stats = await fs.promises.stat(origFilePath);
134
-
135
- if (stats.isFile()) {
136
- // read file content and transform it using template engine
137
- const contents = await fs.promises.readFile(origFilePath, 'utf8');
138
- const compiled = (Handlebars as any).default.compile(contents);
139
- const result = compiled(input);
140
- const newFilePath = path.join(targetPath, newName);
141
-
142
- if (args.dryrun) {
143
- OutputHelper.info(`[DRYRUN]: Write file ${newFilePath}`);
144
- console.log(`${result}`);
145
- } else {
146
- if (!(await existsAsync(newFilePath))) {
147
- await fs.promises.writeFile(newFilePath, result, 'utf8');
148
- OutputHelper.info(`Created '${newFilePath}'`);
149
- } else {
150
- OutputHelper.error(
151
- `File already exists ${newFilePath} will not overwrite`
152
- );
153
- }
154
- }
155
- } else if (stats.isDirectory()) {
156
- const newDirPath = path.join(targetPath, originalName);
157
- if (args.dryrun) {
158
- OutputHelper.info(`[DRYRUN]: Write folder ${newDirPath}`);
159
- } else {
160
- // create folder in destination folder
161
- if (!(await existsAsync(newDirPath))) {
162
- await fs.promises.mkdir(newDirPath);
163
- }
164
- }
165
-
166
- // copy files/folder inside current folder recursively
167
- await InitGameCommand._createDirectoryContentsAsync(
168
- path.join(templatePath, originalName),
169
- path.join(targetPath, newName),
170
- input,
171
- args
172
- );
173
- }
174
- }
175
- }
176
-
177
95
  private static async _runCommandAsync(
178
96
  initGameArgs: InitGameArgs,
179
97
  command: string,
@@ -218,6 +136,10 @@ export class InitGameCommand<T> implements CommandModule<T, InitGameArgs> {
218
136
  }
219
137
 
220
138
  private static _validateGameName(name: string): void {
139
+ if (!name) {
140
+ throw new Error('The project name is required.');
141
+ }
142
+
221
143
  if (name.length === 0) {
222
144
  throw new Error('The project name cannot be empty string.');
223
145
  }