forked from ember-cli/ember-cli-update
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-project-options.js
More file actions
78 lines (62 loc) · 2.09 KB
/
get-project-options.js
File metadata and controls
78 lines (62 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
'use strict';
const isDefaultBlueprint = require('./is-default-blueprint');
const hasYarn = require('./has-yarn');
/**
* Determine if project is a `addon`, `app`, or `glimmer` type
*
* @param {function} checkForDep - Function that will check if dependency exists in `devDependencies` or `dependencies`
* attribute of `package.json`
* @param {array} keywords - Array of strings of the `keywords` attribute from `package.json`
* @returns {string}
*/
function getProjectType(checkForDep, keywords) {
let isAddon = keywords && keywords.indexOf('ember-addon') !== -1;
if (isAddon) {
return 'addon';
}
let isGlimmer = checkForDep('@glimmer/blueprint');
if (isGlimmer) {
return 'glimmer';
}
let isApp = checkForDep('ember-cli');
if (isApp) {
return 'app';
}
throw new Error('Ember CLI project type could not be determined');
}
/**
* Determine what kind of ember flavor this project is and if it uses yarn or npm
*
* @param {array} keywords - the `keywords` attribute from a `package.json`
* @param {object} dependencies - the `dependencies` attribute from a `package.json`
* @param {object} devDependencies - the `devDependencies` attribute from a `package.json`
* @param {object} blueprint - Expected to contain `packageName` and `name`
* @returns {Promise<[string]|string[]>} - Array of strings containing keywords
*/
module.exports = async function getProjectOptions(
{ keywords, dependencies, devDependencies },
blueprint
) {
if (blueprint && !isDefaultBlueprint(blueprint)) {
return ['blueprint'];
}
let allDeps = Object.assign({}, dependencies, devDependencies);
function checkForDep(packageName) {
return allDeps[packageName] !== undefined;
}
let projectType = getProjectType(checkForDep, keywords);
let options = [projectType];
let cwd = process.cwd();
let isYarn = await hasYarn(cwd);
if (isYarn) {
options.push('yarn');
}
// addons don't support the welcome option
if (projectType === 'app') {
let hasWelcome = checkForDep('ember-welcome-page');
if (hasWelcome) {
options.push('welcome');
}
}
return options;
};