template.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.installTemplatePackage = installTemplatePackage;
  6. exports.getTemplateConfig = getTemplateConfig;
  7. exports.copyTemplate = copyTemplate;
  8. exports.executePostInitScript = executePostInitScript;
  9. function _execa() {
  10. const data = _interopRequireDefault(require("execa"));
  11. _execa = function () {
  12. return data;
  13. };
  14. return data;
  15. }
  16. function _path() {
  17. const data = _interopRequireDefault(require("path"));
  18. _path = function () {
  19. return data;
  20. };
  21. return data;
  22. }
  23. function _cliTools() {
  24. const data = require("@react-native-community/cli-tools");
  25. _cliTools = function () {
  26. return data;
  27. };
  28. return data;
  29. }
  30. var PackageManager = _interopRequireWildcard(require("../../tools/packageManager"));
  31. var _copyFiles = _interopRequireDefault(require("../../tools/copyFiles"));
  32. var _replacePathSepForRegex = _interopRequireDefault(require("../../tools/replacePathSepForRegex"));
  33. function _fs() {
  34. const data = _interopRequireDefault(require("fs"));
  35. _fs = function () {
  36. return data;
  37. };
  38. return data;
  39. }
  40. function _chalk() {
  41. const data = _interopRequireDefault(require("chalk"));
  42. _chalk = function () {
  43. return data;
  44. };
  45. return data;
  46. }
  47. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  48. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  49. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  50. async function installTemplatePackage(templateName, root, npm) {
  51. _cliTools().logger.debug(`Installing template from ${templateName}`);
  52. await PackageManager.init({
  53. preferYarn: !npm,
  54. silent: true,
  55. root
  56. });
  57. return PackageManager.install([templateName], {
  58. preferYarn: !npm,
  59. silent: true,
  60. root
  61. });
  62. }
  63. function getTemplateConfig(templateName, templateSourceDir) {
  64. const configFilePath = _path().default.resolve(templateSourceDir, 'node_modules', templateName, 'template.config.js');
  65. _cliTools().logger.debug(`Getting config from ${configFilePath}`);
  66. if (!_fs().default.existsSync(configFilePath)) {
  67. throw new (_cliTools().CLIError)(`Couldn't find the "${configFilePath} file inside "${templateName}" template. Please make sure the template is valid.
  68. Read more: ${_chalk().default.underline.dim('https://github.com/react-native-community/cli/blob/master/docs/init.md#creating-custom-template')}`);
  69. }
  70. return require(configFilePath);
  71. }
  72. async function copyTemplate(templateName, templateDir, templateSourceDir) {
  73. const templatePath = _path().default.resolve(templateSourceDir, 'node_modules', templateName, templateDir);
  74. _cliTools().logger.debug(`Copying template from ${templatePath}`);
  75. let regexStr = _path().default.resolve(templatePath, 'node_modules');
  76. await (0, _copyFiles.default)(templatePath, process.cwd(), {
  77. exclude: [new RegExp((0, _replacePathSepForRegex.default)(regexStr))]
  78. });
  79. }
  80. function executePostInitScript(templateName, postInitScript, templateSourceDir) {
  81. const scriptPath = _path().default.resolve(templateSourceDir, 'node_modules', templateName, postInitScript);
  82. _cliTools().logger.debug(`Executing post init script located ${scriptPath}`);
  83. return (0, _execa().default)(scriptPath, {
  84. stdio: 'inherit'
  85. });
  86. }
  87. //# sourceMappingURL=template.js.map