Skip to content

Commit

Permalink
chore: resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Dec 27, 2022
2 parents 2ebcfbd + 08a2527 commit a0f362b
Show file tree
Hide file tree
Showing 8 changed files with 664 additions and 283 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
build:
working_directory: ~/nest
docker:
- image: cimg/node:18.12
- image: cimg/node:19.3
steps:
- checkout
- run:
Expand All @@ -43,7 +43,7 @@ jobs:
unit_tests:
working_directory: ~/nest
docker:
- image: cimg/node:18.12
- image: cimg/node:19.3
steps:
- checkout
- *restore-cache
Expand Down
1 change: 0 additions & 1 deletion actions/build.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ export class BuildAction extends AbstractAction {
);
} else {
this.compiler.run(configuration, pathToTsconfig, appName, onSuccess);
this.assetsManager.closeWatchers();
}
}

Expand Down
50 changes: 21 additions & 29 deletions actions/new.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class NewAction extends AbstractAction {
const dryRunOption = options.find((option) => option.name === 'dry-run');
const isDryRunEnabled = dryRunOption && dryRunOption.value;

await askForMissingInformation(inputs);
await askForMissingInformation(inputs, options);
await generateApplicationFiles(inputs, options).catch(exit);

const shouldSkipInstall = options.some(
Expand Down Expand Up @@ -68,6 +68,9 @@ export class NewAction extends AbstractAction {
const getApplicationNameInput = (inputs: Input[]) =>
inputs.find((input) => input.name === 'name');

const getPackageManagerInput = (inputs: Input[]) =>
inputs.find((options) => options.name === 'packageManager');

const getProjectDirectory = (
applicationName: Input,
directoryOption?: Input,
Expand All @@ -78,18 +81,25 @@ const getProjectDirectory = (
);
};

const askForMissingInformation = async (inputs: Input[]) => {
const askForMissingInformation = async (inputs: Input[], options: Input[]) => {
console.info(MESSAGES.PROJECT_INFORMATION_START);
console.info();

const prompt: inquirer.PromptModule = inquirer.createPromptModule();

const nameInput = getApplicationNameInput(inputs);
if (!nameInput!.value) {
const message = 'What name would you like to use for the new project?';
const questions = [generateInput('name', message)('nest-app')];
const answers: Answers = await prompt(questions as ReadonlyArray<Question>);
replaceInputMissingInformation(inputs, answers);
}

const packageManagerInput = getPackageManagerInput(options);
if (!packageManagerInput!.value) {
const answers = await askForPackageManager();
replaceInputMissingInformation(options, answers);
}
};

const replaceInputMissingInformation = (
Expand Down Expand Up @@ -120,10 +130,7 @@ const generateApplicationFiles = async (args: Input[], options: Input[]) => {
const mapSchematicOptions = (options: Input[]): SchematicOption[] => {
return options.reduce(
(schematicOptions: SchematicOption[], option: Input) => {
if (
option.name !== 'skip-install' &&
option.value !== 'package-manager'
) {
if (option.name !== 'skip-install') {
schematicOptions.push(new SchematicOption(option.name, option.value));
}
return schematicOptions;
Expand All @@ -137,9 +144,7 @@ const installPackages = async (
dryRunMode: boolean,
installDirectory: string,
) => {
const inputPackageManager: string = options.find(
(option) => option.name === 'package-manager',
)!.value as string;
const inputPackageManager = getPackageManagerInput(options)!.value as string;

let packageManager: AbstractPackageManager;
if (dryRunMode) {
Expand All @@ -148,32 +153,19 @@ const installPackages = async (
console.info();
return;
}
if (inputPackageManager !== undefined) {
try {
packageManager = PackageManagerFactory.create(inputPackageManager);
await packageManager.install(installDirectory, inputPackageManager);
} catch (error) {
if (error && error.message) {
console.error(chalk.red(error.message));
}
try {
packageManager = PackageManagerFactory.create(inputPackageManager);
await packageManager.install(installDirectory, inputPackageManager);
} catch (error) {
if (error && error.message) {
console.error(chalk.red(error.message));
}
} else {
packageManager = await selectPackageManager();
await packageManager.install(
installDirectory,
packageManager.name.toLowerCase(),
);
}
};

const selectPackageManager = async (): Promise<AbstractPackageManager> => {
const answers: Answers = await askForPackageManager();
return PackageManagerFactory.create(answers['package-manager']);
};

const askForPackageManager = async (): Promise<Answers> => {
const questions: Question[] = [
generateSelect('package-manager')(MESSAGES.PACKAGE_MANAGER_QUESTION)([
generateSelect('packageManager')(MESSAGES.PACKAGE_MANAGER_QUESTION)([
PackageManager.NPM,
PackageManager.YARN,
PackageManager.PNPM,
Expand Down
6 changes: 3 additions & 3 deletions commands/new.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export class NewCommand extends AbstractCommand {
.option('-g, --skip-git', 'Skip git repository initialization.', false)
.option('-s, --skip-install', 'Skip package installation.', false)
.option(
'-p, --package-manager [package-manager]',
'Specify package manager.'
'-p, --package-manager [packageManager]',
'Specify package manager.',
)
.option(
'-l, --language [language]',
Expand All @@ -41,7 +41,7 @@ export class NewCommand extends AbstractCommand {
options.push({ name: 'skip-install', value: command.skipInstall });
options.push({ name: 'strict', value: command.strict });
options.push({
name: 'package-manager',
name: 'packageManager',
value: command.packageManager,
});
options.push({ name: 'collection', value: command.collection });
Expand Down
9 changes: 8 additions & 1 deletion commands/start.command.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Command, CommanderStatic } from 'commander';
import { getRemainingFlags } from '../lib/utils/remaining-flags';
import { AbstractCommand } from './abstract.command';
import { Input } from './command.input';

Expand Down Expand Up @@ -74,7 +75,13 @@ export class StartCommand extends AbstractCommand {

const inputs: Input[] = [];
inputs.push({ name: 'app', value: app });
await this.action.handle(inputs, options);
const flags = getRemainingFlags(program);

try {
await this.action.handle(inputs, options, flags);
} catch (err) {
process.exit(1);
}
});
}
}
26 changes: 5 additions & 21 deletions lib/compiler/assets-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,9 @@ import { getValueOrDefault } from './helpers/get-value-or-default';
export class AssetsManager {
private watchAssetsKeyValue: { [key: string]: boolean } = {};
private watchers: chokidar.FSWatcher[] = [];
private actionInProgress = false;

/**
* Using on `nest build` to close file watch or the build process will not end
* Interval like process
* If no action has been taken recently close watchers
* If action has been taken recently flag and try again
*/
public closeWatchers() {
// Consider adjusting this for larger files
const timeoutMs = 500;
const closeFn = () => {
if (this.actionInProgress) {
this.actionInProgress = false;
setTimeout(closeFn, timeoutMs);
} else {
this.watchers.forEach((watcher) => watcher.close());
}
};

setTimeout(closeFn, timeoutMs);
this.watchers.forEach((watcher) => watcher.close());
}

public copyAssets(
Expand Down Expand Up @@ -96,6 +78,10 @@ export class AssetsManager {
.on('change', (path: string) => this.actionOnFile({ ...option, path, action: 'change' }))
.on('unlink', (path: string) => this.actionOnFile({ ...option, path, action: 'unlink' }));

if (!isWatchEnabled) {
watcher.on('ready', () => watcher.close());
}

this.watchers.push(watcher);
}
} catch (err) {
Expand All @@ -115,8 +101,6 @@ export class AssetsManager {
}
// Set path value to true for watching the first time
this.watchAssetsKeyValue[path] = true;
// Set action to true to avoid watches getting cutoff
this.actionInProgress = true;

const dest = copyPathResolve(
path,
Expand Down

0 comments on commit a0f362b

Please sign in to comment.