Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ var visibleName;
var folderName;
var immersive;

const validatePackageId = (packageId) => util.isValidPackageId(packageId) ? true
: 'Invalid package ID. Must match ' + util.PackageIdRegex.toString();

const validateFolderName = (folderName) => util.isValidFolderName(folderName) ? true
: 'Invalid folder name. Must match ' + util.FolderNameRegex.toString();

const askQuestions = () => {
const questions = [
{
Expand All @@ -23,22 +29,22 @@ const askQuestions = () => {
name: 'APPID',
type: 'input',
message: 'What is the app ID of your application?',
validate: util.isValidPackageId,
validate: validatePackageId,
default: packageName
},
{
name: 'FOLDERNAME',
type: 'input',
message: 'In which folder do you want to save this project?',
validate: util.isValidFolderName,
validate: validateFolderName,
default: folderName
},
{
name: 'APPTYPE',
type: 'list',
message: 'What app type do you want?',
choices: ['Landscape', 'Immersive', 'Components'],
default: "Landscape"
default: 'Landscape'
}
];
return inquirer.prompt(questions);
Expand Down Expand Up @@ -82,18 +88,16 @@ function copyFiles (srcPath, destPath) {
}

module.exports = argv => {
let nameRegex = /^([A-Za-z\-\_\d])+$/;
let idRegex = /^[a-z0-9_]+(\.[a-z0-9_]+)*(-[a-zA-Z0-9]*)?$/i;
if (argv.visibleName) {
visibleName = argv.visibleName;
}
if (argv.folderName && nameRegex.test(argv.folderName)) {
if (argv.folderName && util.isValidFolderName(argv.folderName)) {
folderName = argv.folderName;
if (!visibleName) {
visibleName = folderName;
}
}
if (argv.folderName && idRegex.test(argv.packageName)) {
if (argv.packageName && util.isValidPackageId(argv.packageName)) {
packageName = argv.packageName;
}
const currentDirectory = process.cwd();
Expand All @@ -108,8 +112,9 @@ module.exports = argv => {
folderName = answers['FOLDERNAME'];
visibleName = answers['APPNAME'];
let appType = answers['APPTYPE'];
immersive = appType === 'Immersive' || argv.immersive
if (appType == 'Components') {

immersive = appType === 'Immersive' || argv.immersive;
if (appType === 'Components') {
immersive = false;
templatePath = `${__dirname}/../template_components`;
}
Expand Down
9 changes: 5 additions & 4 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,13 @@ module.exports.installPackage = function (argv) {
}
};

module.exports.PackageIdRegex = /^[a-z0-9_]+(\.[a-z0-9_]+)*(-[a-zA-Z0-9]*)?$/;
module.exports.FolderNameRegex = /^([A-Za-z\-_\d])+$/;

module.exports.isValidPackageId = function (packageId) {
let regex = /^[a-z0-9_]+(\.[a-z0-9_]+)*(-[a-zA-Z0-9]*)?$/i;
return regex.test(packageId);
return module.exports.PackageIdRegex.test(packageId);
};

module.exports.isValidFolderName = function (folderName) {
let regex = /^([A-Za-z\-\_\d])+$/;
return regex.test(folderName);
return module.exports.FolderNameRegex.test(folderName);
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "magic-script-cli",
"description": "Magic Script Toolkit",
"version": "2.2.12",
"version": "2.2.13",
"author": "Magic Leap",
"license": "Apache-2.0",
"bin": {
Expand Down