Script for resolving plugin directory by its package name
Summary: Changed "build-plugin" script to allow triggering release by plugin name (required to enable triggering releases by button in Marketplace): 1) Added new script to resolve plugin dir by name 2) Allow passing either plugin dir or name to "build-plugin" script Reviewed By: passy Differential Revision: D22354643 fbshipit-source-id: b7aca57acefc81ca0b6d9c7f359f63d8f0599e39
This commit is contained in:
committed by
Facebook GitHub Bot
parent
b11082d229
commit
228d09d572
@@ -237,6 +237,7 @@
|
|||||||
"build-headless": "cross-env NODE_ENV=production ./ts-node scripts/build-headless.ts $@",
|
"build-headless": "cross-env NODE_ENV=production ./ts-node scripts/build-headless.ts $@",
|
||||||
"prebuild-plugin": "yarn build:pkg",
|
"prebuild-plugin": "yarn build:pkg",
|
||||||
"build-plugin": "./ts-node scripts/build-plugin.ts",
|
"build-plugin": "./ts-node scripts/build-plugin.ts",
|
||||||
|
"resolve-plugin-dir": "./ts-node scripts/resolve-plugin-dir.ts",
|
||||||
"open-dist": "open ../dist/mac/Flipper.app --args --launcher=false --inspect=9229",
|
"open-dist": "open ../dist/mac/Flipper.app --args --launcher=false --inspect=9229",
|
||||||
"fix": "eslint . --fix --ext .js,.ts,.tsx",
|
"fix": "eslint . --fix --ext .js,.ts,.tsx",
|
||||||
"pretest": "yarn build:pkg",
|
"pretest": "yarn build:pkg",
|
||||||
|
|||||||
@@ -11,16 +11,15 @@ import {pluginsDir, rootDir, distDir} from './paths';
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import {execSync} from 'child_process';
|
import {execSync} from 'child_process';
|
||||||
|
import {resolvePluginDir} from './workspaces';
|
||||||
|
|
||||||
(async function buildPlugin() {
|
(async function buildPlugin() {
|
||||||
const pluginDirArg = process.argv[2];
|
const pluginName = process.argv[2];
|
||||||
const pluginDir = await resolveAbsolutePluginDir(pluginDirArg);
|
const pluginDir = await resolvePluginDir(pluginName);
|
||||||
if (path.relative(pluginsDir, pluginDir).includes('..')) {
|
const outputFileArg = process.argv.length > 3 ? process.argv[3] : null;
|
||||||
throw new Error(
|
const outputFile = outputFileArg
|
||||||
`Plugin dir ${pluginDir} is not inside plugins directory ${pluginsDir}`,
|
? path.resolve(outputFileArg)
|
||||||
);
|
: path.join(
|
||||||
}
|
|
||||||
const outputFile = path.join(
|
|
||||||
distDir,
|
distDir,
|
||||||
'plugins',
|
'plugins',
|
||||||
path.relative(pluginsDir, pluginDir) + '.tgz',
|
path.relative(pluginsDir, pluginDir) + '.tgz',
|
||||||
@@ -32,23 +31,3 @@ import {execSync} from 'child_process';
|
|||||||
execSync(bundleCmd, {cwd: rootDir, stdio: 'inherit'});
|
execSync(bundleCmd, {cwd: rootDir, stdio: 'inherit'});
|
||||||
execSync(packCmd, {cwd: rootDir, stdio: 'inherit'});
|
execSync(packCmd, {cwd: rootDir, stdio: 'inherit'});
|
||||||
})();
|
})();
|
||||||
|
|
||||||
async function resolveAbsolutePluginDir(dir: string): Promise<string> {
|
|
||||||
if (path.isAbsolute(dir)) {
|
|
||||||
return dir;
|
|
||||||
}
|
|
||||||
const resolvedFromPluginDir = path.resolve(pluginsDir, dir);
|
|
||||||
if (await fs.pathExists(resolvedFromPluginDir)) {
|
|
||||||
return resolvedFromPluginDir;
|
|
||||||
}
|
|
||||||
const resolvedFromCwd = path.resolve(process.cwd(), dir);
|
|
||||||
if (await fs.pathExists(resolvedFromCwd)) {
|
|
||||||
return resolvedFromCwd;
|
|
||||||
}
|
|
||||||
throw new Error(
|
|
||||||
`Cannot resolve plugin dir path. Paths checked: ${[
|
|
||||||
resolvedFromPluginDir,
|
|
||||||
resolvedFromCwd,
|
|
||||||
]}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|||||||
16
desktop/scripts/resolve-plugin-dir.ts
Normal file
16
desktop/scripts/resolve-plugin-dir.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {resolvePluginDir} from './workspaces';
|
||||||
|
|
||||||
|
(async function () {
|
||||||
|
const pluginName = process.argv[2];
|
||||||
|
const pluginDir = await resolvePluginDir(pluginName);
|
||||||
|
console.log(pluginDir);
|
||||||
|
})();
|
||||||
@@ -211,3 +211,47 @@ export async function publishPackages({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function resolvePluginDir(name: string): Promise<string> {
|
||||||
|
const pluginDir =
|
||||||
|
(await resolvePluginByNameOrId(name)) ?? (await resolvePluginByPath(name));
|
||||||
|
if (!pluginDir) {
|
||||||
|
throw new Error(`Cannot find plugin by name or dir ${name}`);
|
||||||
|
} else {
|
||||||
|
return pluginDir;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function resolvePluginByNameOrId(
|
||||||
|
pluginName: string,
|
||||||
|
): Promise<string | undefined> {
|
||||||
|
const workspaces = await getWorkspaces();
|
||||||
|
const pluginDir = workspaces.packages
|
||||||
|
.filter((p) => p.isPlugin)
|
||||||
|
.find(
|
||||||
|
(p) =>
|
||||||
|
p.json.name === pluginName ||
|
||||||
|
p.json.id === pluginName ||
|
||||||
|
p.json.name === `flipper-plugin-${pluginName}`,
|
||||||
|
)?.dir;
|
||||||
|
return pluginDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function resolvePluginByPath(dir: string): Promise<string | undefined> {
|
||||||
|
if (path.isAbsolute(dir)) {
|
||||||
|
if (await fs.pathExists(dir)) {
|
||||||
|
return dir;
|
||||||
|
} else {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const resolvedFromPluginDir = path.resolve(pluginsDir, dir);
|
||||||
|
if (await fs.pathExists(resolvedFromPluginDir)) {
|
||||||
|
return resolvedFromPluginDir;
|
||||||
|
}
|
||||||
|
const resolvedFromCwd = path.resolve(process.cwd(), dir);
|
||||||
|
if (await fs.pathExists(resolvedFromCwd)) {
|
||||||
|
return resolvedFromCwd;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user