var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.createNewProject=void 0;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator"));var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _path=_interopRequireDefault(require("path"));
var _fs=_interopRequireDefault(require("fs"));
var _chalk=_interopRequireDefault(require("chalk"));
var _inquirer=_interopRequireDefault(require("inquirer"));
var _semver=_interopRequireDefault(require("semver"));
var _common=require("../common");







var _prompt=require("../systemTools/prompt");
var _constants=require("../constants");


















var _apple=require("../platformTools/apple");
var _android=require("../platformTools/android");
var _tizen=require("../platformTools/tizen");
var _webos=require("../platformTools/webos");
var _electron=require("../platformTools/electron");
var _firefox=require("../platformTools/firefox");
var _web=require("../platformTools/web");
var _templateTools=require("../templateTools");
var _fileutils=require("../systemTools/fileutils");
var _exec=require("../systemTools/exec");
var _buildHooks=require("./buildHooks");
var _logger=require("../systemTools/logger");
var _projectParser=require("./projectParser");
var _workspace=require("./workspace");
var _configParser=require("../configTools/configParser");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(source,true).forEach(function(key){(0,_defineProperty2.default)(target,key,source[key]);});}else if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source));}else{ownKeys(source).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key));});}}return target;}

var highlight=_chalk.default.green;

var createNewProject=function createNewProject(c){var args,data,inputProjectName,inputProjectNameObj,_ref,inputAppTitle,inputAppID,inputVersion,inputWorkspace,_ref2,inputTemplate,inputSupportedPlatforms,_ref3,confirm;return _regenerator.default.async(function createNewProject$(_context){while(1){switch(_context.prev=_context.next){case 0:
(0,_common.logTask)('createNewProject');
args=c.program.args;

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=10;break;}
inputProjectName=args[1];_context.next=14;break;case 10:_context.next=12;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 12:inputProjectNameObj=_context.sent;

inputProjectName=inputProjectNameObj.inputProjectName;case 14:_context.next=16;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?'},
{
name:'inputWorkspace',
type:'list',
message:'What workspace to use?',
default:data.defaultWorkspace,
choices:data.optionWorkspaces.keysAsArray}]));case 16:_ref=_context.sent;inputAppTitle=_ref.inputAppTitle;inputAppID=_ref.inputAppID;inputVersion=_ref.inputVersion;inputWorkspace=_ref.inputWorkspace;


c.runtime.selectedWorkspace=inputWorkspace;
(0,_configParser.parseRenativeConfigs)(c);
data.optionTemplates=(0,_templateTools.getTemplateOptions)(c);_context.next=26;return _regenerator.default.awrap(



_inquirer.default.prompt([{
name:'inputTemplate',
type:'list',
message:'What template to use?',
default:data.defaultTemplate,
choices:data.optionTemplates.keysAsArray},
{
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:data.optionPlatforms.keysAsArray,
choices:data.optionPlatforms.keysAsArray}]));case 26:_ref2=_context.sent;inputTemplate=_ref2.inputTemplate;inputSupportedPlatforms=_ref2.inputSupportedPlatforms;



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


data.optionTemplates.selectedOption=inputTemplate;
data.optionPlatforms.selectedOptions=inputSupportedPlatforms;
data.optionWorkspaces.selectedOption=inputWorkspace;
_prepareProjectOverview(c,data);_context.next=36;return _regenerator.default.awrap(

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


confirm){_context.next=41;break;}_context.next=41;return _regenerator.default.awrap(
_generateProject(c,data));case 41:case"end":return _context.stop();}}});};exports.createNewProject=createNewProject;




var _generateProject=function _generateProject(c,data){
(0,_common.logTask)('_generateProject');

var base=_path.default.resolve('.');

c.paths.project.dir=_path.default.join(base,data.projectName.replace(/(\s+)/g,'_'));
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();

(0,_fileutils.mkdirSync)(c.paths.project.dir);

var templates={};


return(0,_exec.executeAsync)(c,"npm show "+data.optionTemplates.selectedOption+" version").then(function(v){
(0,_common.logTask)("_generateProject:"+data.optionTemplates.selectedOption+":"+v,_chalk.default.grey);

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


var config={
projectName:data.projectName,
workspaceID:data.optionWorkspaces.selectedOption,
paths:{
appConfigsDir:'./appConfigs',
platformTemplatesDir:'$RNV_HOME/platformTemplates',
entryDir:'./',
platformAssetsDir:'./platformAssets',
platformBuildsDir:'./platformBuilds',
projectConfigDir:'./projectConfig'},

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

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


(0,_fileutils.writeObjectSync)(c.paths.project.config,config);

(0,_common.logSuccess)("Your project is ready! navigate to project "+
_chalk.default.white("cd "+data.projectName)+" and run "+_chalk.default.white(
'rnv run -p web')+" to see magic happen!");


});
};

var _prepareProjectOverview=function _prepareProjectOverview(c,data){
data.projectName=data.inputProjectName;
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 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(data.optionTemplates.selectedOption),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+=_chalk.default.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       \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 projectConfigs        # Project configuration files/assets             \u2502\n\u2502   \u2502   \u251C\u2500\u2500 fonts             # Folder for all custom fonts                    \u2502\n\u2502   \u2502   \u251C\u2500\u2500 builds            # platformBuilds/* injections                    \u2502\n\u2502   \u2502   \u2514\u2500\u2500 plugins           # Multi-platform plugins injections              \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;
};