@interaktiv/mibuilder-core
Version:
Core libraries to interact with MiBuilder projects.
351 lines (277 loc) • 11.5 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.downloadMetadata = downloadMetadata;
exports.processDeliverTemplates = processDeliverTemplates;
exports.initMetadata = initMetadata;
exports.SCREENSHOTS_FOLDER_NAME = exports.ALL_META_SUB_DIRS = exports.REVIEW_INFORMATION_DIR = exports.TRADE_REPRESENTATIVE_CONTACT_INFORMATION_DIR = exports.REVIEW_INFORMATION_VALUES = exports.TRADE_REPRESENTATIVE_CONTACT_INFORMATION_VALUES = exports.NON_LOCALIZED_APP_VALUES = exports.LOCALIZED_APP_VALUES = exports.NON_LOCALIZED_VERSION_VALUES = exports.LOCALIZED_VERSION_VALUES = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _path = _interopRequireDefault(require("path"));
var _dxl = require("@interaktiv/dxl");
var _travelingFastlane = require("@interaktiv/traveling-fastlane");
var _types = require("@interaktiv/types");
var _mibuilderError = require("../mibuilder-error");
var _ux = require("../ux");
let cliUx;
async function getCliUx() {
if (cliUx == null) cliUx = await _ux.UX.create('deliver');
return cliUx;
} // Values taken from fastlane.tools source see
// https://github.com/fastlane/fastlane/blob/1af33c0884/deliver/lib/deliver/upload_metadata.rb
// All the localized values attached to the version
const LOCALIZED_VERSION_VALUES = ['description', 'keywords', 'release_notes', 'support_url', 'marketing_url', 'promotional_text']; // Everything attached to the version but not being localized
exports.LOCALIZED_VERSION_VALUES = LOCALIZED_VERSION_VALUES;
const NON_LOCALIZED_VERSION_VALUES = ['copyright']; // Localized app details values
exports.NON_LOCALIZED_VERSION_VALUES = NON_LOCALIZED_VERSION_VALUES;
const LOCALIZED_APP_VALUES = ['name', 'subtitle', 'privacy_url']; // Non localized app details values
exports.LOCALIZED_APP_VALUES = LOCALIZED_APP_VALUES;
const NON_LOCALIZED_APP_VALUES = ['primary_category', 'secondary_category', 'primary_first_sub_category', 'primary_second_sub_category', 'secondary_first_sub_category', 'secondary_second_sub_category']; // Trade Representative Contact Information values
exports.NON_LOCALIZED_APP_VALUES = NON_LOCALIZED_APP_VALUES;
const TRADE_REPRESENTATIVE_CONTACT_INFORMATION_VALUES = {
trade_representative_trade_name: 'trade_name',
trade_representative_first_name: 'first_name',
trade_representative_last_name: 'last_name',
trade_representative_address_line_1: 'address_line1',
trade_representative_address_line_2: 'address_line2',
trade_representative_address_line_3: 'address_line3',
trade_representative_city_name: 'city_name',
trade_representative_state: 'state',
trade_representative_country: 'country',
trade_representative_postal_code: 'postal_code',
trade_representative_phone_number: 'phone_number',
trade_representative_email: 'email_address',
trade_representative_is_displayed_on_app_store: 'is_displayed_on_app_store'
}; // Review information values
exports.TRADE_REPRESENTATIVE_CONTACT_INFORMATION_VALUES = TRADE_REPRESENTATIVE_CONTACT_INFORMATION_VALUES;
const REVIEW_INFORMATION_VALUES = {
review_first_name: 'first_name',
review_last_name: 'last_name',
review_phone_number: 'phone_number',
review_email: 'email_address',
review_demo_user: 'demo_user',
review_demo_password: 'demo_password',
review_notes: 'notes'
}; // Directory name it contains trade representative contact information
exports.REVIEW_INFORMATION_VALUES = REVIEW_INFORMATION_VALUES;
const TRADE_REPRESENTATIVE_CONTACT_INFORMATION_DIR = 'trade_representative_contact_information'; // Directory name it contains review information
exports.TRADE_REPRESENTATIVE_CONTACT_INFORMATION_DIR = TRADE_REPRESENTATIVE_CONTACT_INFORMATION_DIR;
const REVIEW_INFORMATION_DIR = 'review_information';
exports.REVIEW_INFORMATION_DIR = REVIEW_INFORMATION_DIR;
const ALL_META_SUB_DIRS = [TRADE_REPRESENTATIVE_CONTACT_INFORMATION_DIR, REVIEW_INFORMATION_DIR];
exports.ALL_META_SUB_DIRS = ALL_META_SUB_DIRS;
const SCREENSHOTS_FOLDER_NAME = 'screenshots';
exports.SCREENSHOTS_FOLDER_NAME = SCREENSHOTS_FOLDER_NAME;
async function downloadMetadata({
config = {},
paths = {},
force = false,
confirmForce = false
}) {
const {
rootDir
} = config;
if ((await (0, _dxl.exists)(rootDir)) === false) {
throw new _mibuilderError.MiBuilderError(`Kein gültiges Project in ${rootDir} gefunden`, 'InvalidProjectWorkspace', ['App Projekt erstellen über: $ mibuilder create:app']);
}
const {
fastlaneMetaDataDiriOS: projectMetaDataDiriOS
} = paths;
const deliverAlreadyInitialized = await (0, _dxl.exists)(_path.default.resolve(projectMetaDataDiriOS));
if (deliverAlreadyInitialized && force === true === false) {
throw new _mibuilderError.MiBuilderError('Metadaten bereits heruntergeladen', 'StoreMetadataExists', ['Set force param to true']);
}
if (deliverAlreadyInitialized && confirmForce) {
const cli = await getCliUx();
try {
const yesno = await cli.confirm(`Bestehende Metadata überschreiben?`);
if (yesno === false) {
throw new _mibuilderError.MiBuilderError('Metadaten Aktualisierung abgebrochen', 'MetadataDownloadAbort');
}
cliUx.log('');
cliUx.startSpinner('Aktualisiere Metadaten, überschreibe vorhandene');
} catch (err) {
// Ignore timeout error otherwise re-throw
if (/prompt timeout/gim.test(err.toString()) === false) throw err;
cliUx.log('');
cliUx.startSpinner('Aktualisiere Metadaten, überschreibe vorhandene');
}
}
await (0, _dxl.remove)(projectMetaDataDiriOS);
const runDeliverFromProject = (args = [], options = {}) => (0, _travelingFastlane.runBundleAction)('deliver', [...args], (0, _extends2.default)({
cwd: rootDir,
pipeStdout: true
}, options)); // INFO: We need to handle the force situation ourselves otherwise fastlane
// will prompt to overwrite existent metadata in any case, cause the dirs
// are already there but not the data itself. So force on every download
// command execution
const args = ['--force', '--verbose'].filter(Boolean);
await runDeliverFromProject(['download_metadata', ...args]);
await runDeliverFromProject(['download_screenshots', ...args]);
if (deliverAlreadyInitialized && confirmForce) cliUx.stopSpinner();
} // eslint-disable-next-line max-lines-per-function
async function processDeliverTemplates({
config = {},
locale = 'de-DE',
paths = {}
}) {
const {
fastlaneMetaDataDiriOS,
fastlaneScreenshotsDiriOS
} = paths;
const localizedMetaDataDir = _path.default.join(fastlaneMetaDataDiriOS, locale); // Localized version values
// Localized app values
await Promise.all([...LOCALIZED_VERSION_VALUES, ...LOCALIZED_APP_VALUES].map(name => {
let content;
switch (name) {
case 'keywords':
content = 'Steuerberater, Steuerberatung, Fachberater';
break;
case 'release_notes':
content = 'Fehlerkorrekturen und Leistungsverbesserungen';
break;
case 'name':
content = config.app.name;
break;
case 'privacy_url':
if (config.app.type === 'Steuerberater') {
content = 'https://www.deubner-steuern.de/index.php?id=[ID]';
} else {
content = 'https://www.deubner-recht.de/index.php?id=[ID]';
}
break;
case 'support':
content = 'https://www.deubner-verlag.de';
break;
default:
content = '';
}
return {
content,
name,
path: _path.default.resolve(localizedMetaDataDir, `${name}.txt`)
};
}).map(f => (0, _dxl.outputFile)(f.path, f.content))); // Non-localized version values
// Non-localized app values
await Promise.all([...NON_LOCALIZED_VERSION_VALUES, ...NON_LOCALIZED_APP_VALUES].map(name => {
let content;
switch (name) {
case 'copyright':
content = `${new Date().getFullYear()} ${config.app.copyright}`;
break;
case 'primary_category':
// For possible values see
// https://docs.fastlane.tools/actions/deliver/#reference
content = 'MZGenre.Finance';
break;
case 'secondary_category':
// For possible values see
// https://docs.fastlane.tools/actions/deliver/#reference
content = 'MZGenre.Business';
break;
default:
content = '';
}
return {
content,
name,
path: _path.default.resolve(fastlaneMetaDataDiriOS, `${name}.txt`)
};
}).map(f => (0, _dxl.outputFile)(f.path, f.content))); // Trade Representative Contact Information values
const tradeRepresentativeContactInformationDir = _path.default.join(fastlaneMetaDataDiriOS, TRADE_REPRESENTATIVE_CONTACT_INFORMATION_DIR);
await Promise.all((0, _types.definiteValuesOf)(TRADE_REPRESENTATIVE_CONTACT_INFORMATION_VALUES).map(name => {
let content;
switch (name) {
case 'trade_name':
content = 'Deubner Verlag GmbH & Co KG';
break;
case 'address_line1':
content = 'Oststr. 11';
break;
case 'city_name':
content = 'Köln';
break;
case 'country':
content = 'Germany';
break;
case 'postal_code':
content = '50996';
break;
case 'is_displayed_on_app_store':
content = 'false';
break;
default:
content = '';
}
return {
content,
name,
path: _path.default.resolve(tradeRepresentativeContactInformationDir, `${name}.txt`)
};
}).map(f => (0, _dxl.outputFile)(f.path, f.content))); // Review information values
const reviewInformationDir = _path.default.join(fastlaneMetaDataDiriOS, REVIEW_INFORMATION_DIR);
await Promise.all((0, _types.definiteValuesOf)(REVIEW_INFORMATION_VALUES).map(name => {
let content;
switch (name) {
case 'first_name':
content = 'Nora';
break;
case 'last_name':
content = 'Knetschke';
break;
case 'phone_number':
content = '+4922193701886';
break;
case 'email_address':
content = 'kanzleiapp@deubner-verlag.de';
break;
default:
content = '';
}
return {
content,
name,
path: _path.default.resolve(reviewInformationDir, `${name}.txt`)
};
}).map(f => (0, _dxl.outputFile)(f.path, f.content))); // Screenshots dir
await (0, _dxl.mkdirp)(_path.default.resolve(fastlaneScreenshotsDiriOS, locale)); // Ratings
await (0, _dxl.outputJson)(_path.default.resolve(fastlaneMetaDataDiriOS, 'rating.json'), {
CARTOON_FANTASY_VIOLENCE: 0,
REALISTIC_VIOLENCE: 0,
PROLONGED_GRAPHIC_SADISTIC_REALISTIC_VIOLENCE: 0,
PROFANITY_CRUDE_HUMOR: 0,
MATURE_SUGGESTIVE: 0,
HORROR: 0,
MEDICAL_TREATMENT_INFO: 0,
ALCOHOL_TOBACCO_DRUGS: 0,
GAMBLING: 0,
SEXUAL_CONTENT_NUDITY: 0,
GRAPHIC_SEXUAL_CONTENT_NUDITY: 0,
UNRESTRICTED_WEB_ACCESS: 0,
GAMBLING_CONTESTS: 0
});
}
async function initMetadata({
config = {},
paths = {},
force = false
}) {
try {
await downloadMetadata({
config,
paths,
force
});
} catch (err) {
if (err.name === 'StoreMetadataExists') return; // App does not exist on App Store Connect
if (/could not find app/gim.test(err.message)) {
await processDeliverTemplates({
config,
paths
});
return;
}
throw err;
}
}