Skip to content

Commit 506c5ae

Browse files
author
Robert Jackson
authored
Merge pull request #1079 from spham92/docs
2 parents fc221be + 2283383 commit 506c5ae

13 files changed

Lines changed: 137 additions & 3 deletions

src/choose-blueprint-updates.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ const inquirer = require('inquirer');
55
const loadSafeBlueprint = require('./load-safe-blueprint');
66
const { defaultTo } = require('./constants');
77

8+
/**
9+
* Format the string that is displayed when user is prompted for a blueprint
10+
*
11+
* @param {object} blueprint - Expected to contain `name` and `version` attributes
12+
* @param {string} latestVersion - Latest version for the blueprint
13+
* @returns {string}
14+
*/
815
function formatBlueprintLine({
916
blueprint,
1017
latestVersion
@@ -26,6 +33,17 @@ async function chooseBlueprint({
2633
return choicesByName[answer.blueprint];
2734
}
2835

36+
/**
37+
* Facilitate prompting the user for which blueprint they want to update
38+
*
39+
* @param {string} cwd - Used in `checkForBlueprintUpdates` in order to generate url or path to it if on local disk
40+
* @param {object} emberCliUpdateJson - Use the `blueprints` property from this
41+
* @param {boolean} reset - Optional
42+
* @param {boolean} compare - Optional
43+
* @param {boolean} codemods - Optional
44+
* @param {string} to - Optional (could be undefined).
45+
* @returns {Promise<{blueprint: (*|{}), areAllUpToDate, to: string}>}
46+
*/
2947
async function chooseBlueprintUpdates({
3048
cwd,
3149
emberCliUpdateJson,

src/get-base-blueprint.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ const downloadPackage = require('./download-package');
55
const loadSafeBlueprint = require('./load-safe-blueprint');
66
const isDefaultBlueprint = require('./is-default-blueprint');
77

8+
/**
9+
* If the passed in `blueprint` is not the base blueprint, find it. A base blueprint is either
10+
* an `addon`, `app`, or `glimmer` blueprint or has the `isBaseBlueprint` boolean set to true.
11+
*
12+
* @param cwd - Used in `parseBlueprintPackage` to read package.json and find a viable version and normalize url
13+
* if it exists
14+
* @param blueprints - Find the base blueprint in this array if the passed blueprint is not one
15+
* @param blueprint - Figure out if this is a base blueprint
16+
* @returns {Promise<*>}
17+
*/
818
async function getBaseBlueprint({
919
cwd,
1020
blueprints,

src/get-blueprint-file-path.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ async function getBlueprintFilePath(cwd) {
99
return path.join(cwd, relative);
1010
}
1111

12+
/**
13+
* Use `config` as the parent directory of `ember-cli-update.json` unless a different config
14+
* folder is set in the a `package.json` file at the root of the project directory
15+
*
16+
* @param {String} cwd - Current working directory path where a `package.json` file could exist
17+
* @returns {Promise<string>}
18+
*/
1219
async function getBlueprintRelativeFilePath(cwd) {
1320
let configDir = 'config';
1421

src/get-project-options.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ const path = require('path');
44
const fs = require('fs-extra');
55
const isDefaultBlueprint = require('./is-default-blueprint');
66

7+
/**
8+
* Determine if project is a `addon`, `app`, or `glimmer` type
9+
*
10+
* @param {function} checkForDep - Function that will check if dependency exists in `devDependencies` or `dependencies`
11+
* attribute of `package.json`
12+
* @param {array} keywords - Array of strings of the `keywords` attribute from `package.json`
13+
* @returns {string}
14+
*/
715
function getProjectType(checkForDep, keywords) {
816
let isAddon = keywords && keywords.indexOf('ember-addon') !== -1;
917

@@ -26,6 +34,15 @@ function getProjectType(checkForDep, keywords) {
2634
throw new Error('Ember CLI project type could not be determined');
2735
}
2836

37+
/**
38+
* Determine what kind of ember flavor this project is and if it uses yarn or npm
39+
*
40+
* @param {array} keywords - the `keywords` attribute from a `package.json`
41+
* @param {object} dependencies - the `dependencies` attribute from a `package.json`
42+
* @param {object} devDependencies - the `devDependencies` attribute from a `package.json`
43+
* @param {object} blueprint - Expected to contain `packageName` and `name`
44+
* @returns {Promise<[string]|string[]>} - Array of strings containing keywords
45+
*/
2946
module.exports = async function getProjectOptions({
3047
keywords,
3148
dependencies,

src/get-project-version.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@ const _getProjectVersion = require('boilerplate-update/src/get-project-version')
55

66
const glimmerVersionCutoff = '0.6.3';
77

8+
/**
9+
* Fine the minimum version from `versions` array that matches the `packageVersion` range string
10+
*
11+
* @param {string} packageVersion - Can be a version range such as ^1.0.2 or an exact version
12+
* @param {array<string>} versions - Array of version strings available for package
13+
* @param {object} projectOptions - Glimmer projects are a special case
14+
* @returns {string}
15+
*/
816
module.exports = function getProjectVersion(packageVersion, versions, projectOptions) {
17+
// _getProjectVersion gets the minimum version that satisfies the given packageVersion string
918
let projectVersion = _getProjectVersion(packageVersion, versions);
1019

1120
if (projectOptions.includes('glimmer') && semver.lt(projectVersion, glimmerVersionCutoff)) {

src/get-versions.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
const npm = require('boilerplate-update/src/npm');
44

5+
/**
6+
* Returns an array of strings i.e.
7+
* [
8+
* "0.0.0",
9+
* "3.23.0-beta.2"
10+
* ]
11+
* @param packageName
12+
* @returns {Promise<Array<string>>}
13+
*/
514
module.exports = async function getVersions(packageName) {
615
return await npm.json(`view ${packageName} versions`);
716
};

src/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ const resolvePackage = require('./resolve-package');
2323
const { defaultTo } = require('./constants');
2424
const normalizeBlueprintArgs = require('./normalize-blueprint-args');
2525

26+
/**
27+
* If `version` attribute exists in the `blueprint` object and URL is empty, skip. Otherwise resolve the details of
28+
* the blueprint
29+
*
30+
* @param {Object} blueprint - Expected to contain `name`, `options` array, `packageName`, `location`, and `version`
31+
* attributes
32+
* @param {String} url - Optional parameter that links to package
33+
* @param {String} range - Version range i.e. 1.0.2
34+
* @returns {Promise<void>}
35+
* @private
36+
*/
2637
async function _resolvePackage(blueprint, url, range) {
2738
if (blueprint.version && !url) {
2839
return;
@@ -137,6 +148,7 @@ module.exports = async function emberCliUpdate({
137148
});
138149
}
139150

151+
// If blueprint is located on disk
140152
if (blueprint.location && !packageUrl) {
141153
let parsedPackage = await parseBlueprintPackage({
142154
cwd,
@@ -153,6 +165,9 @@ module.exports = async function emberCliUpdate({
153165
blueprint
154166
});
155167

168+
// If no base blueprint is found, set the selected one as the base blueprint.
169+
// `glimmer`, `app`, and `addon` blueprints as well as ones whose `isBaseBlueprint` attribute is
170+
// set to true will also have baseBlueprint undefined
156171
if (!baseBlueprint) {
157172
// for non-existing blueprints
158173
blueprint.isBaseBlueprint = true;

src/is-default-blueprint.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ const {
77
glimmerPackageName
88
} = require('./constants');
99

10+
/**
11+
* A default blueprint either the `addon` or `app` blueprint provided by `ember-cli` or the `glimmer` one
12+
*
13+
* @param {string} packageName - Ensure this is one of the package names that contain the default blueprints
14+
* @param {string} name - Check if this is the name of one of the default blueprint names
15+
* @returns {boolean}
16+
*/
1017
function isDefaultBlueprint({ packageName, name }) {
1118
if (packageName === glimmerPackageName && name === glimmerPackageName) {
1219
return true;

src/load-default-blueprint-from-disk.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ const getProjectVersion = require('./get-project-version');
88
const loadDefaultBlueprint = require('./load-default-blueprint');
99
const utils = require('./utils');
1010

11+
/**
12+
* Generate the configuration for the "base blueprint" which is the blueprint that first created
13+
* the ember project
14+
*
15+
* @param {string} cwd - Current working directory expected to be a node project path
16+
* @param {string} version - Optional. if not pass will use the one specified in package json
17+
* @returns {Promise<*|{}>}
18+
*/
1119
async function loadDefaultBlueprintFromDisk({
1220
cwd,
1321
version
@@ -32,9 +40,7 @@ async function loadDefaultBlueprintFromDisk({
3240
}
3341
}
3442

35-
let blueprint = loadDefaultBlueprint(projectOptions, version);
36-
37-
return blueprint;
43+
return loadDefaultBlueprint(projectOptions, version);
3844
}
3945

4046
module.exports = loadDefaultBlueprintFromDisk;

src/load-safe-blueprint-file.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@ const semver = require('semver');
66

77
const currentSchemaVersion = '1.0.0';
88

9+
/**
10+
* Iterate through the `packages` attribute of the `ember-cli-update.json` file and ensure each
11+
* configuration has an `options` attribute
12+
*
13+
* `emberCliUpdateJson.blueprints` is expected to have at least the following attributes:
14+
* {
15+
* packageName: 'package name',
16+
* location: 'Path on disk if local',
17+
* version: '1.2.3',
18+
* options: [],
19+
* ... Any other values
20+
* }
21+
*
22+
* @param {String} emberCliUpdateJsonPath - Path to `ember-cli-update.json` file
23+
* @returns {Promise<*>} - Contains object with `blueprints` attribute that is an array
24+
*/
925
async function loadSafeBlueprintFile(emberCliUpdateJsonPath) {
1026
let emberCliUpdateJson = await loadBlueprintFile(emberCliUpdateJsonPath);
1127

0 commit comments

Comments
 (0)