mirror of
https://github.com/laurent22/joplin.git
synced 2024-11-24 08:12:24 +02:00
Tools: Add script to build plugin repository
This commit is contained in:
parent
ceb252b9ad
commit
734514b6d8
@ -1334,6 +1334,15 @@ packages/lib/uuid.js.map
|
||||
packages/lib/versionInfo.d.ts
|
||||
packages/lib/versionInfo.js
|
||||
packages/lib/versionInfo.js.map
|
||||
packages/plugins/ToggleSideBars/api/index.d.ts
|
||||
packages/plugins/ToggleSideBars/api/index.js
|
||||
packages/plugins/ToggleSideBars/api/index.js.map
|
||||
packages/plugins/ToggleSideBars/api/types.d.ts
|
||||
packages/plugins/ToggleSideBars/api/types.js
|
||||
packages/plugins/ToggleSideBars/api/types.js.map
|
||||
packages/plugins/ToggleSideBars/src/index.d.ts
|
||||
packages/plugins/ToggleSideBars/src/index.js
|
||||
packages/plugins/ToggleSideBars/src/index.js.map
|
||||
packages/renderer/HtmlToHtml.d.ts
|
||||
packages/renderer/HtmlToHtml.js
|
||||
packages/renderer/HtmlToHtml.js.map
|
||||
@ -1646,6 +1655,9 @@ packages/server/src/utils/urlUtils.js.map
|
||||
packages/server/src/utils/uuidgen.d.ts
|
||||
packages/server/src/utils/uuidgen.js
|
||||
packages/server/src/utils/uuidgen.js.map
|
||||
packages/tools/build-plugin-repository.d.ts
|
||||
packages/tools/build-plugin-repository.js
|
||||
packages/tools/build-plugin-repository.js.map
|
||||
packages/tools/release-server.d.ts
|
||||
packages/tools/release-server.js
|
||||
packages/tools/release-server.js.map
|
||||
|
12
.gitignore
vendored
12
.gitignore
vendored
@ -1323,6 +1323,15 @@ packages/lib/uuid.js.map
|
||||
packages/lib/versionInfo.d.ts
|
||||
packages/lib/versionInfo.js
|
||||
packages/lib/versionInfo.js.map
|
||||
packages/plugins/ToggleSideBars/api/index.d.ts
|
||||
packages/plugins/ToggleSideBars/api/index.js
|
||||
packages/plugins/ToggleSideBars/api/index.js.map
|
||||
packages/plugins/ToggleSideBars/api/types.d.ts
|
||||
packages/plugins/ToggleSideBars/api/types.js
|
||||
packages/plugins/ToggleSideBars/api/types.js.map
|
||||
packages/plugins/ToggleSideBars/src/index.d.ts
|
||||
packages/plugins/ToggleSideBars/src/index.js
|
||||
packages/plugins/ToggleSideBars/src/index.js.map
|
||||
packages/renderer/HtmlToHtml.d.ts
|
||||
packages/renderer/HtmlToHtml.js
|
||||
packages/renderer/HtmlToHtml.js.map
|
||||
@ -1635,6 +1644,9 @@ packages/server/src/utils/urlUtils.js.map
|
||||
packages/server/src/utils/uuidgen.d.ts
|
||||
packages/server/src/utils/uuidgen.js
|
||||
packages/server/src/utils/uuidgen.js.map
|
||||
packages/tools/build-plugin-repository.d.ts
|
||||
packages/tools/build-plugin-repository.js
|
||||
packages/tools/build-plugin-repository.js.map
|
||||
packages/tools/release-server.d.ts
|
||||
packages/tools/release-server.js
|
||||
packages/tools/release-server.js.map
|
||||
|
@ -1,38 +0,0 @@
|
||||
'use strict';
|
||||
const __awaiter = (this && this.__awaiter) || function(thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function(resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function(resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator['throw'](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
// import * as fs from 'fs-extra';
|
||||
const { execCommand } = require('./tool-utils.js');
|
||||
function pluginInfoFromSearchResults(results) {
|
||||
const output = [];
|
||||
for (const r of results) {
|
||||
if (r.name.indexOf('joplin-plugin') !== 0) { continue; }
|
||||
if (!r.keywords || !r.keywords.includes('joplin-plugin')) { continue; }
|
||||
output.push({
|
||||
name: r.name,
|
||||
version: r.version,
|
||||
date: new Date(r.date),
|
||||
});
|
||||
}
|
||||
return output;
|
||||
}
|
||||
function main() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const searchResults = (yield execCommand('npm search joplin-plugin --searchlimit 1000 --json')).trim();
|
||||
const npmPlugins = pluginInfoFromSearchResults(JSON.parse(searchResults));
|
||||
console.info(npmPlugins);
|
||||
});
|
||||
}
|
||||
main().catch((error) => {
|
||||
console.error('Fatal error');
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
// # sourceMappingURL=build-plugin-repository.js.map
|
113
packages/tools/build-plugin-repository.ts
Normal file
113
packages/tools/build-plugin-repository.ts
Normal file
@ -0,0 +1,113 @@
|
||||
import * as fs from 'fs-extra';
|
||||
import * as path from 'path';
|
||||
import * as process from 'process';
|
||||
const { execCommand, execCommandVerbose, rootDir, resolveRelativePathWithinDir } = require('./tool-utils.js');
|
||||
|
||||
interface NpmPackage {
|
||||
name: string;
|
||||
version: string;
|
||||
date: Date;
|
||||
}
|
||||
|
||||
function pluginInfoFromSearchResults(results: any[]): NpmPackage[] {
|
||||
const output: NpmPackage[] = [];
|
||||
|
||||
for (const r of results) {
|
||||
if (r.name.indexOf('joplin-plugin') !== 0) continue;
|
||||
if (!r.keywords || !r.keywords.includes('joplin-plugin')) continue;
|
||||
|
||||
output.push({
|
||||
name: r.name,
|
||||
version: r.version,
|
||||
date: new Date(r.date),
|
||||
});
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
async function checkPluginRepository(dirPath: string) {
|
||||
if (!(await fs.pathExists(dirPath))) throw new Error(`No plugin repository at: ${dirPath}`);
|
||||
if (!(await fs.pathExists(`${dirPath}/.git`))) throw new Error(`Directory is not a Git repository: ${dirPath}`);
|
||||
}
|
||||
|
||||
async function readManifest(manifestPath: string) {
|
||||
const content = await fs.readFile(manifestPath, 'utf8');
|
||||
return JSON.parse(content);
|
||||
}
|
||||
|
||||
function shortPackageName(packageName: string): string {
|
||||
return packageName.substr('joplin-plugin-'.length);
|
||||
}
|
||||
|
||||
async function extractPluginFilesFromPackage(workDir: string, packageName: string, destDir: string): Promise<any> {
|
||||
const previousDir = process.cwd();
|
||||
process.chdir(workDir);
|
||||
|
||||
await execCommandVerbose('npm', ['install', packageName, '--save', '--ignore-scripts']);
|
||||
|
||||
const pluginDir = resolveRelativePathWithinDir(workDir, 'node_modules', packageName, 'publish');
|
||||
|
||||
const files = await fs.readdir(pluginDir);
|
||||
const manifestFilePath = path.resolve(pluginDir, files.find(f => path.extname(f) === '.json'));
|
||||
const pluginFilePath = path.resolve(pluginDir, files.find(f => path.extname(f) === '.jpl'));
|
||||
|
||||
if (!(await fs.pathExists(manifestFilePath))) throw new Error(`Could not find manifest file at ${manifestFilePath}`);
|
||||
if (!(await fs.pathExists(pluginFilePath))) throw new Error(`Could not find plugin file at ${pluginFilePath}`);
|
||||
|
||||
// At this point we don't validate any of the plugin files as it's partly
|
||||
// done when publishing, and will be done anyway when the app attempts to
|
||||
// load the plugin. We just assume all files are valid here.
|
||||
const manifest = await readManifest(manifestFilePath);
|
||||
|
||||
// We can't use the manifest plugin ID as directory name since, although
|
||||
// it's supposed to be globally unique, there's no guarantee. However the
|
||||
// package name is definitely unique.
|
||||
const pluginDestDir = resolveRelativePathWithinDir(destDir, shortPackageName(packageName));
|
||||
await fs.mkdirp(pluginDestDir);
|
||||
|
||||
await fs.copy(manifestFilePath, path.resolve(pluginDestDir, 'plugin.json'));
|
||||
await fs.copy(pluginFilePath, path.resolve(pluginDestDir, 'plugin.jpl'));
|
||||
|
||||
process.chdir(previousDir);
|
||||
|
||||
return manifest;
|
||||
}
|
||||
|
||||
async function main() {
|
||||
// We assume that the repository is located in a directory next to the main
|
||||
// Joplin monorepo.
|
||||
const repoDir = path.resolve(path.dirname(rootDir), 'joplin-plugins');
|
||||
const tempDir = `${repoDir}/temp`;
|
||||
|
||||
await checkPluginRepository(repoDir);
|
||||
|
||||
await fs.mkdirp(tempDir);
|
||||
|
||||
const searchResults = (await execCommand('npm search joplin-plugin --searchlimit 1000 --json')).trim();
|
||||
const npmPackages = pluginInfoFromSearchResults(JSON.parse(searchResults));
|
||||
|
||||
const packageTempDir = `${tempDir}/packages`;
|
||||
|
||||
await fs.mkdirp(packageTempDir);
|
||||
process.chdir(packageTempDir);
|
||||
await execCommand('npm init --yes --loglevel silent');
|
||||
|
||||
const manifests: any = {};
|
||||
|
||||
for (const npmPackage of npmPackages) {
|
||||
const destDir = `${repoDir}/plugins/`;
|
||||
const manifest = await extractPluginFilesFromPackage(packageTempDir, npmPackage.name, destDir);
|
||||
manifests[shortPackageName(npmPackage.name)] = manifest;
|
||||
}
|
||||
|
||||
await fs.writeFile(path.resolve(repoDir, 'manifests.json'), JSON.stringify(manifests, null, '\t'), 'utf8');
|
||||
|
||||
await fs.remove(tempDir);
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
console.error('Fatal error');
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
@ -40,6 +40,14 @@ function commandToString(commandName, args = []) {
|
||||
return output.join(' ');
|
||||
}
|
||||
|
||||
toolUtils.resolveRelativePathWithinDir = function(baseDir, ...relativePath) {
|
||||
const path = require('path');
|
||||
const resolvedBaseDir = path.resolve(baseDir);
|
||||
const resolvedPath = path.resolve(baseDir, ...relativePath);
|
||||
if (resolvedPath.indexOf(resolvedBaseDir) !== 0) throw new Error(`Resolved path for relative path "${JSON.stringify(relativePath)}" is not within base directory "${baseDir}" (Was resolved to ${resolvedPath})`);
|
||||
return resolvedPath;
|
||||
};
|
||||
|
||||
toolUtils.execCommandVerbose = function(commandName, args = []) {
|
||||
console.info(`> ${commandToString(commandName, args)}`);
|
||||
const promise = execa(commandName, args);
|
||||
|
Loading…
Reference in New Issue
Block a user