All files / dist/platformTools index.js

12.58% Statements 19/151
0% Branches 0/58
0% Functions 0/36
15.53% Lines 16/103

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 1954x   4x 4x 4x                       4x       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.platformEject=exports.platformConfigure=exports.platformList=void 0;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator"));var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
 
var _chalk=_interopRequireDefault(require("chalk"));
var _path=_interopRequireDefault(require("path"));
var _inquirer=_interopRequireDefault(require("inquirer"));
var _common=require("../common");
 
 
 
 
var _prompt=require("../systemTools/prompt");
var _fileutils=require("../systemTools/fileutils");
var _buildHooks=require("../projectTools/buildHooks");
var _projectParser=require("../projectTools/projectParser");
var _constants=require("../constants");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 platformList=function platformList(c){return new Promise(function(resolve,reject){
var opts=_genPlatOptions(c);
console.log("\n"+opts.asString);
resolve();
});};exports.platformList=platformList;
 
var platformConfigure=function platformConfigure(c){return new Promise(function(resolve,reject){
var p=c.program.platform||'all';
(0,_common.logTask)("platformConfigure:"+p);
 
(0,_buildHooks.executePipe)(c,PIPES.PLATFORM_CONFIGURE_BEFORE).
then(function(){return cleanPlatformBuild(c,p);}).
then(function(){return(0,_projectParser.cleanPlaformAssets)(c);}).
then(function(){return _runCopyPlatforms(c,p);}).
then(function(){return(0,_buildHooks.executePipe)(c,PIPES.PLATFORM_CONFIGURE_AFTER);}).
then(function(){return resolve();}).
catch(function(e){return reject(e);});
});};exports.platformConfigure=platformConfigure;
 
var _generatePlatformChoices=function _generatePlatformChoices(c){return c.buildConfig.defaults.supportedPlatforms.map(function(platform){
var isConnected=c.paths.project.platformTemplatesDirs[platform].includes(c.paths.rnv.platformTemplates.dir);
return{name:platform+" - "+(isConnected?_chalk.default.green('(connected)'):_chalk.default.yellow('(ejected)')),value:platform,isConnected:isConnected};
});};
 
var platformEject=function platformEject(c){var _ref,ejectedPlatforms,ptfn,rptf,prf,copyShared;return _regenerator.default.async(function platformEject$(_context){while(1){switch(_context.prev=_context.next){case 0:
(0,_common.logTask)('platformEject');_context.next=3;return _regenerator.default.awrap(
 
_inquirer.default.prompt({
name:'ejectedPlatforms',
message:'This will copy platformTemplates folders from ReNative managed directly to your project Select platforms you would like to connect',
type:'checkbox',
choices:_generatePlatformChoices(c).map(function(choice){return _objectSpread({},choice,{disabled:!choice.isConnected});})}));case 3:_ref=_context.sent;ejectedPlatforms=_ref.ejectedPlatforms;
 
 
if(ejectedPlatforms.length){
ptfn='platformTemplates';
rptf=c.paths.rnv.platformTemplates.dir;
prf=c.paths.project.dir;
 
copyShared=false;
 
ejectedPlatforms.forEach(function(platform){
if(_constants.PLATFORMS[platform].requiresSharedConfig){
copyShared=true;
}
 
(0,_fileutils.copyFolderContentsRecursiveSync)(_path.default.join(rptf,platform),_path.default.join(prf,ptfn,platform));
 
if(copyShared){
(0,_fileutils.copyFolderContentsRecursiveSync)(_path.default.join(rptf,'_shared'),_path.default.join(prf,ptfn,'_shared'));
}
 
c.files.project.config.platformTemplatesDirs=c.files.project.config.platformTemplatesDirs||{};
c.files.project.config.platformTemplatesDirs[platform]="./"+ptfn;
 
(0,_fileutils.writeObjectSync)(c.paths.project.config,c.files.project.config);
});
}
 
(0,_common.logSuccess)(
_chalk.default.white(ejectedPlatforms.join(','))+" platform templates are located in "+_chalk.default.white(
c.files.project.config.platformTemplatesDirs[ejectedPlatforms[0]])+" now. You can edit them directly!");case 7:case"end":return _context.stop();}}});};exports.platformEject=platformEject;
 
 
 
 
var _genPlatOptions=function _genPlatOptions(c){
var opts=(0,_prompt.generateOptions)(c.buildConfig.defaults.supportedPlatforms,true,null,function(i,obj,mapping,defaultVal){
var isEjected=c.paths.project.platformTemplatesDirs[obj].includes(c.paths.rnv.platformTemplates.dir)?_chalk.default.green('(connected)'):_chalk.default.yellow('(ejected)');
return"-["+_chalk.default.white(i+1)+"] "+_chalk.default.white(defaultVal)+" - "+isEjected+" \n";
});
return opts;
};
 
