yeoman-environment 3.16.1 → 3.17.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/lib/environment.js +31 -6
- package/lib/util/conflicter.js +73 -21
- package/package.json +1 -1
package/lib/environment.js
CHANGED
|
@@ -463,7 +463,32 @@ class Environment extends Base {
|
|
|
463
463
|
* @param {String} packagePath - PackagePath to the generator npm package (optional)
|
|
464
464
|
* @return {Object} environment - This environment
|
|
465
465
|
*/
|
|
466
|
-
register(
|
|
466
|
+
register(pathOrStub, meta, ...args) {
|
|
467
|
+
if (typeof pathOrStub === 'string') {
|
|
468
|
+
if (typeof meta === 'object') {
|
|
469
|
+
return this._registerGeneratorPath(pathOrStub, meta.namespace, meta.packagePath);
|
|
470
|
+
}
|
|
471
|
+
return this._registerGeneratorPath(pathOrStub, meta, ...args);
|
|
472
|
+
}
|
|
473
|
+
if (pathOrStub) {
|
|
474
|
+
if (typeof meta === 'object') {
|
|
475
|
+
return this.registerStub(pathOrStub, meta.namespace, meta.resolved, meta.packagePath);
|
|
476
|
+
}
|
|
477
|
+
return this.registerStub(pathOrStub, meta, ...args);
|
|
478
|
+
}
|
|
479
|
+
throw new TypeError('You must provide a generator name to register.');
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* Registers a specific `generator` to this environment. This generator is stored under
|
|
484
|
+
* provided namespace, or a default namespace format if none if available.
|
|
485
|
+
*
|
|
486
|
+
* @param {String} name - Filepath to the a generator or a npm package name
|
|
487
|
+
* @param {String} namespace - Namespace under which register the generator (optional)
|
|
488
|
+
* @param {String} packagePath - PackagePath to the generator npm package (optional)
|
|
489
|
+
* @return {Object} environment - This environment
|
|
490
|
+
*/
|
|
491
|
+
_registerGeneratorPath(name, namespace, packagePath) {
|
|
467
492
|
if (typeof name !== 'string') {
|
|
468
493
|
throw new TypeError('You must provide a generator name to register.');
|
|
469
494
|
}
|
|
@@ -1041,13 +1066,13 @@ class Environment extends Base {
|
|
|
1041
1066
|
start(options) {
|
|
1042
1067
|
return new Promise((resolve, reject) => {
|
|
1043
1068
|
if (this.conflicter === undefined) {
|
|
1044
|
-
|
|
1069
|
+
this.conflicterOptions = _.pick(
|
|
1045
1070
|
_.defaults({}, this.options, options),
|
|
1046
|
-
['force', 'bail', 'ignoreWhitespace', 'dryRun', 'skipYoResolve', 'logCwd']
|
|
1071
|
+
['force', 'bail', 'ignoreWhitespace', 'dryRun', 'skipYoResolve', 'logCwd', 'regenerate']
|
|
1047
1072
|
);
|
|
1048
|
-
conflicterOptions.cwd = conflicterOptions.logCwd;
|
|
1073
|
+
this.conflicterOptions.cwd = this.conflicterOptions.logCwd;
|
|
1049
1074
|
|
|
1050
|
-
this.conflicter = new Conflicter(this.adapter, conflicterOptions);
|
|
1075
|
+
this.conflicter = new Conflicter(this.adapter, this.conflicterOptions);
|
|
1051
1076
|
|
|
1052
1077
|
this.queueConflicter();
|
|
1053
1078
|
this.queuePackageManagerInstall();
|
|
@@ -1353,7 +1378,7 @@ class Environment extends Base {
|
|
|
1353
1378
|
* @param {(...args: any[]) => void | Promise<void>} task
|
|
1354
1379
|
* @param {{ once?: string, startQueue?: boolean }} [options]
|
|
1355
1380
|
*/
|
|
1356
|
-
queueTask(priority, task, options) {
|
|
1381
|
+
queueTask(priority, task, options = {}) {
|
|
1357
1382
|
return new Promise((resolve, reject) => {
|
|
1358
1383
|
this.runLoop.add(
|
|
1359
1384
|
priority,
|
package/lib/util/conflicter.js
CHANGED
|
@@ -61,11 +61,8 @@ class Conflicter {
|
|
|
61
61
|
let log;
|
|
62
62
|
if (typeof logStatus === 'function') {
|
|
63
63
|
log = logStatus;
|
|
64
|
-
} else {
|
|
65
|
-
log = this.adapter.log[logStatus];
|
|
66
|
-
if (log) {
|
|
67
|
-
log = log.bind(this.adapter.log);
|
|
68
|
-
}
|
|
64
|
+
} else if (this.adapter.log[logStatus]) {
|
|
65
|
+
log = (...args) => this.adapter.log[logStatus](...args);
|
|
69
66
|
}
|
|
70
67
|
if (log) {
|
|
71
68
|
this.queue.add('log', done => {
|
|
@@ -86,24 +83,79 @@ class Conflicter {
|
|
|
86
83
|
file.binary = binaryDiff.isBinary(file.path, file.contents);
|
|
87
84
|
}
|
|
88
85
|
|
|
89
|
-
let args;
|
|
90
|
-
let logFunction;
|
|
91
86
|
if (file.binary) {
|
|
92
|
-
logFunction = this.adapter.log.writeln
|
|
93
|
-
args = [binaryDiff.diff(file.path, file.contents)];
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
file.conflicterChanges
|
|
101
|
-
];
|
|
87
|
+
const logFunction = (...args) => this.adapter.log.writeln(...args);
|
|
88
|
+
const args = [binaryDiff.diff(file.path, file.contents)];
|
|
89
|
+
if (queue) {
|
|
90
|
+
this._log(logFunction, ...args);
|
|
91
|
+
} else {
|
|
92
|
+
logFunction(...args);
|
|
93
|
+
}
|
|
94
|
+
return;
|
|
102
95
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
96
|
+
|
|
97
|
+
if (!file.conflicterChanges) {
|
|
98
|
+
throw new Error(`Changes should be available for file ${file.path}`);
|
|
99
|
+
}
|
|
100
|
+
if (this.adapter.diff) {
|
|
101
|
+
const logFunction = (...args) => this.adapter.diff(...args);
|
|
102
|
+
const args = [file.conflicterChanges];
|
|
103
|
+
if (queue) {
|
|
104
|
+
this._log(logFunction, ...args);
|
|
105
|
+
} else {
|
|
106
|
+
logFunction(...args);
|
|
107
|
+
}
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const logFunction = (...args) => this.adapter.log.colored(...args);
|
|
111
|
+
const colorLines = colored => {
|
|
112
|
+
if (colored.color) {
|
|
113
|
+
const lines = colored.message.split('\n');
|
|
114
|
+
const returnValue = [];
|
|
115
|
+
for (const [idx, message] of lines.entries()) {
|
|
116
|
+
// Empty message can be ignored
|
|
117
|
+
if (message) {
|
|
118
|
+
returnValue.push({message, color: colored.color});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (idx + 1 < lines.length) {
|
|
122
|
+
returnValue.push({message: '\n'});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return returnValue;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return [colored];
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
if (file.conflicterChanges) {
|
|
133
|
+
const messages = file.conflicterChanges.map(change => {
|
|
134
|
+
if (change.added) {
|
|
135
|
+
return {color: 'added', message: change.value};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (change.removed) {
|
|
139
|
+
return {color: 'removed', message: change.value};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return {message: change.value};
|
|
143
|
+
})
|
|
144
|
+
.map(colored => colorLines(colored));
|
|
145
|
+
|
|
146
|
+
const args = [
|
|
147
|
+
{message: '\n'},
|
|
148
|
+
{message: 'removed', color: 'removed'},
|
|
149
|
+
{message: 'added', color: 'added'},
|
|
150
|
+
{message: '\n\n'},
|
|
151
|
+
...messages.flat(),
|
|
152
|
+
{message: '\n\n'}
|
|
153
|
+
];
|
|
154
|
+
if (queue) {
|
|
155
|
+
this._log(logFunction, args);
|
|
156
|
+
} else {
|
|
157
|
+
logFunction(args);
|
|
158
|
+
}
|
|
107
159
|
}
|
|
108
160
|
}
|
|
109
161
|
|