This repository has been archived by the owner on Dec 5, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: teach
gulp extend
to accept a package URL (#266)
- Loading branch information
Showing
3 changed files
with
162 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
packages/liferay-theme-tasks/lib/prompts/url_package_prompt.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* © 2017 Liferay, Inc. <https://liferay.com> | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
const inquirer = require('inquirer'); | ||
const {URL} = require('url'); | ||
|
||
const themeFinder = require('../theme_finder'); | ||
|
||
class URLPackagePrompt { | ||
constructor(...args) { | ||
this.init(...args); | ||
} | ||
|
||
init(config, cb) { | ||
this.done = cb; | ||
|
||
inquirer.prompt( | ||
[ | ||
{ | ||
message: 'Enter the URL for the package:', | ||
name: 'packageURL', | ||
type: 'input', | ||
validate: this._validatePackageURL, | ||
}, | ||
], | ||
this._afterPrompt.bind(this) | ||
); | ||
} | ||
|
||
_validatePackageURL(packageURL, _answers) { | ||
try { | ||
new URL(packageURL); | ||
} catch (err) { | ||
return `"${packageURL}" is not a valid URL`; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
_afterPrompt(answers) { | ||
const config = themeFinder.getLiferayThemeModuleFromURL(answers.packageURL); | ||
answers.module = config.name; | ||
answers.modules = { | ||
[config.name]: Object.assign( | ||
{}, | ||
config, | ||
{realPath: answers.packageURL}, | ||
), | ||
}; | ||
this.done(answers); | ||
} | ||
} | ||
|
||
URLPackagePrompt.prompt = (config, cb) => new URLPackagePrompt(config, cb); | ||
|
||
module.exports = URLPackagePrompt; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters