PageRenderTime 53ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/node_modules/xdl/build/detach/IosShellApp.js

https://bitbucket.org/zhivkokasabov/devrealm
JavaScript | 333 lines | 246 code | 51 blank | 36 comment | 62 complexity | 2ca6e17ebf1174bd186a4375691d4d11 MD5 | raw file
Possible License(s): Apache-2.0, BSD-2-Clause, JSON, MIT, WTFPL, Unlicense, CC-BY-SA-3.0, BSD-3-Clause, 0BSD
  1. // Copyright 2015-present 650 Industries. All rights reserved.
  2. 'use strict';
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.createIOSShellAppAsync = undefined;
  7. /**
  8. * Build the iOS workspace at the given path.
  9. * @return the path to the resulting build artifact
  10. */
  11. let _buildAsync = (() => {
  12. var _ref = _asyncToGenerator(function* (projectName, workspacePath, configuration, type, relativeBuildDestination, verbose) {
  13. let buildCmd, pathToArtifact;
  14. const buildDest = `${relativeBuildDestination}-${type}`;
  15. if (type === 'simulator') {
  16. buildCmd = `xcodebuild -workspace ${projectName}.xcworkspace -scheme ${projectName} -sdk iphonesimulator -configuration ${configuration} -derivedDataPath ${buildDest} CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO ARCHS="i386 x86_64" ONLY_ACTIVE_ARCH=NO | xcpretty`;
  17. pathToArtifact = _path.default.join(buildDest, 'Build', 'Products', `${configuration}-iphonesimulator`, `${projectName}.app`);
  18. } else if (type === 'archive') {
  19. buildCmd = `xcodebuild -workspace ${projectName}.xcworkspace -scheme ${projectName} -sdk iphoneos -destination generic/platform=iOS -configuration ${configuration} archive -derivedDataPath ${buildDest} -archivePath ${buildDest}/${projectName}.xcarchive CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO | xcpretty`;
  20. pathToArtifact = _path.default.join(buildDest, `${projectName}.xcarchive`);
  21. } else {
  22. throw new Error(`Unsupported build type: ${type}`);
  23. }
  24. console.log(`Building iOS workspace at ${workspacePath} to ${buildDest}:\n`);
  25. console.log(buildCmd);
  26. if (!verbose) {
  27. console.log('\nxcodebuild is running. Logging errors only. To see full output, use --verbose 1...');
  28. }
  29. yield (0, (_ExponentTools || _load_ExponentTools()).spawnAsyncThrowError)(buildCmd, null, {
  30. // only stderr
  31. stdio: verbose ? 'inherit' : ['ignore', 'ignore', 'inherit'],
  32. cwd: workspacePath,
  33. shell: true
  34. });
  35. return _path.default.resolve(workspacePath, pathToArtifact);
  36. });
  37. return function _buildAsync(_x, _x2, _x3, _x4, _x5, _x6) {
  38. return _ref.apply(this, arguments);
  39. };
  40. })();
  41. let _podInstallAsync = (() => {
  42. var _ref2 = _asyncToGenerator(function* (workspacePath, isRepoUpdateEnabled) {
  43. // ensure pods are clean
  44. const pathsToClean = [_path.default.join(workspacePath, 'Pods'), _path.default.join(workspacePath, 'Podfile.lock')];
  45. pathsToClean.forEach(function (path) {
  46. if ((_fsExtra || _load_fsExtra()).default.existsSync(path)) {
  47. (_rimraf || _load_rimraf()).default.sync(path);
  48. }
  49. });
  50. // install
  51. let cocoapodsArgs = ['install'];
  52. if (isRepoUpdateEnabled) {
  53. cocoapodsArgs.push('--repo-update');
  54. }
  55. console.log('Installing iOS workspace dependencies...');
  56. console.log(`pod ${cocoapodsArgs.join(' ')}`);
  57. yield (0, (_ExponentTools || _load_ExponentTools()).spawnAsyncThrowError)('pod', cocoapodsArgs, {
  58. stdio: 'inherit',
  59. cwd: workspacePath
  60. });
  61. });
  62. return function _podInstallAsync(_x7, _x8) {
  63. return _ref2.apply(this, arguments);
  64. };
  65. })();
  66. let _createStandaloneContextAsync = (() => {
  67. var _ref3 = _asyncToGenerator(function* (args) {
  68. // right now we only ever build a single detached workspace for service contexts.
  69. // TODO: support multiple different pod configurations, assemble a cache of those builds.
  70. const expoSourcePath = '../ios';
  71. const workspaceSourcePath = _path.default.join(expoSourcePath, '..', 'shellAppWorkspaces', 'ios', 'default');
  72. let { privateConfigFile } = args;
  73. let privateConfig;
  74. if (privateConfigFile) {
  75. let privateConfigContents = yield (_fsExtra || _load_fsExtra()).default.readFile(privateConfigFile, 'utf8');
  76. privateConfig = JSON.parse(privateConfigContents);
  77. }
  78. let manifest;
  79. if (args.action === 'configure') {
  80. const { url, sdkVersion, releaseChannel } = args;
  81. manifest = yield (0, (_ExponentTools || _load_ExponentTools()).getManifestAsync)(url, {
  82. 'Exponent-SDK-Version': sdkVersion,
  83. 'Exponent-Platform': 'ios',
  84. 'Expo-Release-Channel': releaseChannel ? releaseChannel : 'default'
  85. });
  86. }
  87. const buildFlags = (_StandaloneBuildFlags || _load_StandaloneBuildFlags()).default.createIos(args.configuration, {
  88. workspaceSourcePath,
  89. appleTeamId: args.appleTeamId
  90. });
  91. const context = (_StandaloneContext || _load_StandaloneContext()).default.createServiceContext(expoSourcePath, args.archivePath, manifest, privateConfig, buildFlags, args.url, args.releaseChannel);
  92. return context;
  93. });
  94. return function _createStandaloneContextAsync(_x9) {
  95. return _ref3.apply(this, arguments);
  96. };
  97. })();
  98. /**
  99. * possible args:
  100. * @param url manifest url for shell experience
  101. * @param sdkVersion sdk to use when requesting the manifest
  102. * @param releaseChannel channel to pull manifests from, default is 'default'
  103. * @param archivePath path to existing NSBundle to configure
  104. * @param privateConfigFile path to a private config file containing, e.g., private api keys
  105. * @param appleTeamId Apple Developer's account Team ID
  106. * @param output specify the output path of the configured archive (ie) /tmp/my-app-archive-build.xcarchive or /tmp/my-app-ios-build.tar.gz
  107. */
  108. let _configureAndCopyShellAppArchiveAsync = (() => {
  109. var _ref4 = _asyncToGenerator(function* (args) {
  110. const { output, type } = args;
  111. const context = yield _createStandaloneContextAsync(args);
  112. const { projectName } = (_IosWorkspace || _load_IosWorkspace()).getPaths(context);
  113. yield (_IosNSBundle || _load_IosNSBundle()).configureAsync(context);
  114. if (output) {
  115. // TODO: un-hard-code ExpoKitApp.app
  116. const archiveName = projectName.replace(/[^0-9a-z_\-\.]/gi, '_');
  117. const appReleasePath = _path.default.resolve(_path.default.join(`${context.data.archivePath}`, '..'));
  118. if (type === 'simulator') {
  119. yield (0, (_ExponentTools || _load_ExponentTools()).spawnAsync)(`mv ExpoKitApp.app ${archiveName}.app && tar -czvf ${output} ${archiveName}.app`, null, {
  120. stdio: 'inherit',
  121. cwd: appReleasePath,
  122. shell: true
  123. });
  124. } else if (type === 'archive') {
  125. yield (0, (_ExponentTools || _load_ExponentTools()).spawnAsync)('/bin/mv', [`ExpoKitApp.xcarchive`, output], {
  126. stdio: 'inherit',
  127. cwd: `${context.data.archivePath}/../../../..`
  128. });
  129. }
  130. }
  131. });
  132. return function _configureAndCopyShellAppArchiveAsync(_x10) {
  133. return _ref4.apply(this, arguments);
  134. };
  135. })();
  136. let _createShellAppWorkspaceAsync = (() => {
  137. var _ref5 = _asyncToGenerator(function* (context, skipRepoUpdate) {
  138. if ((_fsExtra || _load_fsExtra()).default.existsSync(context.build.ios.workspaceSourcePath)) {
  139. console.log(`Removing existing workspace at ${context.build.ios.workspaceSourcePath}...`);
  140. try {
  141. (_rimraf || _load_rimraf()).default.sync(context.build.ios.workspaceSourcePath);
  142. } catch (_) {}
  143. }
  144. yield (_IosWorkspace || _load_IosWorkspace()).createDetachedAsync(context);
  145. yield _podInstallAsync(context.build.ios.workspaceSourcePath, !skipRepoUpdate);
  146. });
  147. return function _createShellAppWorkspaceAsync(_x11, _x12) {
  148. return _ref5.apply(this, arguments);
  149. };
  150. })();
  151. /**
  152. * possible args:
  153. * @param configuration StandaloneBuildConfiguration (Debug or Release)
  154. * @param verbose show all xcodebuild output (default false)
  155. * @param reuseWorkspace if true, when building, assume a detached workspace already exists rather than creating a new one.
  156. * @param skipRepoUpdate if true, when building, omit `--repo-update` cocoapods flag.
  157. */
  158. let _buildAndCopyShellAppArtifactAsync = (() => {
  159. var _ref6 = _asyncToGenerator(function* (args) {
  160. const context = yield _createStandaloneContextAsync(args);
  161. const { verbose, type, reuseWorkspace } = args;
  162. const { projectName } = (_IosWorkspace || _load_IosWorkspace()).getPaths(context);
  163. if (!reuseWorkspace) {
  164. yield _createShellAppWorkspaceAsync(context, args.skipRepoUpdate);
  165. }
  166. const pathToArtifact = yield _buildAsync(projectName, context.build.ios.workspaceSourcePath, context.build.configuration, type, _path.default.relative(context.build.ios.workspaceSourcePath, '../shellAppBase'), verbose);
  167. const artifactDestPath = _path.default.join('../shellAppBase-builds', type, context.build.configuration);
  168. console.log(`\nFinished building, copying artifact to ${_path.default.resolve(artifactDestPath)}...`);
  169. if ((_fsExtra || _load_fsExtra()).default.existsSync(artifactDestPath)) {
  170. yield (0, (_ExponentTools || _load_ExponentTools()).spawnAsyncThrowError)('/bin/rm', ['-rf', artifactDestPath]);
  171. }
  172. console.log(`mkdir -p ${artifactDestPath}`);
  173. yield (0, (_ExponentTools || _load_ExponentTools()).spawnAsyncThrowError)('/bin/mkdir', ['-p', artifactDestPath]);
  174. console.log(`cp -R ${pathToArtifact} ${artifactDestPath}`);
  175. yield (0, (_ExponentTools || _load_ExponentTools()).spawnAsyncThrowError)('/bin/cp', ['-R', pathToArtifact, artifactDestPath]);
  176. });
  177. return function _buildAndCopyShellAppArtifactAsync(_x13) {
  178. return _ref6.apply(this, arguments);
  179. };
  180. })();
  181. /**
  182. * possible args in addition to action-specific args:
  183. * @param action
  184. * build - build a binary
  185. * configure - don't build anything, just configure the files in an existing NSBundle
  186. * @param type type of artifact to build or configure (simulator or archive)
  187. */
  188. let createIOSShellAppAsync = (() => {
  189. var _ref7 = _asyncToGenerator(function* (args) {
  190. args = _validateCLIArgs(args);
  191. if (args.action === 'build') {
  192. yield _buildAndCopyShellAppArtifactAsync(args);
  193. } else if (args.action === 'configure') {
  194. yield _configureAndCopyShellAppArchiveAsync(args);
  195. }
  196. });
  197. return function createIOSShellAppAsync(_x14) {
  198. return _ref7.apply(this, arguments);
  199. };
  200. })();
  201. var _fsExtra;
  202. function _load_fsExtra() {
  203. return _fsExtra = _interopRequireDefault(require('fs-extra'));
  204. }
  205. var _path = _interopRequireDefault(require('path'));
  206. var _rimraf;
  207. function _load_rimraf() {
  208. return _rimraf = _interopRequireDefault(require('rimraf'));
  209. }
  210. var _ExponentTools;
  211. function _load_ExponentTools() {
  212. return _ExponentTools = require('./ExponentTools');
  213. }
  214. var _IosNSBundle;
  215. function _load_IosNSBundle() {
  216. return _IosNSBundle = _interopRequireWildcard(require('./IosNSBundle'));
  217. }
  218. var _IosWorkspace;
  219. function _load_IosWorkspace() {
  220. return _IosWorkspace = _interopRequireWildcard(require('./IosWorkspace'));
  221. }
  222. var _StandaloneBuildFlags;
  223. function _load_StandaloneBuildFlags() {
  224. return _StandaloneBuildFlags = _interopRequireDefault(require('./StandaloneBuildFlags'));
  225. }
  226. var _StandaloneContext;
  227. function _load_StandaloneContext() {
  228. return _StandaloneContext = _interopRequireDefault(require('./StandaloneContext'));
  229. }
  230. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  231. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  232. function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
  233. function _validateCLIArgs(args) {
  234. args.type = args.type || 'archive';
  235. args.configuration = args.configuration || 'Release';
  236. args.verbose = args.verbose || false;
  237. switch (args.type) {
  238. case 'simulator':
  239. {
  240. if (args.configuration !== 'Debug' && args.configuration !== 'Release') {
  241. throw new Error(`Unsupported build configuration ${args.configuration}`);
  242. }
  243. break;
  244. }
  245. case 'archive':
  246. {
  247. if (args.configuration !== 'Release') {
  248. throw new Error('Release is the only supported configuration when archiving');
  249. }
  250. break;
  251. }
  252. default:
  253. {
  254. throw new Error(`Unsupported build type ${args.type}`);
  255. }
  256. }
  257. switch (args.action) {
  258. case 'configure':
  259. {
  260. if (!args.url) {
  261. throw new Error('Must run with `--url MANIFEST_URL`');
  262. }
  263. if (!args.sdkVersion) {
  264. throw new Error('Must run with `--sdkVersion SDK_VERSION`');
  265. }
  266. if (!args.archivePath) {
  267. throw new Error('Need to provide --archivePath <path to existing archive for configuration>');
  268. }
  269. break;
  270. }
  271. case 'build':
  272. {
  273. break;
  274. }
  275. default:
  276. {
  277. throw new Error(`Unsupported build action ${args.action}`);
  278. }
  279. }
  280. return args;
  281. }exports.createIOSShellAppAsync = createIOSShellAppAsync;
  282. //# sourceMappingURL=../__sourcemaps__/detach/IosShellApp.js.map