pulsar/script/config.js

124 lines
3.4 KiB
JavaScript
Raw Normal View History

// This module exports paths, names, and other metadata that is referenced
// throughout the build.
2019-05-31 19:33:56 +03:00
'use strict';
2019-05-31 19:33:56 +03:00
const fs = require('fs');
const path = require('path');
const spawnSync = require('./lib/spawn-sync');
2019-05-31 19:33:56 +03:00
const repositoryRootPath = path.resolve(__dirname, '..');
const apmRootPath = path.join(repositoryRootPath, 'apm');
const scriptRootPath = path.join(repositoryRootPath, 'script');
const buildOutputPath = path.join(repositoryRootPath, 'out');
const docsOutputPath = path.join(repositoryRootPath, 'docs', 'output');
const intermediateAppPath = path.join(buildOutputPath, 'app');
const symbolsPath = path.join(buildOutputPath, 'symbols');
const electronDownloadPath = path.join(repositoryRootPath, 'electron');
const homeDirPath = process.env.HOME || process.env.USERPROFILE;
const atomHomeDirPath =
process.env.ATOM_HOME || path.join(homeDirPath, '.atom');
2019-06-01 01:29:10 +03:00
const appMetadata = require(path.join(repositoryRootPath, 'package.json'));
const apmMetadata = require(path.join(apmRootPath, 'package.json'));
const computedAppVersion = computeAppVersion(
process.env.ATOM_RELEASE_VERSION || appMetadata.version
);
const channel = getChannel(computedAppVersion);
const appName = getAppName(channel);
const executableName = getExecutableName(channel, appName);
const channelName = getChannelName(channel);
2016-08-02 15:04:45 +03:00
module.exports = {
2017-01-25 19:13:42 +03:00
appMetadata,
apmMetadata,
channel,
channelName,
appName,
executableName,
computedAppVersion,
2017-01-25 19:13:42 +03:00
repositoryRootPath,
apmRootPath,
scriptRootPath,
buildOutputPath,
docsOutputPath,
intermediateAppPath,
symbolsPath,
electronDownloadPath,
atomHomeDirPath,
homeDirPath,
getApmBinPath,
getNpmBinPath,
snapshotAuxiliaryData: {}
2019-05-31 19:33:56 +03:00
};
2016-07-28 19:52:23 +03:00
function getChannelName(channel) {
2019-06-26 17:32:07 +03:00
return channel === 'stable' ? 'atom' : `atom-${channel}`;
}
2019-05-31 19:33:56 +03:00
function getChannel(version) {
const match = version.match(/\d+\.\d+\.\d+(-([a-z]+)(\d+|-\w{4,})?)?$/);
2018-06-24 01:09:13 +03:00
if (!match) {
2019-05-31 19:33:56 +03:00
throw new Error(`Found incorrectly formatted Atom version ${version}`);
2018-06-24 01:09:13 +03:00
} else if (match[2]) {
2019-05-31 19:33:56 +03:00
return match[2];
2016-07-28 19:52:23 +03:00
}
2018-06-24 01:09:13 +03:00
2019-05-31 19:33:56 +03:00
return 'stable';
2016-07-28 19:52:23 +03:00
}
2019-05-31 19:33:56 +03:00
function getAppName(channel) {
return channel === 'stable'
? 'Atom'
2019-05-31 19:33:56 +03:00
: `Atom ${process.env.ATOM_CHANNEL_DISPLAY_NAME ||
channel.charAt(0).toUpperCase() + channel.slice(1)}`;
}
2019-06-01 01:29:10 +03:00
function getExecutableName(channel, appName) {
if (process.platform === 'darwin') {
2019-06-01 01:29:10 +03:00
return appName;
} else if (process.platform === 'win32') {
2019-06-01 01:29:10 +03:00
return channel === 'stable' ? 'atom.exe' : `atom-${channel}.exe`;
} else {
2019-06-01 01:29:10 +03:00
return 'atom';
}
}
2019-06-01 01:29:10 +03:00
function computeAppVersion(version) {
2018-06-24 01:09:13 +03:00
if (version.match(/-dev$/)) {
2019-05-31 19:33:56 +03:00
const result = spawnSync('git', ['rev-parse', '--short', 'HEAD'], {
cwd: repositoryRootPath
});
const commitHash = result.stdout.toString().trim();
version += '-' + commitHash;
}
2019-05-31 19:33:56 +03:00
return version;
}
2019-05-31 19:33:56 +03:00
function getApmBinPath() {
const apmBinName = process.platform === 'win32' ? 'apm.cmd' : 'apm';
return path.join(
apmRootPath,
'node_modules',
'atom-package-manager',
'bin',
apmBinName
);
2016-08-02 15:04:45 +03:00
}
2019-05-31 19:33:56 +03:00
function getNpmBinPath(external = false) {
if (process.env.NPM_BIN_PATH) return process.env.NPM_BIN_PATH;
2019-05-31 19:33:56 +03:00
const npmBinName = process.platform === 'win32' ? 'npm.cmd' : 'npm';
const localNpmBinPath = path.resolve(
repositoryRootPath,
'script',
'node_modules',
'.bin',
npmBinName
);
return !external && fs.existsSync(localNpmBinPath)
? localNpmBinPath
: npmBinName;
2016-08-02 15:04:45 +03:00
}