var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=exports.taskRnvNew=void 0;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator"));var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));var _path=_interopRequireDefault(require("path"));
var _inquirer=_interopRequireDefault(require("inquirer"));
var _semver=_interopRequireDefault(require("semver"));
var _lodash=_interopRequireDefault(require("lodash.set"));
var _prompt=require("../../cli/prompt");
var _constants=require("../../core/constants");
var _templateManager=require("../../core/templateManager");
var _fileutils=require("../../core/systemManager/fileutils");
var _exec=require("../../core/systemManager/exec");
var _logger=require("../../core/systemManager/logger");











var _workspace=require("../../core/projectManager/workspace");
var _configParser=require("../../core/configManager/configParser");
var _npmUtils=require("../../core/systemManager/npmUtils");
var _gitUtils=require("../../core/systemManager/gitUtils");
var _analytics=_interopRequireDefault(require("../../core/systemManager/analytics"));function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly)symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable;});keys.push.apply(keys,symbols);}return keys;}function _objectSpread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};if(i%2){ownKeys(Object(source),true).forEach(function(key){(0,_defineProperty2.default)(target,key,source[key]);});}else if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source));}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key));});}}return target;}

var highlight=(0,_logger.chalk)().green;

var _prepareProjectOverview=function _prepareProjectOverview(c,data){
data.appTitle=data.inputAppTitle||data.defaultAppTitle;
data.teamID='';
data.appID=data.inputAppID?
data.inputAppID.replace(/\s+/g,'-').toLowerCase():
data.appID;
data.version=data.inputVersion||data.defaultVersion;
var tempString=data.optionTemplates.selectedOption+"@"+data.optionTemplates.selectedVersion;

var str=(0,_logger.printBoxStart)('🚀  ReNative Project Generator');
str+=(0,_logger.printIntoBox)('');
str+=(0,_logger.printIntoBox)("Project Name (folder): "+
highlight(data.projectName),
1);

str+=(0,_logger.printIntoBox)("Workspace: "+
highlight(data.optionWorkspaces.selectedOption),
1);

str+=(0,_logger.printIntoBox)("Project Title: "+highlight(data.appTitle),1);
str+=(0,_logger.printIntoBox)("Project Version: "+highlight(data.version),1);
str+=(0,_logger.printIntoBox)("App ID: "+highlight(data.appID),1);
str+=(0,_logger.printIntoBox)("Project Template: "+highlight(tempString),1);
str+=(0,_logger.printIntoBox)("Git Enabled: "+highlight(data.gitEnabled),1);
str+=(0,_logger.printIntoBox)('');
str+=(0,_logger.printIntoBox)('Project Platforms:');
str+=(0,_logger.printArrIntoBox)(data.optionPlatforms.selectedOptions);
str+=(0,_logger.printIntoBox)('');
str+=(0,_logger.printIntoBox)('Project Structure:');
str+=(0,_logger.printIntoBox)('');
str+=(0,_logger.printIntoBox)(data.projectName);
str+=(0,_logger.chalk)().gray("\u2502   \u251C\u2500\u2500 appConfigs            # Application flavour configuration files/assets \u2502\n\u2502   \u2502   \u2514\u2500\u2500 [APP_ID]          # Example application flavour                    \u2502\n\u2502   \u2502       \u251C\u2500\u2500 assets        # Platform assets injected to ./platformAssets   \u2502\n\u2502   \u2502       \u251C\u2500\u2500 builds        # Platform files injected to ./platformBuilds    \u2502\n\u2502   \u2502       \u251C\u2500\u2500 fonts             # Folder for all custom fonts                \u2502\n\u2502   \u2502       \u251C\u2500\u2500 plugins           # Multi-platform plugins injections          \u2502\n\u2502   \u2502       \u2514\u2500\u2500 renative.json # Application flavour config                     \u2502\n\u2502   \u251C\u2500\u2500 platformAssets        # Generated cross-platform assets                \u2502\n\u2502   \u251C\u2500\u2500 platformBuilds        # Generated platform app projects                \u2502\n\u2502   \u251C\u2500\u2500 src                   # Source code files                              \u2502\n\u2502   \u251C\u2500\u2500 index.*.js            # Entry files                                    \u2502\n\u2502   \u2514\u2500\u2500 renative.json         # ReNative project configuration                 \u2502\n");












str+=(0,_logger.printIntoBox)('');
str+=(0,_logger.printBoxEnd)();
str+='\n';

data.confirmString=str;
};