var platformConnect=function platformConnect(c){var _ref2,connectedPlatforms,_ref3,deletePlatformFolder,pathsToRemove;return _regenerator.default.async(function platformConnect$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:
(0,_common.logTask)('platformConnect');_context2.next=3;return _regenerator.default.awrap(
 
_inquirer.default.prompt({
name:'connectedPlatforms',
message:'This will point platformTemplates folders from your local project to ReNative managed one. Select platforms you would like to connect',
type:'checkbox',
choices:_generatePlatformChoices(c).map(function(choice){return _objectSpread({},choice,{disabled:choice.isConnected});})}));case 3:_ref2=_context2.sent;connectedPlatforms=_ref2.connectedPlatforms;
 
 
 
if(connectedPlatforms.length){
connectedPlatforms.forEach(function(platform){var _c$files$project$conf;
if((_c$files$project$conf=c.files.project.config.platformTemplatesDirs)==null?void 0:_c$files$project$conf[platform]){
delete c.files.project.config.platformTemplatesDirs[platform];
}
 
if(!Object.keys(c.files.project.config.platformTemplatesDirs).length){
delete c.files.project.config.platformTemplatesDirs;
}
 
(0,_fileutils.writeObjectSync)(c.paths.project.config,c.files.project.config);
});
}_context2.next=8;return _regenerator.default.awrap(
 
_inquirer.default.prompt({
name:'deletePlatformFolder',
type:'confirm',
message:'Would you also like to delete the previously used platform folder?'}));case 8:_ref3=_context2.sent;deletePlatformFolder=_ref3.deletePlatformFolder;if(!
 
 
deletePlatformFolder){_context2.next=15;break;}
pathsToRemove=[];
connectedPlatforms.forEach(function(platform){
pathsToRemove.push(_path.default.join(c.paths.project.platformTemplatesDirs[platform],platform));
});_context2.next=15;return _regenerator.default.awrap(
 
 
 
(0,_fileutils.removeDirs)(pathsToRemove));case 15:
 
 
(0,_common.logSuccess)(
_chalk.default.white(connectedPlatforms.join(','))+" now using ReNative platformTemplates located in "+_chalk.default.white(c.paths.rnv.platformTemplates.dir)+" now!");case 16:case"end":return _context2.stop();}}});};
 
 
 
var _runCopyPlatforms=function _runCopyPlatforms(c,platform){return new Promise(function(resolve,reject){
(0,_common.logTask)("_runCopyPlatforms:"+platform);
var copyPlatformTasks=[];
if(platform==='all'){
for(var k in c.buildConfig.platforms){
if((0,_common.isPlatformSupportedSync)(k)){
var ptPath=_path.default.join(c.paths.project.platformTemplatesDirs[k],""+k);
var pPath=_path.default.join(c.paths.project.builds.dir,c.runtime.appId+"_"+k);
copyPlatformTasks.push((0,_fileutils.copyFolderContentsRecursiveSync)(ptPath,pPath));
}
}
}else if((0,_common.isPlatformSupportedSync)(platform)){
var _ptPath=_path.default.join(c.paths.project.platformTemplatesDirs[platform],""+platform);
var _pPath=_path.default.join(c.paths.project.builds.dir,c.runtime.appId+"_"+platform);
copyPlatformTasks.push((0,_fileutils.copyFolderContentsRecursiveSync)(_ptPath,_pPath));
}else{
logWarning("Your platform "+_chalk.default.white(platform)+" config is not present. Check "+_chalk.default.white(c.paths.appConfig.config));
}
 
Promise.all(copyPlatformTasks).then(function(values){
resolve();
});
});};
 
var cleanPlatformBuild=function cleanPlatformBuild(c,platform){return new Promise(function(resolve,reject){
(0,_common.logTask)("cleanPlatformBuild:"+platform);
 
var cleanTasks=[];
 
if(platform==='all'){
for(var k in c.buildConfig.platforms){
if((0,_common.isPlatformSupportedSync)(k)){
var pPath=_path.default.join(c.paths.project.builds.dir,c.runtime.appId+"_"+k);
cleanTasks.push((0,_fileutils.cleanFolder)(pPath));
}
}
}else if((0,_common.isPlatformSupportedSync)(platform)){
var _pPath2=_path.default.join(c.paths.project.builds.dir,c.runtime.appId+"_"+platform);
cleanTasks.push((0,_fileutils.cleanFolder)(_pPath2));
}
 
Promise.all(cleanTasks).then(function(values){
resolve();
});
});};
 
var createPlatformBuild=function createPlatformBuild(c,platform){return new Promise(function(resolve,reject){
(0,_common.logTask)("createPlatformBuild:"+platform);
 
if(!(0,_common.isPlatformSupportedSync)(platform,null,reject))return;
 
var pPath=_path.default.join(c.paths.project.builds.dir,c.runtime.appId+"_"+platform);
var ptPath=_path.default.join(c.paths.project.platformTemplatesDirs[platform],""+platform);
(0,_fileutils.copyFolderContentsRecursiveSync)(ptPath,pPath,false,[_path.default.join(ptPath,'_privateConfig')]);
 
resolve();
});};
//# sourceMappingURL=index.js.map