Typescriptify the main process code (9/N)
Summary: Converted scripts/build-release.js and scripts/build-headless.js to typescript Reviewed By: passy Differential Revision: D20066504 fbshipit-source-id: 25f336062361e1211b581f96979978a6bf4fe6d4
This commit is contained in:
committed by
Facebook Github Bot
parent
09d0b4c841
commit
caf04e4e4a
22
package.json
22
package.json
@@ -83,6 +83,7 @@
|
||||
"@types/react-redux": "^7.1.5",
|
||||
"@types/react-virtualized-auto-sizer": "^1.0.0",
|
||||
"@types/react-window": "^1.8.1",
|
||||
"@types/recursive-readdir": "^2.2.0",
|
||||
"@types/redux-persist": "^4.3.1",
|
||||
"@types/requestidlecallback": "^0.3.1",
|
||||
"@types/rsocket-core": "^0.0.5",
|
||||
@@ -90,9 +91,10 @@
|
||||
"@types/testing-library__react": "^9.1.2",
|
||||
"@types/tmp": "^0.1.0",
|
||||
"@types/uuid": "^3.4.5",
|
||||
"@typescript-eslint/eslint-plugin": "^2.19.2",
|
||||
"@typescript-eslint/parser": "^2.19.2",
|
||||
"@types/ws": "^7.2.0",
|
||||
"@types/yazl": "^2.4.2",
|
||||
"@typescript-eslint/eslint-plugin": "^2.19.2",
|
||||
"@typescript-eslint/parser": "^2.19.2",
|
||||
"babel-code-frame": "^6.26.0",
|
||||
"babel-eslint": "^10.0.1",
|
||||
"electron": "7.1.2",
|
||||
@@ -214,18 +216,20 @@
|
||||
"rm-modules": "rimraf node_modules static/node_modules",
|
||||
"rm-temp": "rimraf $TMPDIR/jest* $TMPDIR/react-native-packager*",
|
||||
"rm-bundle": "rimraf static/main.bundle.*",
|
||||
"reset": "yarn rm-dist && yarn rm-temp && yarn cache clean && yarn rm-modules && yarn rm-bundle",
|
||||
"start": "cross-env NODE_ENV=development ts-node --files scripts/start-dev-server.ts --inspect=9229",
|
||||
"start:break": "cross-env NODE_ENV=development ts-node scripts/start-dev-server.ts --inspect-brk=9229",
|
||||
"start:no-embedded-plugins": "cross-env NODE_ENV=development cross-env FLIPPER_NO_EMBEDDED_PLUGINS=true ts-node scripts/start-dev-server.ts",
|
||||
"build": "yarn rm-dist && cross-env NODE_ENV=production node scripts/build-release.js $@",
|
||||
"build-headless": "yarn rm-dist && mkdir dist && cross-env NODE_ENV=production node scripts/build-headless.js $@",
|
||||
"reset": "yarn rm-dist && yarn rm-temp && yarn cache clean && yarn rm-bundle && yarn rm-modules",
|
||||
"start": "cross-env NODE_ENV=development TS_NODE_FILES=true node --require ts-node/register scripts/start-dev-server.ts --inspect=9229",
|
||||
"start:break": "cross-env NODE_ENV=development TS_NODE_FILES=true node --require ts-node/register scripts/start-dev-server.ts --inspect-brk=9229",
|
||||
"start:no-embedded-plugins": "cross-env NODE_ENV=development cross-env FLIPPER_NO_EMBEDDED_PLUGINS=true TS_NODE_FILES=true node --require ts-node/register scripts/start-dev-server.ts",
|
||||
"build": "yarn rm-dist && cross-env NODE_ENV=production TS_NODE_FILES=true node --require ts-node/register scripts/build-release.ts $@",
|
||||
"build-headless": "yarn rm-dist && mkdir dist && cross-env NODE_ENV=production TS_NODE_FILES=true node --require ts-node/register scripts/build-headless.ts $@",
|
||||
"fix": "eslint . --fix --ext .js,.tsx",
|
||||
"test": "jest --testPathPattern=\"node\\.(js|tsx)$\" --no-cache",
|
||||
"test:debug": "node --inspect node_modules/.bin/jest --runInBand",
|
||||
"test-electron": "jest --testPathPattern=\"electron\\.(js|tsx)$\" --testEnvironment=@jest-runner/electron/environment --runner=@jest-runner/electron --no-cache",
|
||||
"test-with-device": "USE_ELECTRON_STUBS=1 jest --testPathPattern=\"device\\.(js|tsx)$\" --detectOpenHandles --no-cache",
|
||||
"lint": "eslint . --ext .js,.ts,.tsx && flow check && tsc --noemit"
|
||||
"tsc": "tsc --noemit",
|
||||
"lint": "eslint . --ext .js,.ts,.tsx && flow check && yarn tsc",
|
||||
"everything": "yarn reset && yarn install && yarn lint && yarn test && yarn test-electron && yarn build --mac --win --linux && yarn build-headless --mac --linux && yarn start"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"7zip-bin-mac": "^1.0.1"
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const lineReplace = require('line-replace');
|
||||
const yazl = require('yazl');
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import lineReplace from 'line-replace';
|
||||
import yazl from 'yazl';
|
||||
const {exec: createBinary} = require('pkg');
|
||||
const {
|
||||
buildFolder,
|
||||
@@ -22,10 +22,14 @@ const {
|
||||
|
||||
const PLUGINS_FOLDER_NAME = 'plugins';
|
||||
|
||||
function preludeBundle(dir, versionNumber, buildRevision) {
|
||||
function preludeBundle(
|
||||
dir: string,
|
||||
versionNumber: string,
|
||||
buildRevision: string,
|
||||
) {
|
||||
const revisionStr =
|
||||
buildRevision == null ? '' : `global.__REVISION__="${buildRevision}";`;
|
||||
return new Promise((resolve, reject) =>
|
||||
return new Promise(resolve =>
|
||||
lineReplace({
|
||||
file: path.join(dir, 'bundle.js'),
|
||||
line: 1,
|
||||
@@ -36,8 +40,8 @@ function preludeBundle(dir, versionNumber, buildRevision) {
|
||||
);
|
||||
}
|
||||
|
||||
async function createZip(buildDir, distDir, targets) {
|
||||
return new Promise((resolve, reject) => {
|
||||
async function createZip(buildDir: string, distDir: string, targets: string[]) {
|
||||
return new Promise(resolve => {
|
||||
const zip = new yazl.ZipFile();
|
||||
|
||||
// add binaries for each target
|
||||
@@ -64,9 +68,8 @@ async function createZip(buildDir, distDir, targets) {
|
||||
}
|
||||
|
||||
(async () => {
|
||||
const targets = {};
|
||||
let platformPostfix;
|
||||
|
||||
const targets: {mac?: string; linux?: string; win?: string} = {};
|
||||
let platformPostfix: string = '';
|
||||
if (process.argv.indexOf('--mac') > -1) {
|
||||
targets.mac = 'node10-macos-x64';
|
||||
platformPostfix = '-macos';
|
||||
@@ -79,13 +82,13 @@ async function createZip(buildDir, distDir, targets) {
|
||||
targets.win = 'node10-win-x64';
|
||||
platformPostfix = '-win';
|
||||
}
|
||||
if (targets.length === 0) {
|
||||
const length = Object.keys(targets).length;
|
||||
if (length === 0) {
|
||||
throw new Error('No targets specified. eg. --mac, --win, or --linux');
|
||||
} else if (Object.keys(targets).length > 1) {
|
||||
} else if (length > 1) {
|
||||
// platformPostfix is automatically added by pkg
|
||||
platformPostfix = '';
|
||||
}
|
||||
|
||||
// Compiling all plugins takes a long time. Use this flag for quicker
|
||||
// developement iteration by not including any plugins.
|
||||
const skipPlugins = process.argv.indexOf('--no-plugins') > -1;
|
||||
@@ -7,11 +7,10 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
const path = require('path');
|
||||
const fs = require('fs-extra');
|
||||
const builder = require('electron-builder');
|
||||
const Platform = builder.Platform;
|
||||
const cp = require('promisify-child-process');
|
||||
import path from 'path';
|
||||
import fs from 'fs-extra';
|
||||
import {Platform, Arch, ElectronDownloadOptions, build} from 'electron-builder';
|
||||
import {spawn} from 'promisify-child-process';
|
||||
const {
|
||||
buildFolder,
|
||||
compile,
|
||||
@@ -21,14 +20,14 @@ const {
|
||||
getVersionNumber,
|
||||
genMercurialRevision,
|
||||
} = require('./build-utils.js');
|
||||
const fetch = require('node-fetch');
|
||||
import fetch from 'node-fetch';
|
||||
const {
|
||||
ICONS,
|
||||
buildLocalIconPath,
|
||||
getIconURL,
|
||||
} = require('../src/utils/icons.js');
|
||||
|
||||
function generateManifest(versionNumber) {
|
||||
function generateManifest(versionNumber: string) {
|
||||
const filePath = path.join(__dirname, '..', 'dist');
|
||||
if (!fs.existsSync(filePath)) {
|
||||
fs.mkdirSync(filePath);
|
||||
@@ -42,7 +41,11 @@ function generateManifest(versionNumber) {
|
||||
);
|
||||
}
|
||||
|
||||
function modifyPackageManifest(buildFolder, versionNumber, hgRevision) {
|
||||
function modifyPackageManifest(
|
||||
buildFolder: string,
|
||||
versionNumber: string,
|
||||
hgRevision: string,
|
||||
) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('Creating package.json manifest');
|
||||
const manifest = require('../package.json');
|
||||
@@ -63,14 +66,14 @@ function modifyPackageManifest(buildFolder, versionNumber, hgRevision) {
|
||||
);
|
||||
}
|
||||
|
||||
async function buildDist(buildFolder) {
|
||||
const targetsRaw = [];
|
||||
const postBuildCallbacks = [];
|
||||
async function buildDist(buildFolder: string) {
|
||||
const targetsRaw: Map<Platform, Map<Arch, string[]>>[] = [];
|
||||
const postBuildCallbacks: (() => void)[] = [];
|
||||
|
||||
if (process.argv.indexOf('--mac') > -1) {
|
||||
targetsRaw.push(Platform.MAC.createTarget(['dir']));
|
||||
postBuildCallbacks.push(() =>
|
||||
cp.spawn('zip', ['-qyr9', '../Flipper-mac.zip', 'Flipper.app'], {
|
||||
spawn('zip', ['-qyr9', '../Flipper-mac.zip', 'Flipper.app'], {
|
||||
cwd: path.join(__dirname, '..', 'dist', 'mac'),
|
||||
encoding: 'utf-8',
|
||||
}),
|
||||
@@ -87,19 +90,19 @@ async function buildDist(buildFolder) {
|
||||
}
|
||||
|
||||
// merge all target maps into a single map
|
||||
let targetsMerged = [];
|
||||
let targetsMerged: [Platform, Map<Arch, string[]>][] = [];
|
||||
for (const target of targetsRaw) {
|
||||
targetsMerged = targetsMerged.concat(Array.from(target));
|
||||
}
|
||||
const targets = new Map(targetsMerged);
|
||||
|
||||
const electronDownload = {};
|
||||
const electronDownloadOptions: ElectronDownloadOptions = {};
|
||||
if (process.env.electron_config_cache) {
|
||||
electronDownload.cache = process.env.electron_config_cache;
|
||||
electronDownloadOptions.cache = process.env.electron_config_cache;
|
||||
}
|
||||
|
||||
try {
|
||||
await builder.build({
|
||||
await build({
|
||||
publish: 'never',
|
||||
config: {
|
||||
appId: `com.facebook.sonar`,
|
||||
@@ -107,7 +110,7 @@ async function buildDist(buildFolder) {
|
||||
buildResources: path.join(__dirname, '..', 'static'),
|
||||
output: path.join(__dirname, '..', 'dist'),
|
||||
},
|
||||
electronDownload,
|
||||
electronDownload: electronDownloadOptions,
|
||||
npmRebuild: false,
|
||||
},
|
||||
projectDir: buildFolder,
|
||||
@@ -119,17 +122,19 @@ async function buildDist(buildFolder) {
|
||||
}
|
||||
}
|
||||
|
||||
function copyStaticFolder(buildFolder) {
|
||||
function copyStaticFolder(buildFolder: string) {
|
||||
fs.copySync(path.join(__dirname, '..', 'static'), buildFolder, {
|
||||
dereference: true,
|
||||
});
|
||||
}
|
||||
|
||||
function downloadIcons(buildFolder) {
|
||||
function downloadIcons(buildFolder: string) {
|
||||
const iconURLs = Object.entries(ICONS).reduce((acc, [name, sizes]) => {
|
||||
acc.push(
|
||||
// get icons in @1x and @2x
|
||||
// @ts-ignore
|
||||
...sizes.map(size => ({name, size, density: 1})),
|
||||
// @ts-ignore
|
||||
...sizes.map(size => ({name, size, density: 2})),
|
||||
);
|
||||
return acc;
|
||||
@@ -7,7 +7,6 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
/* This file needs to be plain JS to be imported by scripts/build-release.js */
|
||||
/* eslint-disable import/no-commonjs */
|
||||
|
||||
const AVAILABLE_SIZES = [8, 10, 12, 16, 18, 20, 24, 32];
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
"jsx": "react",
|
||||
"moduleResolution": "node",
|
||||
"baseUrl": ".",
|
||||
"downlevelIteration": true,
|
||||
"downlevelIteration": true,
|
||||
"skipLibCheck": true,
|
||||
"paths": {
|
||||
"flipper": ["./src/index.tsx"],
|
||||
"live-plugin-manager": ["./types/live-plugin-manager.d.tsx"]
|
||||
|
||||
18
types/line-replace.d.ts
vendored
Normal file
18
types/line-replace.d.ts
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
declare module 'line-replace' {
|
||||
export default function(args: {
|
||||
file: string;
|
||||
line: number;
|
||||
text: string;
|
||||
addNewLine: boolean;
|
||||
callback: (args: {file: string; line: number; replacedText: string; text: string}) => void;
|
||||
}): void;
|
||||
}
|
||||
14
yarn.lock
14
yarn.lock
@@ -1589,6 +1589,13 @@
|
||||
"@types/prop-types" "*"
|
||||
csstype "^2.2.0"
|
||||
|
||||
"@types/recursive-readdir@^2.2.0":
|
||||
version "2.2.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/recursive-readdir/-/recursive-readdir-2.2.0.tgz#b39cd5474fd58ea727fe434d5c68b7a20ba9121c"
|
||||
integrity sha512-HGk753KRu2N4mWduovY4BLjYq4jTOL29gV2OfGdGxHcPSWGFkC5RRIdk+VTs5XmYd7MVAD+JwKrcb5+5Y7FOCg==
|
||||
dependencies:
|
||||
"@types/node" "*"
|
||||
|
||||
"@types/redux-devtools-extension@^2.13.2":
|
||||
version "2.13.2"
|
||||
resolved "https://registry.yarnpkg.com/@types/redux-devtools-extension/-/redux-devtools-extension-2.13.2.tgz#b2e09a8c163b2b0f5072e6a5ac41474000df2111"
|
||||
@@ -1759,6 +1766,13 @@
|
||||
dependencies:
|
||||
"@types/yargs-parser" "*"
|
||||
|
||||
"@types/yazl@^2.4.2":
|
||||
version "2.4.2"
|
||||
resolved "https://registry.yarnpkg.com/@types/yazl/-/yazl-2.4.2.tgz#d5f8a4752261badbf1a36e8b49e042dc18ec84bc"
|
||||
integrity sha512-T+9JH8O2guEjXNxqmybzQ92mJUh2oCwDDMSSimZSe1P+pceZiFROZLYmcbqkzV5EUwz6VwcKXCO2S2yUpra6XQ==
|
||||
dependencies:
|
||||
"@types/node" "*"
|
||||
|
||||
"@typescript-eslint/eslint-plugin@^2.19.2":
|
||||
version "2.19.2"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.19.2.tgz#e279aaae5d5c1f2547b4cff99204e1250bc7a058"
|
||||
|
||||
Reference in New Issue
Block a user