@ember-tooling/blueprint-model 0.0.0 → 0.0.2
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/LICENSE +21 -0
- package/package.json +16 -6
- package/utilities/directory-for-package-name.js +31 -0
- package/utilities/edit-file-diff.js +64 -0
- package/utilities/experiments.js +54 -0
- package/utilities/file-info.js +170 -0
- package/utilities/open-editor.js +44 -0
- package/utilities/prepend-emoji.js +12 -0
- package/utilities/process-template.js +10 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2013 Stefan Penner, Robert Jackson and ember-cli contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ember-tooling/blueprint-model",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://github.com/ember-cli/ember-cli.git",
|
|
7
|
+
"directory": "packages/blueprint-model"
|
|
8
|
+
},
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"chalk": "^4.1.2",
|
|
11
|
+
"diff": "^7.0.0",
|
|
12
|
+
"isbinaryfile": "^5.0.4",
|
|
13
|
+
"lodash": "^4.17.21",
|
|
14
|
+
"promise.hash.helper": "^1.0.8",
|
|
15
|
+
"quick-temp": "^0.1.8",
|
|
16
|
+
"silent-error": "^1.1.1"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Derive a directory name from a package name.
|
|
7
|
+
* Takes scoped packages into account.
|
|
8
|
+
*
|
|
9
|
+
* @method directoryForPackageName
|
|
10
|
+
* @param {String} packageName
|
|
11
|
+
* @return {String} Derived directory name.
|
|
12
|
+
*/
|
|
13
|
+
module.exports = function directoryForPackageName(packageName) {
|
|
14
|
+
let isScoped = packageName[0] === '@' && packageName.includes('/');
|
|
15
|
+
|
|
16
|
+
if (isScoped) {
|
|
17
|
+
let slashIndex = packageName.indexOf('/');
|
|
18
|
+
let scopeName = packageName.substring(1, slashIndex);
|
|
19
|
+
let packageNameWithoutScope = packageName.substring(slashIndex + 1);
|
|
20
|
+
let pathParts = process.cwd().split(path.sep);
|
|
21
|
+
let parentDirectoryContainsScopeName = pathParts.includes(scopeName);
|
|
22
|
+
|
|
23
|
+
if (parentDirectoryContainsScopeName) {
|
|
24
|
+
return packageNameWithoutScope;
|
|
25
|
+
} else {
|
|
26
|
+
return `${scopeName}-${packageNameWithoutScope}`;
|
|
27
|
+
}
|
|
28
|
+
} else {
|
|
29
|
+
return packageName;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const util = require('util');
|
|
5
|
+
const jsdiff = require('diff');
|
|
6
|
+
const quickTemp = require('quick-temp');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const SilentError = require('silent-error');
|
|
9
|
+
const openEditor = require('./open-editor');
|
|
10
|
+
const hash = require('promise.hash.helper');
|
|
11
|
+
|
|
12
|
+
const readFile = util.promisify(fs.readFile);
|
|
13
|
+
const writeFile = util.promisify(fs.writeFile);
|
|
14
|
+
|
|
15
|
+
class EditFileDiff {
|
|
16
|
+
constructor(options) {
|
|
17
|
+
this.info = options.info;
|
|
18
|
+
|
|
19
|
+
quickTemp.makeOrRemake(this, 'tmpDifferenceDir');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
edit() {
|
|
23
|
+
return hash({
|
|
24
|
+
input: this.info.render(),
|
|
25
|
+
output: readFile(this.info.outputPath),
|
|
26
|
+
})
|
|
27
|
+
.then(this.invokeEditor.bind(this))
|
|
28
|
+
.then(this.applyPatch.bind(this))
|
|
29
|
+
.finally(this.cleanUp.bind(this));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
cleanUp() {
|
|
33
|
+
quickTemp.remove(this, 'tmpDifferenceDir');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
applyPatch(resultHash) {
|
|
37
|
+
return hash({
|
|
38
|
+
diffString: readFile(resultHash.diffPath),
|
|
39
|
+
currentString: readFile(resultHash.outputPath),
|
|
40
|
+
}).then((result) => {
|
|
41
|
+
let appliedDiff = jsdiff.applyPatch(result.currentString.toString(), result.diffString.toString());
|
|
42
|
+
|
|
43
|
+
if (!appliedDiff) {
|
|
44
|
+
let message = 'Patch was not cleanly applied.';
|
|
45
|
+
this.info.ui.writeLine(`${message} Please choose another action.`);
|
|
46
|
+
throw new SilentError(message);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return writeFile(resultHash.outputPath, appliedDiff);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
invokeEditor(result) {
|
|
54
|
+
let info = this.info;
|
|
55
|
+
let diff = jsdiff.createPatch(info.outputPath, result.output.toString(), result.input);
|
|
56
|
+
let diffPath = path.join(this.tmpDifferenceDir, 'currentDiff.diff');
|
|
57
|
+
|
|
58
|
+
return writeFile(diffPath, diff)
|
|
59
|
+
.then(() => openEditor(diffPath))
|
|
60
|
+
.then(() => ({ outputPath: info.outputPath, diffPath }));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
module.exports = EditFileDiff;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const chalk = require('chalk');
|
|
4
|
+
const availableExperiments = Object.freeze(['EMBROIDER', 'CLASSIC']);
|
|
5
|
+
|
|
6
|
+
const deprecatedExperiments = Object.freeze([]);
|
|
7
|
+
const enabledExperiments = Object.freeze([]);
|
|
8
|
+
const deprecatedExperimentsDeprecationsIssued = [];
|
|
9
|
+
|
|
10
|
+
function isExperimentEnabled(experimentName) {
|
|
11
|
+
if (!availableExperiments.includes(experimentName)) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (process.env.EMBER_CLI_ENABLE_ALL_EXPERIMENTS && deprecatedExperiments.includes(experimentName)) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (process.env.EMBER_CLI_ENABLE_ALL_EXPERIMENTS) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (process.env.EMBER_CLI_CLASSIC && experimentName === 'EMBROIDER') {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let experimentEnvironmentVariable = `EMBER_CLI_${experimentName}`;
|
|
28
|
+
let experimentValue = process.env[experimentEnvironmentVariable];
|
|
29
|
+
|
|
30
|
+
if (deprecatedExperiments.includes(experimentName)) {
|
|
31
|
+
let deprecationPreviouslyIssued = deprecatedExperimentsDeprecationsIssued.includes(experimentName);
|
|
32
|
+
let isSpecifiedByUser = experimentValue !== undefined;
|
|
33
|
+
|
|
34
|
+
if (!deprecationPreviouslyIssued && isSpecifiedByUser) {
|
|
35
|
+
console.warn(
|
|
36
|
+
chalk.yellow(`The ${experimentName} experiment in ember-cli has been deprecated and will be removed.`)
|
|
37
|
+
);
|
|
38
|
+
deprecatedExperimentsDeprecationsIssued.push(experimentName);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (enabledExperiments.includes(experimentName)) {
|
|
43
|
+
return experimentValue !== 'false';
|
|
44
|
+
} else {
|
|
45
|
+
return experimentValue !== undefined && experimentValue !== 'false';
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
module.exports = {
|
|
50
|
+
isExperimentEnabled,
|
|
51
|
+
|
|
52
|
+
// exported for testing purposes
|
|
53
|
+
_deprecatedExperimentsDeprecationsIssued: deprecatedExperimentsDeprecationsIssued,
|
|
54
|
+
};
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const util = require('util');
|
|
5
|
+
const chalk = require('chalk');
|
|
6
|
+
const EditFileDiff = require('./edit-file-diff');
|
|
7
|
+
const EOL = require('os').EOL;
|
|
8
|
+
const rxEOL = new RegExp(EOL, 'g');
|
|
9
|
+
const isBinaryFile = require('isbinaryfile').isBinaryFileSync;
|
|
10
|
+
const hash = require('promise.hash.helper');
|
|
11
|
+
const canEdit = require('./open-editor').canEdit;
|
|
12
|
+
const processTemplate = require('./process-template');
|
|
13
|
+
|
|
14
|
+
const readFile = util.promisify(fs.readFile);
|
|
15
|
+
const lstat = util.promisify(fs.stat);
|
|
16
|
+
|
|
17
|
+
function diffHighlight(line) {
|
|
18
|
+
if (line[0] === '+') {
|
|
19
|
+
return chalk.green(line);
|
|
20
|
+
} else if (line[0] === '-') {
|
|
21
|
+
return chalk.red(line);
|
|
22
|
+
} else if (/^@@/.test(line)) {
|
|
23
|
+
return chalk.cyan(line);
|
|
24
|
+
} else {
|
|
25
|
+
return line;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const NOOP = (_) => _;
|
|
30
|
+
class FileInfo {
|
|
31
|
+
constructor(options) {
|
|
32
|
+
this.action = options.action;
|
|
33
|
+
this.outputBasePath = options.outputBasePath;
|
|
34
|
+
this.outputPath = options.outputPath;
|
|
35
|
+
this.displayPath = options.displayPath;
|
|
36
|
+
this.inputPath = options.inputPath;
|
|
37
|
+
this.templateVariables = options.templateVariables;
|
|
38
|
+
this.replacer = options.replacer || NOOP;
|
|
39
|
+
this.ui = options.ui;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
confirmOverwrite(path) {
|
|
43
|
+
let promptOptions = {
|
|
44
|
+
type: 'expand',
|
|
45
|
+
name: 'answer',
|
|
46
|
+
default: false,
|
|
47
|
+
message: `${chalk.red('Overwrite')} ${path}?`,
|
|
48
|
+
choices: [
|
|
49
|
+
{ key: 'y', name: 'Yes, overwrite', value: 'overwrite' },
|
|
50
|
+
{ key: 'n', name: 'No, skip', value: 'skip' },
|
|
51
|
+
],
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
let outputPathIsFile = false;
|
|
55
|
+
try {
|
|
56
|
+
outputPathIsFile = fs.statSync(this.outputPath).isFile();
|
|
57
|
+
} catch (err) {
|
|
58
|
+
/* ignore */
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
let canDiff = !isBinaryFile(this.inputPath) && (!outputPathIsFile || !isBinaryFile(this.outputPath));
|
|
62
|
+
|
|
63
|
+
if (canDiff) {
|
|
64
|
+
promptOptions.choices.push({ key: 'd', name: 'Diff', value: 'diff' });
|
|
65
|
+
|
|
66
|
+
if (canEdit()) {
|
|
67
|
+
promptOptions.choices.push({ key: 'e', name: 'Edit', value: 'edit' });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return this.ui.prompt(promptOptions).then((response) => response.answer);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
displayDiff() {
|
|
75
|
+
let info = this,
|
|
76
|
+
jsdiff = require('diff');
|
|
77
|
+
return hash({
|
|
78
|
+
input: this.render(),
|
|
79
|
+
output: readFile(info.outputPath),
|
|
80
|
+
}).then((result) => {
|
|
81
|
+
let diff = jsdiff.createPatch(
|
|
82
|
+
info.outputPath,
|
|
83
|
+
result.output.toString().replace(rxEOL, '\n'),
|
|
84
|
+
result.input.replace(rxEOL, '\n')
|
|
85
|
+
);
|
|
86
|
+
let lines = diff.split('\n');
|
|
87
|
+
|
|
88
|
+
for (let i = 0; i < lines.length; i++) {
|
|
89
|
+
info.ui.write(diffHighlight(lines[i] + EOL));
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async render() {
|
|
95
|
+
if (!this.rendered) {
|
|
96
|
+
let result = await this._render();
|
|
97
|
+
this.rendered = this.replacer(result, this);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return this.rendered;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
_render() {
|
|
104
|
+
let path = this.inputPath;
|
|
105
|
+
let context = this.templateVariables;
|
|
106
|
+
|
|
107
|
+
return readFile(path).then((content) =>
|
|
108
|
+
lstat(path).then((fileStat) => {
|
|
109
|
+
if (isBinaryFile(content, fileStat.size)) {
|
|
110
|
+
return content;
|
|
111
|
+
} else {
|
|
112
|
+
try {
|
|
113
|
+
return processTemplate(content.toString(), context);
|
|
114
|
+
} catch (err) {
|
|
115
|
+
err.message += ` (Error in blueprint template: ${path})`;
|
|
116
|
+
throw err;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
})
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
checkForConflict() {
|
|
124
|
+
return this.render().then((input) => {
|
|
125
|
+
input = input.toString().replace(rxEOL, '\n');
|
|
126
|
+
|
|
127
|
+
return readFile(this.outputPath)
|
|
128
|
+
.then((output) => {
|
|
129
|
+
output = output.toString().replace(rxEOL, '\n');
|
|
130
|
+
|
|
131
|
+
return input === output ? 'identical' : 'confirm';
|
|
132
|
+
})
|
|
133
|
+
.catch((e) => {
|
|
134
|
+
if (e.code === 'ENOENT') {
|
|
135
|
+
return 'none';
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
throw e;
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
confirmOverwriteTask() {
|
|
144
|
+
let info = this;
|
|
145
|
+
|
|
146
|
+
return function () {
|
|
147
|
+
function doConfirm() {
|
|
148
|
+
return info.confirmOverwrite(info.displayPath).then((action) => {
|
|
149
|
+
if (action === 'diff') {
|
|
150
|
+
return info.displayDiff().then(doConfirm);
|
|
151
|
+
} else if (action === 'edit') {
|
|
152
|
+
let editFileDiff = new EditFileDiff({ info });
|
|
153
|
+
return editFileDiff
|
|
154
|
+
.edit()
|
|
155
|
+
.then(() => (info.action = action))
|
|
156
|
+
.catch(() => doConfirm())
|
|
157
|
+
.then(() => info);
|
|
158
|
+
} else {
|
|
159
|
+
info.action = action;
|
|
160
|
+
return info;
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return doConfirm();
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
module.exports = FileInfo;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const spawn = require('child_process').spawn;
|
|
4
|
+
|
|
5
|
+
function openEditor(file) {
|
|
6
|
+
if (!openEditor.canEdit()) {
|
|
7
|
+
throw new Error('EDITOR environment variable is not set');
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (!file) {
|
|
11
|
+
throw new Error('No `file` option provided');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
let editorArgs = openEditor._env().EDITOR.split(' ');
|
|
15
|
+
let editor = editorArgs.shift();
|
|
16
|
+
const args = [file].concat(editorArgs);
|
|
17
|
+
let editProcess = openEditor._spawn(editor, args, { stdio: 'inherit' });
|
|
18
|
+
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
editProcess.on('close', (code) => {
|
|
21
|
+
if (code === 0) {
|
|
22
|
+
resolve();
|
|
23
|
+
} else {
|
|
24
|
+
reject(
|
|
25
|
+
new Error(`Spawn('${editor}', [${args.join(',')}]) exited with a non zero error status code: '${code}'`)
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
openEditor.canEdit = function () {
|
|
33
|
+
return openEditor._env().EDITOR !== undefined;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
openEditor._env = function () {
|
|
37
|
+
return process.env;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
openEditor._spawn = function () {
|
|
41
|
+
return spawn.apply(this, arguments);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
module.exports = openEditor;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function supportEmoji() {
|
|
4
|
+
const hasEmojiTurnedOff = process.argv.indexOf('--no-emoji') > -1;
|
|
5
|
+
return process.stdout.isTTY && process.platform !== 'win32' && !hasEmojiTurnedOff;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const areEmojiSupported = supportEmoji();
|
|
9
|
+
|
|
10
|
+
module.exports = function prependEmoji(emoji, msg) {
|
|
11
|
+
return areEmojiSupported ? `${emoji} ${msg}` : msg;
|
|
12
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function processTemplate(content, context) {
|
|
4
|
+
let options = {
|
|
5
|
+
evaluate: /<%([\s\S]+?)%>/g,
|
|
6
|
+
interpolate: /<%=([\s\S]+?)%>/g,
|
|
7
|
+
escape: /<%-([\s\S]+?)%>/g,
|
|
8
|
+
};
|
|
9
|
+
return require('lodash/template')(content, options)(context);
|
|
10
|
+
};
|