# All files / dist/projectTools projectGenerator.js

12% Statements 15/125
0% Branches 0/41
0% Functions 0/18
16% Lines 12/75

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    2474x

    4x
    4x
    4x
    4x
    4x

    4x

    4x

    4x

    4x

    4x
    4x
     var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.projectGeneratorHelp=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 createNewProject=function createNewProject(c){var args,data,inputProjectName,inputProjectNameObj,_ref,inputAppTitle,inputAppID,inputVersion,inputTemplate,inputSupportedPlatforms,_ref2,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'};

    data.optionPlatforms=(0,_prompt.generateOptions)(_constants.SUPPORTED_PLATFORMS,true);
    data.optionTemplates=(0,_templateTools.getTemplateOptions)(c);
    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:'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 16:_ref=_context.sent;inputAppTitle=_ref.inputAppTitle;inputAppID=_ref.inputAppID;inputVersion=_ref.inputVersion;inputTemplate=_ref.inputTemplate;inputSupportedPlatforms=_ref.inputSupportedPlatforms;

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

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

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

    confirm){_context.next=33;break;}_context.next=33;return _regenerator.default.awrap(
    _generateProject(c,data));case 33: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,
    workspace:'rnv',
    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)("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;
    };

    var projectGeneratorHelp=function projectGeneratorHelp(c){return _regenerator.default.async(function projectGeneratorHelp$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:
    console.log("Creates new project:\nYSSYYSYSYSY");case 1:case"end":return _context2.stop();}}});};exports.projectGeneratorHelp=projectGeneratorHelp;
    //# sourceMappingURL=projectGenerator.js.map