var taskRnvNew=function taskRnvNew(c){var _renativeTemplateConf,_renativeTemplateConf2;var args,_await$inquirer$promp,confirmInRnvProject,data,inputProjectName,inputProjectNameObj,_await$inquirer$promp2,_confirm,_await$inquirer$promp3,inputAppTitle,inputAppID,inputVersion,_await$inquirer$promp4,inputWorkspace,customTemplate,_await$inquirer$promp5,inputTemplate,selectedInputTemplate,_await$inquirer$promp6,inputTemplateCustom,inputTemplateVersion,_await$inquirer$promp7,confirmAddTemplate,_c$files$workspace$co,renativeTemplateConfig,supportedPlatforms,_await$inquirer$promp8,inputSupportedPlatforms,renativeTemplateConfigExt,bootstrapQuestions,inquirerQuestions,inquirerObj,results,_await$inquirer$promp9,gitEnabled,_await$inquirer$promp10,confirm,templates,config;return _regenerator.default.async(function taskRnvNew$(_context){while(1){switch(_context.prev=_context.next){case 0:
(0,_logger.logTask)('taskRnvNew');
args=c.program.args;if(!

(0,_fileutils.fsExistsSync)(c.paths.project.config)){_context.next=10;break;}
(0,_logger.logWarning)("You are in ReNative project. Found: "+c.paths.project.config);_context.next=6;return _regenerator.default.awrap(
_inquirer.default.prompt({
name:'confirmInRnvProject',
type:'confirm',
message:'Are you sure you want to continue?'}));case 6:_await$inquirer$promp=_context.sent;confirmInRnvProject=_await$inquirer$promp.confirmInRnvProject;if(

confirmInRnvProject){_context.next=10;break;}return _context.abrupt("return",
Promise.reject('Cancelled'));case 10:




data={
defaultVersion:'0.1.0',
defaultTemplate:'renative-template-hello-world',
defaultProjectName:'helloRenative',
defaultAppTitle:'Hello Renative',
defaultWorkspace:'rnv'};

data.optionPlatforms=(0,_prompt.generateOptions)(_constants.SUPPORTED_PLATFORMS,true);
data.optionTemplates={};
data.optionWorkspaces=(0,_workspace.getWorkspaceOptions)(c);if(!(







args[1]&&args[1]!=='')){_context.next=18;break;}
inputProjectName=args[1];_context.next=22;break;case 18:_context.next=20;return _regenerator.default.awrap(

_inquirer.default.prompt({
name:'inputProjectName',
type:'input',
validate:function validate(value){return!!value;},
message:
"What's your project Name? (no spaces, folder based on ID will be created in this directory)"}));case 20:inputProjectNameObj=_context.sent;

inputProjectName=inputProjectNameObj==null?void 0:inputProjectNameObj.inputProjectName;case 22:


data.projectName=inputProjectName;
c.paths.project.dir=_path.default.join(
_constants.CURRENT_DIR,
data.projectName.replace(/(\s+)/g,'_'));if(!

(0,_fileutils.fsExistsSync)(c.paths.project.dir)){_context.next=33;break;}_context.next=27;return _regenerator.default.awrap(
_inquirer.default.prompt({
type:'confirm',
name:'confirm',
message:"Folder "+c.paths.project.dir+" already exists. RNV will override it. Continue?"}));case 27:_await$inquirer$promp2=_context.sent;_confirm=_await$inquirer$promp2.confirm;if(


_confirm){_context.next=31;break;}return _context.abrupt("return",
Promise.reject('Cancelled by user'));case 31:_context.next=33;return _regenerator.default.awrap(

(0,_fileutils.cleanFolder)(c.paths.project.dir));case 33:


(0,_fileutils.mkdirSync)(c.paths.project.dir);_context.next=36;return _regenerator.default.awrap(








_inquirer.default.prompt([
{
name:'inputAppTitle',
type:'input',
default:data.defaultAppTitle,
validate:function validate(val){return!!val||'Please enter a title';},
message:"What's your project Title?"},

{
name:'inputAppID',
type:'input',
default:function _default(){
data.appID="com.mycompany."+inputProjectName.
replace(/\s+/g,'').
toLowerCase();
return data.appID;
},
validate:function validate(id){return!!id.match(/[a-z]+\.[a-z0-9]+\.[a-z0-9]+/)||
'Please enter a valid appID (com.test.app)';},
message:"What's your App ID?"},

{
name:'inputVersion',
type:'input',
default:data.defaultVersion,
validate:function validate(v){return!!_semver.default.valid(_semver.default.coerce(v))||
'Please enter a valid semver version (1.0.0, 42.6.7.9.3-alpha, etc.)';},
message:"What's your Version?"}]));case 36:_await$inquirer$promp3=_context.sent;inputAppTitle=_await$inquirer$promp3.inputAppTitle;inputAppID=_await$inquirer$promp3.inputAppID;inputVersion=_await$inquirer$promp3.inputVersion;_context.next=42;return _regenerator.default.awrap(








_inquirer.default.prompt([
{
name:'inputWorkspace',
type:'list',
message:'What workspace to use?',
default:data.defaultWorkspace,
choices:data.optionWorkspaces.keysAsArray}]));case 42:_await$inquirer$promp4=_context.sent;inputWorkspace=_await$inquirer$promp4.inputWorkspace;


data.optionWorkspaces.selectedOption=inputWorkspace;

c.runtime.selectedWorkspace=inputWorkspace;_context.next=48;return _regenerator.default.awrap(
(0,_configParser.parseRenativeConfigs)(c));case 48:
data.optionTemplates=(0,_templateManager.getTemplateOptions)(c);




customTemplate='Custom Template ...';

data.optionTemplates.keysAsArray.push(customTemplate);_context.next=53;return _regenerator.default.awrap(

_inquirer.default.prompt({
name:'inputTemplate',
type:'list',
message:'What template to use?',
default:data.defaultTemplate,
choices:data.optionTemplates.keysAsArray}));case 53:_await$inquirer$promp5=_context.sent;inputTemplate=_await$inquirer$promp5.inputTemplate;if(!(



inputTemplate===customTemplate)){_context.next=63;break;}_context.next=58;return _regenerator.default.awrap(
_inquirer.default.prompt({
name:'inputTemplateCustom',
type:'input',
message:'Type exact name of your template NPM package.'}));case 58:_await$inquirer$promp6=_context.sent;inputTemplateCustom=_await$inquirer$promp6.inputTemplateCustom;

selectedInputTemplate=inputTemplateCustom;_context.next=64;break;case 63:

selectedInputTemplate=inputTemplate;case 64:


data.optionTemplates.selectedOption=selectedInputTemplate;_context.next=67;return _regenerator.default.awrap(


(0,_npmUtils.listAndSelectNpmVersion)(c,
data.optionTemplates.selectedOption,Object.keys(c.files.rnv.projectTemplates.config.projectTemplates)));case 67:inputTemplateVersion=_context.sent;

data.optionTemplates.selectedVersion=inputTemplateVersion;_context.next=71;return _regenerator.default.awrap(

(0,_exec.executeAsync)("npm i "+selectedInputTemplate+"@"+inputTemplateVersion+" --no-save",{
cwd:c.paths.project.dir}));case 71:if(


data.optionTemplates.keysAsArray.includes(selectedInputTemplate)){_context.next=83;break;}_context.next=74;return _regenerator.default.awrap(
_inquirer.default.prompt({
name:'confirmAddTemplate',
type:'confirm',
message:"Would you like to add "+
(0,_logger.chalk)().white(selectedInputTemplate)+" to your "+c.runtime.selectedWorkspace+" workspace template list?"}));case 74:_await$inquirer$promp7=_context.sent;confirmAddTemplate=_await$inquirer$promp7.confirmAddTemplate;if(!


confirmAddTemplate){_context.next=83;break;}
if(!((_c$files$workspace$co=c.files.workspace.config)==null?void 0:_c$files$workspace$co.projectTemplates)){
c.files.workspace.config.projectTemplates={};
}
c.files.workspace.config.projectTemplates[selectedInputTemplate]={};
(0,_fileutils.writeObjectSync)(c.paths.workspace.config,c.files.workspace.config);_context.next=82;return _regenerator.default.awrap(
(0,_configParser.parseRenativeConfigs)(c));case 82:

(0,_logger.logInfo)("Updating "+c.paths.workspace.config+"...DONE");case 83:



renativeTemplateConfig=(0,_fileutils.readObjectSync)(_path.default.join(c.paths.project.dir,'node_modules',selectedInputTemplate,'renative.template.json'));





supportedPlatforms=(renativeTemplateConfig==null?void 0:(_renativeTemplateConf=renativeTemplateConfig.defaults)==null?void 0:_renativeTemplateConf.supportedPlatforms)||data.optionPlatforms.keysAsArray;_context.next=87;return _regenerator.default.awrap(

_inquirer.default.prompt({
name:'inputSupportedPlatforms',
type:'checkbox',
pageSize:20,
message:'What platforms would you like to use?',
validate:function validate(val){return!!val.length||'Please select at least a platform';},
default:supportedPlatforms,
choices:supportedPlatforms}));case 87:_await$inquirer$promp8=_context.sent;inputSupportedPlatforms=_await$inquirer$promp8.inputSupportedPlatforms;





renativeTemplateConfigExt={};
bootstrapQuestions=renativeTemplateConfig==null?void 0:(_renativeTemplateConf2=renativeTemplateConfig.templateConfig)==null?void 0:_renativeTemplateConf2.bootstrapQuestions;if(!(

bootstrapQuestions==null?void 0:bootstrapQuestions.length)){_context.next=99;break;}
inquirerQuestions=[];
inquirerObj={};

bootstrapQuestions.forEach(function(q,i){
var choicesObj={};
if(q.options){
q.options.forEach(function(opt){
choicesObj[opt.title]=opt;
});
}
inquirerObj["q"+i]=_objectSpread(_objectSpread({},q),{},{choicesObj:choicesObj});
inquirerQuestions.push({
name:"q"+i,
type:q.type,
message:q.title,
choices:Object.keys(choicesObj)});

});_context.next=97;return _regenerator.default.awrap(


_inquirer.default.prompt(inquirerQuestions));case 97:results=_context.sent;

Object.keys(results).forEach(function(k){var _objConfig$configProp;
var objConfig=inquirerObj[k];
var objResult=results[k];
var objValue=objConfig.choicesObj[objResult];

var targetKey=objConfig==null?void 0:(_objConfig$configProp=objConfig.configProp)==null?void 0:_objConfig$configProp.key;

if(targetKey){
(0,_lodash.default)(renativeTemplateConfigExt,targetKey,objValue);
}
});case 99:_context.next=101;return _regenerator.default.awrap(






_inquirer.default.prompt({
name:'gitEnabled',
type:'confirm',
message:'Do you want to set-up git in your new project?'}));case 101:_await$inquirer$promp9=_context.sent;gitEnabled=_await$inquirer$promp9.gitEnabled;






data=_objectSpread(_objectSpread({},
data),{},{
inputProjectName:inputProjectName,
inputAppTitle:inputAppTitle,
inputAppID:inputAppID,
inputVersion:inputVersion,
inputTemplate:inputTemplate,
inputSupportedPlatforms:inputSupportedPlatforms,
inputWorkspace:inputWorkspace,
gitEnabled:gitEnabled});

data.optionPlatforms.selectedOptions=inputSupportedPlatforms;

_prepareProjectOverview(c,data);_context.next=108;return _regenerator.default.awrap(

_inquirer.default.prompt({
type:'confirm',
name:'confirm',
message:"\n"+data.confirmString+"\nIs all this correct?"}));case 108:_await$inquirer$promp10=_context.sent;confirm=_await$inquirer$promp10.confirm;if(


confirm){_context.next=112;break;}return _context.abrupt("return");case 112:_context.prev=112;_context.next=115;return _regenerator.default.awrap(







_analytics.default.captureEvent({
type:'newProject',
template:inputTemplate,
platforms:inputSupportedPlatforms}));case 115:_context.next=120;break;case 117:_context.prev=117;_context.t0=_context["catch"](112);


(0,_logger.logDebug)(_context.t0);case 120:


c.paths.project.package=_path.default.join(c.paths.project.dir,'package.json');
c.paths.project.config=_path.default.join(
c.paths.project.dir,
_constants.RENATIVE_CONFIG_NAME);


data.packageName=data.appTitle.replace(/\s+/g,'-').toLowerCase();

templates={};

(0,_logger.logTask)("_generateProject:"+
data.optionTemplates.selectedOption+":"+data.optionTemplates.selectedVersion,
(0,_logger.chalk)().grey);


templates[data.optionTemplates.selectedOption]={
version:data.optionTemplates.selectedVersion};


config=_objectSpread(_objectSpread(_objectSpread({},
renativeTemplateConfig),
renativeTemplateConfigExt),{},{
projectName:data.projectName,
workspaceID:data.optionWorkspaces.selectedOption,
paths:{
appConfigsDir:'./appConfigs',
entryDir:'./',
platformAssetsDir:'./platformAssets',
platformBuildsDir:'./platformBuilds'},

defaults:{
title:data.appTitle,
id:data.appID,
supportedPlatforms:data.optionPlatforms.selectedOptions},

templates:templates,
currentTemplate:data.optionTemplates.selectedOption,
isNew:true,
isMonorepo:false});


(0,_fileutils.writeFileSync)(c.paths.project.config,config);if(!

data.gitEnabled){_context.next=131;break;}_context.next=131;return _regenerator.default.awrap(
(0,_gitUtils.configureGit)(c));case 131:


(0,_logger.logSuccess)("Your project is ready! navigate to project "+
(0,_logger.chalk)().white("cd "+
data.projectName)+" and run "+
(0,_logger.chalk)().white(
'rnv run')+" to see magic happen!");case 132:case"end":return _context.stop();}}},null,null,[[112,117]],Promise);};exports.taskRnvNew=taskRnvNew;var _default2=




{
description:'Create new ReNative project',
fn:taskRnvNew,
task:'new',
params:_constants.PARAMS.withBase(),
platforms:[],
isGlobalScope:true};exports.default=_default2;
//# sourceMappingURL=task.rnv.new.js.map