197 lines
8.3 KiB
JavaScript
197 lines
8.3 KiB
JavaScript
// Copyright 2015-present 650 Industries. All rights reserved.
|
|
'use strict';
|
|
|
|
// Set EXPO_VIEW_DIR to universe/exponent to test locally
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.detachAndroidAsync = undefined;
|
|
|
|
let regexFileAsync = (() => {
|
|
var _ref = _asyncToGenerator(function* (filename, regex, replace) {
|
|
let file = yield (_fsExtra || _load_fsExtra()).default.readFile(filename);
|
|
let fileString = file.toString();
|
|
yield (_fsExtra || _load_fsExtra()).default.writeFile(filename, fileString.replace(regex, replace));
|
|
});
|
|
|
|
return function regexFileAsync(_x, _x2, _x3) {
|
|
return _ref.apply(this, arguments);
|
|
};
|
|
})();
|
|
|
|
let renamePackageAsync = (() => {
|
|
var _ref2 = _asyncToGenerator(function* (directory, originalPkg, destPkg) {
|
|
let originalSplitPackage = originalPkg.split('.');
|
|
let originalDeepDirectory = directory;
|
|
for (let i = 0; i < originalSplitPackage.length; i++) {
|
|
originalDeepDirectory = _path.default.join(originalDeepDirectory, originalSplitPackage[i]);
|
|
}
|
|
|
|
// copy files into temp directory
|
|
let tmpDirectory = _path.default.join(directory, 'tmp-exponent-directory');
|
|
(_mkdirp || _load_mkdirp()).default.sync(tmpDirectory);
|
|
yield (_Utils || _load_Utils()).ncpAsync(originalDeepDirectory, tmpDirectory);
|
|
|
|
// delete old package
|
|
(_rimraf || _load_rimraf()).default.sync(_path.default.join(directory, originalSplitPackage[0]));
|
|
|
|
// make new package
|
|
let newSplitPackage = destPkg.split('.');
|
|
let newDeepDirectory = directory;
|
|
for (let i = 0; i < newSplitPackage.length; i++) {
|
|
newDeepDirectory = _path.default.join(newDeepDirectory, newSplitPackage[i]);
|
|
(_mkdirp || _load_mkdirp()).default.sync(newDeepDirectory);
|
|
}
|
|
|
|
// copy from temp to new package
|
|
yield (_Utils || _load_Utils()).ncpAsync(tmpDirectory, newDeepDirectory);
|
|
|
|
// delete temp
|
|
(_rimraf || _load_rimraf()).default.sync(tmpDirectory);
|
|
});
|
|
|
|
return function renamePackageAsync(_x4, _x5, _x6) {
|
|
return _ref2.apply(this, arguments);
|
|
};
|
|
})();
|
|
|
|
let detachAndroidAsync = exports.detachAndroidAsync = (() => {
|
|
var _ref3 = _asyncToGenerator(function* (projectRoot, expoDirectory, sdkVersion, experienceUrl, manifest, expoViewUrl) {
|
|
let tmpExpoDirectory;
|
|
if (process.env.EXPO_VIEW_DIR) {
|
|
// Only for testing
|
|
tmpExpoDirectory = process.env.EXPO_VIEW_DIR;
|
|
} else {
|
|
tmpExpoDirectory = _path.default.join(projectRoot, 'temp-android-directory');
|
|
(_mkdirp || _load_mkdirp()).default.sync(tmpExpoDirectory);
|
|
console.log('Downloading Android code...');
|
|
yield (_Api || _load_Api()).default.downloadAsync(expoViewUrl, tmpExpoDirectory, { extract: true });
|
|
}
|
|
|
|
let androidProjectDirectory = _path.default.join(projectRoot, 'android');
|
|
|
|
console.log('Moving Android project files...');
|
|
|
|
yield (_Utils || _load_Utils()).ncpAsync(_path.default.join(tmpExpoDirectory, 'android', 'maven'), _path.default.join(expoDirectory, 'maven'));
|
|
yield (_Utils || _load_Utils()).ncpAsync(_path.default.join(tmpExpoDirectory, 'android', 'detach-scripts'), _path.default.join(expoDirectory, 'detach-scripts'));
|
|
yield (_Utils || _load_Utils()).ncpAsync(_path.default.join(tmpExpoDirectory, 'exponent-view-template', 'android'), androidProjectDirectory);
|
|
if (process.env.EXPO_VIEW_DIR) {
|
|
(_rimraf || _load_rimraf()).default.sync(_path.default.join(androidProjectDirectory, 'build'));
|
|
(_rimraf || _load_rimraf()).default.sync(_path.default.join(androidProjectDirectory, 'app', 'build'));
|
|
}
|
|
|
|
// Fix up app/build.gradle
|
|
console.log('Configuring Android project...');
|
|
let appBuildGradle = _path.default.join(androidProjectDirectory, 'app', 'build.gradle');
|
|
yield regexFileAsync(appBuildGradle, /\/\* UNCOMMENT WHEN DISTRIBUTING/g, '');
|
|
yield regexFileAsync(appBuildGradle, /END UNCOMMENT WHEN DISTRIBUTING \*\//g, '');
|
|
yield regexFileAsync(appBuildGradle, `compile project(':expoview')`, '');
|
|
|
|
// Fix AndroidManifest
|
|
let androidManifest = _path.default.join(androidProjectDirectory, 'app', 'src', 'main', 'AndroidManifest.xml');
|
|
yield regexFileAsync(androidManifest, 'PLACEHOLDER_DETACH_SCHEME', manifest.detach.scheme);
|
|
|
|
// Fix MainActivity
|
|
let mainActivity = _path.default.join(androidProjectDirectory, 'app', 'src', 'main', 'java', 'detach', 'app', 'template', 'pkg', 'name', 'MainActivity.java');
|
|
yield regexFileAsync(mainActivity, 'TEMPLATE_INITIAL_URL', experienceUrl);
|
|
|
|
// Fix package name
|
|
let packageName = manifest.android.package;
|
|
yield renamePackageAsync(_path.default.join(androidProjectDirectory, 'app', 'src', 'main', 'java'), ANDROID_TEMPLATE_PKG, packageName);
|
|
yield renamePackageAsync(_path.default.join(androidProjectDirectory, 'app', 'src', 'test', 'java'), ANDROID_TEMPLATE_PKG, packageName);
|
|
yield renamePackageAsync(_path.default.join(androidProjectDirectory, 'app', 'src', 'androidTest', 'java'), ANDROID_TEMPLATE_PKG, packageName);
|
|
|
|
let packageNameMatches = yield (0, (_globPromise || _load_globPromise()).default)(androidProjectDirectory + '/**/*.@(java|gradle|xml)');
|
|
if (packageNameMatches) {
|
|
let oldPkgRegex = new RegExp(`${ANDROID_TEMPLATE_PKG.replace(/\./g, '\\.')}`, 'g');
|
|
for (let i = 0; i < packageNameMatches.length; i++) {
|
|
yield regexFileAsync(packageNameMatches[i], oldPkgRegex, packageName);
|
|
}
|
|
}
|
|
|
|
// Fix app name
|
|
console.log('Naming Android project...');
|
|
let appName = manifest.name;
|
|
yield regexFileAsync(_path.default.resolve(androidProjectDirectory, 'app', 'src', 'main', 'res', 'values', 'strings.xml'), ANDROID_TEMPLATE_NAME, appName);
|
|
|
|
// Fix image
|
|
let icon = manifest.android && manifest.android.icon ? manifest.android.icon : manifest.icon;
|
|
if (icon) {
|
|
let iconMatches = yield (0, (_globPromise || _load_globPromise()).default)(_path.default.join(androidProjectDirectory, 'app', 'src', 'main', 'res') + '/**/ic_launcher.png');
|
|
if (iconMatches) {
|
|
for (let i = 0; i < iconMatches.length; i++) {
|
|
yield (_fsExtra || _load_fsExtra()).default.unlink(iconMatches[i]);
|
|
// TODO: make more efficient
|
|
yield (0, (_ExponentTools || _load_ExponentTools()).saveImageToPathAsync)(projectRoot, icon, iconMatches[i]);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Clean up
|
|
console.log('Cleaning up Android...');
|
|
if (!process.env.EXPO_VIEW_DIR) {
|
|
(0, (_ExponentTools || _load_ExponentTools()).rimrafDontThrow)(tmpExpoDirectory);
|
|
}
|
|
console.log('Android detach is complete!\n');
|
|
});
|
|
|
|
return function detachAndroidAsync(_x7, _x8, _x9, _x10, _x11, _x12) {
|
|
return _ref3.apply(this, arguments);
|
|
};
|
|
})();
|
|
|
|
var _mkdirp;
|
|
|
|
function _load_mkdirp() {
|
|
return _mkdirp = _interopRequireDefault(require('mkdirp'));
|
|
}
|
|
|
|
var _fsExtra;
|
|
|
|
function _load_fsExtra() {
|
|
return _fsExtra = _interopRequireDefault(require('fs-extra'));
|
|
}
|
|
|
|
var _path = _interopRequireDefault(require('path'));
|
|
|
|
var _rimraf;
|
|
|
|
function _load_rimraf() {
|
|
return _rimraf = _interopRequireDefault(require('rimraf'));
|
|
}
|
|
|
|
var _globPromise;
|
|
|
|
function _load_globPromise() {
|
|
return _globPromise = _interopRequireDefault(require('glob-promise'));
|
|
}
|
|
|
|
var _ExponentTools;
|
|
|
|
function _load_ExponentTools() {
|
|
return _ExponentTools = require('./ExponentTools');
|
|
}
|
|
|
|
var _Api;
|
|
|
|
function _load_Api() {
|
|
return _Api = _interopRequireDefault(require('../Api'));
|
|
}
|
|
|
|
var _Utils;
|
|
|
|
function _load_Utils() {
|
|
return _Utils = _interopRequireWildcard(require('../Utils'));
|
|
}
|
|
|
|
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; } }
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
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"); }); }; }
|
|
|
|
const ANDROID_TEMPLATE_PKG = 'detach.app.template.pkg.name';
|
|
const ANDROID_TEMPLATE_NAME = 'DetachAppTemplate';
|
|
//# sourceMappingURL=../__sourcemaps__/detach/OldAndroidDetach.js.map
|