You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-06-24 23:26:50 +02:00
Plugins: Updated types
This commit is contained in:
@ -6,8 +6,3 @@
|
|||||||
/dist
|
/dist
|
||||||
tsconfig.json
|
tsconfig.json
|
||||||
webpack.config.js
|
webpack.config.js
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,10 +23,18 @@ export default class JoplinContentScripts {
|
|||||||
* * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script)
|
* * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script)
|
||||||
* * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script)
|
* * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script)
|
||||||
*
|
*
|
||||||
|
* See also the [postMessage demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages)
|
||||||
|
*
|
||||||
* @param type Defines how the script will be used. See the type definition for more information about each supported type.
|
* @param type Defines how the script will be used. See the type definition for more information about each supported type.
|
||||||
* @param id A unique ID for the content script.
|
* @param id A unique ID for the content script.
|
||||||
* @param scriptPath Must be a path relative to the plugin main script. For example, if your file content_script.js is next to your index.ts file, you would set `scriptPath` to `"./content_script.js`.
|
* @param scriptPath Must be a path relative to the plugin main script. For example, if your file content_script.js is next to your index.ts file, you would set `scriptPath` to `"./content_script.js`.
|
||||||
*/
|
*/
|
||||||
register(type: ContentScriptType, id: string, scriptPath: string): Promise<void>;
|
register(type: ContentScriptType, id: string, scriptPath: string): Promise<void>;
|
||||||
onMessage(id: string, callback: any): Promise<void>;
|
/**
|
||||||
|
* Listens to a messages sent from the content script using postMessage().
|
||||||
|
* See {@link ContentScriptType} for more information as well as the
|
||||||
|
* [postMessage
|
||||||
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages)
|
||||||
|
*/
|
||||||
|
onMessage(contentScriptId: string, callback: any): Promise<void>;
|
||||||
}
|
}
|
||||||
|
@ -458,7 +458,7 @@ export enum ContentScriptType {
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* See {@link JoplinContentScript.onMessage} for more details, as well as
|
* See {@link JoplinContentScripts.onMessage} for more details, as well as
|
||||||
* the [postMessage
|
* the [postMessage
|
||||||
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
||||||
*
|
*
|
||||||
@ -557,7 +557,7 @@ export enum ContentScriptType {
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* See {@link JoplinContentScript.onMessage} for more details, as well as
|
* See {@link JoplinContentScripts.onMessage} for more details, as well as
|
||||||
* the [postMessage
|
* the [postMessage
|
||||||
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
||||||
*
|
*
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dist": "webpack",
|
"dist": "webpack --joplin-plugin-config buildMain && webpack --joplin-plugin-config buildExtraScripts && webpack --joplin-plugin-config createArchive",
|
||||||
"prepare": "npm run dist",
|
"prepare": "npm run dist",
|
||||||
"update": "npm install -g generator-joplin && yo joplin --update"
|
"update": "npm install -g generator-joplin && yo joplin --update"
|
||||||
},
|
},
|
||||||
@ -22,6 +22,7 @@
|
|||||||
"typescript": "^3.9.3",
|
"typescript": "^3.9.3",
|
||||||
"webpack": "^4.43.0",
|
"webpack": "^4.43.0",
|
||||||
"webpack-cli": "^3.3.11",
|
"webpack-cli": "^3.3.11",
|
||||||
"chalk": "^4.1.0"
|
"chalk": "^4.1.0",
|
||||||
|
"yargs": "^16.2.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -33,10 +33,6 @@ const manifest = readManifest(manifestPath);
|
|||||||
const pluginArchiveFilePath = path.resolve(publishDir, `${manifest.id}.jpl`);
|
const pluginArchiveFilePath = path.resolve(publishDir, `${manifest.id}.jpl`);
|
||||||
const pluginInfoFilePath = path.resolve(publishDir, `${manifest.id}.json`);
|
const pluginInfoFilePath = path.resolve(publishDir, `${manifest.id}.json`);
|
||||||
|
|
||||||
fs.removeSync(distDir);
|
|
||||||
fs.removeSync(publishDir);
|
|
||||||
fs.mkdirpSync(publishDir);
|
|
||||||
|
|
||||||
function validatePackageJson() {
|
function validatePackageJson() {
|
||||||
const content = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
const content = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
||||||
if (!content.name || content.name.indexOf('joplin-plugin-') !== 0) {
|
if (!content.name || content.name.indexOf('joplin-plugin-') !== 0) {
|
||||||
@ -109,6 +105,7 @@ function createPluginInfo(manifestPath, destPath, jplFilePath) {
|
|||||||
|
|
||||||
function onBuildCompleted() {
|
function onBuildCompleted() {
|
||||||
try {
|
try {
|
||||||
|
fs.removeSync(path.resolve(publishDir, 'index.js'));
|
||||||
createPluginArchive(distDir, pluginArchiveFilePath);
|
createPluginArchive(distDir, pluginArchiveFilePath);
|
||||||
createPluginInfo(manifestPath, pluginInfoFilePath, pluginArchiveFilePath);
|
createPluginInfo(manifestPath, pluginInfoFilePath, pluginArchiveFilePath);
|
||||||
validatePackageJson();
|
validatePackageJson();
|
||||||
@ -174,6 +171,16 @@ const extraScriptConfig = Object.assign({}, baseConfig, {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const createArchiveConfig = {
|
||||||
|
stats: 'errors-only',
|
||||||
|
entry: './dist/index.js',
|
||||||
|
output: {
|
||||||
|
filename: 'index.js',
|
||||||
|
path: publishDir,
|
||||||
|
},
|
||||||
|
plugins: [new WebpackOnBuildPlugin(onBuildCompleted)],
|
||||||
|
};
|
||||||
|
|
||||||
function resolveExtraScriptPath(name) {
|
function resolveExtraScriptPath(name) {
|
||||||
const relativePath = `./src/${name}`;
|
const relativePath = `./src/${name}`;
|
||||||
|
|
||||||
@ -196,8 +203,8 @@ function resolveExtraScriptPath(name) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function addExtraScriptConfigs(baseConfig, userConfig) {
|
function buildExtraScriptConfigs(userConfig) {
|
||||||
if (!userConfig.extraScripts.length) return baseConfig;
|
if (!userConfig.extraScripts.length) return [];
|
||||||
|
|
||||||
const output = [];
|
const output = [];
|
||||||
|
|
||||||
@ -209,22 +216,55 @@ function addExtraScriptConfigs(baseConfig, userConfig) {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
return baseConfig.concat(output);
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addLastConfigStep(config) {
|
function main(processArgv) {
|
||||||
const lastConfig = config[config.length - 1];
|
const yargs = require('yargs/yargs');
|
||||||
if (!lastConfig.plugins) lastConfig.plugins = [];
|
const argv = yargs(processArgv).argv;
|
||||||
lastConfig.plugins.push(new WebpackOnBuildPlugin(onBuildCompleted));
|
|
||||||
config[config.length - 1] = lastConfig;
|
const configName = argv['joplin-plugin-config'];
|
||||||
return config;
|
if (!configName) throw new Error('A config file must be specified via the --joplin-plugin-config flag');
|
||||||
|
|
||||||
|
// Webpack configurations run in parallel, while we need them to run in
|
||||||
|
// sequence, and to do that it seems the only way is to run webpack multiple
|
||||||
|
// times, with different config each time.
|
||||||
|
|
||||||
|
const configs = {
|
||||||
|
// Builds the main src/index.ts and copy the extra content from /src to
|
||||||
|
// /dist including scripts, CSS and any other asset.
|
||||||
|
buildMain: pluginConfig,
|
||||||
|
|
||||||
|
// Builds the extra scripts as defined in plugin.config.json. When doing
|
||||||
|
// so, some JavaScript files that were copied in the previous might be
|
||||||
|
// overwritten here by the compiled version. This is by design. The
|
||||||
|
// result is that JS files that don't need compilation, are simply
|
||||||
|
// copied to /dist, while those that do need it are correctly compiled.
|
||||||
|
buildExtraScripts: buildExtraScriptConfigs(userConfig),
|
||||||
|
|
||||||
|
// Ths config is for creating the .jpl, which is done via the plugin, so
|
||||||
|
// it doesn't actually need an entry and output, however webpack won't
|
||||||
|
// run without this. So we give it an entry that we know is going to
|
||||||
|
// exist and output in the publish dir. Then the plugin will delete this
|
||||||
|
// temporary file before packaging the plugin.
|
||||||
|
createArchive: createArchiveConfig,
|
||||||
|
};
|
||||||
|
|
||||||
|
// If we are running the first config step, we clean up and create the build
|
||||||
|
// directories.
|
||||||
|
if (configName === 'buildMain') {
|
||||||
|
fs.removeSync(distDir);
|
||||||
|
fs.removeSync(publishDir);
|
||||||
|
fs.mkdirpSync(publishDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
return configs[configName];
|
||||||
}
|
}
|
||||||
|
|
||||||
let exportedConfigs = [pluginConfig];
|
let exportedConfigs = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
exportedConfigs = addExtraScriptConfigs(exportedConfigs, userConfig);
|
exportedConfigs = main(process.argv);
|
||||||
exportedConfigs = addLastConfigStep(exportedConfigs);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(chalk.red(error.message));
|
console.error(chalk.red(error.message));
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
dist/
|
dist/
|
||||||
node_modules/
|
node_modules/
|
||||||
publish/
|
publish/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,7 +6,3 @@
|
|||||||
/dist
|
/dist
|
||||||
tsconfig.json
|
tsconfig.json
|
||||||
webpack.config.js
|
webpack.config.js
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,10 +23,18 @@ export default class JoplinContentScripts {
|
|||||||
* * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script)
|
* * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script)
|
||||||
* * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script)
|
* * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script)
|
||||||
*
|
*
|
||||||
|
* See also the [postMessage demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages)
|
||||||
|
*
|
||||||
* @param type Defines how the script will be used. See the type definition for more information about each supported type.
|
* @param type Defines how the script will be used. See the type definition for more information about each supported type.
|
||||||
* @param id A unique ID for the content script.
|
* @param id A unique ID for the content script.
|
||||||
* @param scriptPath Must be a path relative to the plugin main script. For example, if your file content_script.js is next to your index.ts file, you would set `scriptPath` to `"./content_script.js`.
|
* @param scriptPath Must be a path relative to the plugin main script. For example, if your file content_script.js is next to your index.ts file, you would set `scriptPath` to `"./content_script.js`.
|
||||||
*/
|
*/
|
||||||
register(type: ContentScriptType, id: string, scriptPath: string): Promise<void>;
|
register(type: ContentScriptType, id: string, scriptPath: string): Promise<void>;
|
||||||
onMessage(id: string, callback: any): Promise<void>;
|
/**
|
||||||
|
* Listens to a messages sent from the content script using postMessage().
|
||||||
|
* See {@link ContentScriptType} for more information as well as the
|
||||||
|
* [postMessage
|
||||||
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages)
|
||||||
|
*/
|
||||||
|
onMessage(contentScriptId: string, callback: any): Promise<void>;
|
||||||
}
|
}
|
||||||
|
@ -458,7 +458,7 @@ export enum ContentScriptType {
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* See {@link JoplinContentScript.onMessage} for more details, as well as
|
* See {@link JoplinContentScripts.onMessage} for more details, as well as
|
||||||
* the [postMessage
|
* the [postMessage
|
||||||
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
||||||
*
|
*
|
||||||
@ -557,7 +557,7 @@ export enum ContentScriptType {
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* See {@link JoplinContentScript.onMessage} for more details, as well as
|
* See {@link JoplinContentScripts.onMessage} for more details, as well as
|
||||||
* the [postMessage
|
* the [postMessage
|
||||||
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
||||||
*
|
*
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dist": "webpack",
|
"dist": "webpack --joplin-plugin-config buildMain && webpack --joplin-plugin-config buildExtraScripts && webpack --joplin-plugin-config createArchive",
|
||||||
"prepare": "npm run dist",
|
"prepare": "npm run dist",
|
||||||
"update": "npm install -g generator-joplin && yo joplin --update"
|
"update": "npm install -g generator-joplin && yo joplin --update"
|
||||||
},
|
},
|
||||||
@ -22,7 +22,8 @@
|
|||||||
"typescript": "^3.9.3",
|
"typescript": "^3.9.3",
|
||||||
"webpack": "^4.43.0",
|
"webpack": "^4.43.0",
|
||||||
"webpack-cli": "^3.3.11",
|
"webpack-cli": "^3.3.11",
|
||||||
"chalk": "^4.1.0"
|
"chalk": "^4.1.0",
|
||||||
|
"yargs": "^16.2.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"left-pad": "^1.3.0"
|
"left-pad": "^1.3.0"
|
||||||
|
@ -33,10 +33,6 @@ const manifest = readManifest(manifestPath);
|
|||||||
const pluginArchiveFilePath = path.resolve(publishDir, `${manifest.id}.jpl`);
|
const pluginArchiveFilePath = path.resolve(publishDir, `${manifest.id}.jpl`);
|
||||||
const pluginInfoFilePath = path.resolve(publishDir, `${manifest.id}.json`);
|
const pluginInfoFilePath = path.resolve(publishDir, `${manifest.id}.json`);
|
||||||
|
|
||||||
fs.removeSync(distDir);
|
|
||||||
fs.removeSync(publishDir);
|
|
||||||
fs.mkdirpSync(publishDir);
|
|
||||||
|
|
||||||
function validatePackageJson() {
|
function validatePackageJson() {
|
||||||
const content = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
const content = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
||||||
if (!content.name || content.name.indexOf('joplin-plugin-') !== 0) {
|
if (!content.name || content.name.indexOf('joplin-plugin-') !== 0) {
|
||||||
@ -109,6 +105,7 @@ function createPluginInfo(manifestPath, destPath, jplFilePath) {
|
|||||||
|
|
||||||
function onBuildCompleted() {
|
function onBuildCompleted() {
|
||||||
try {
|
try {
|
||||||
|
fs.removeSync(path.resolve(publishDir, 'index.js'));
|
||||||
createPluginArchive(distDir, pluginArchiveFilePath);
|
createPluginArchive(distDir, pluginArchiveFilePath);
|
||||||
createPluginInfo(manifestPath, pluginInfoFilePath, pluginArchiveFilePath);
|
createPluginInfo(manifestPath, pluginInfoFilePath, pluginArchiveFilePath);
|
||||||
validatePackageJson();
|
validatePackageJson();
|
||||||
@ -174,6 +171,16 @@ const extraScriptConfig = Object.assign({}, baseConfig, {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const createArchiveConfig = {
|
||||||
|
stats: 'errors-only',
|
||||||
|
entry: './dist/index.js',
|
||||||
|
output: {
|
||||||
|
filename: 'index.js',
|
||||||
|
path: publishDir,
|
||||||
|
},
|
||||||
|
plugins: [new WebpackOnBuildPlugin(onBuildCompleted)],
|
||||||
|
};
|
||||||
|
|
||||||
function resolveExtraScriptPath(name) {
|
function resolveExtraScriptPath(name) {
|
||||||
const relativePath = `./src/${name}`;
|
const relativePath = `./src/${name}`;
|
||||||
|
|
||||||
@ -196,8 +203,8 @@ function resolveExtraScriptPath(name) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function addExtraScriptConfigs(baseConfig, userConfig) {
|
function buildExtraScriptConfigs(userConfig) {
|
||||||
if (!userConfig.extraScripts.length) return baseConfig;
|
if (!userConfig.extraScripts.length) return [];
|
||||||
|
|
||||||
const output = [];
|
const output = [];
|
||||||
|
|
||||||
@ -209,22 +216,55 @@ function addExtraScriptConfigs(baseConfig, userConfig) {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
return baseConfig.concat(output);
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addLastConfigStep(config) {
|
function main(processArgv) {
|
||||||
const lastConfig = config[config.length - 1];
|
const yargs = require('yargs/yargs');
|
||||||
if (!lastConfig.plugins) lastConfig.plugins = [];
|
const argv = yargs(processArgv).argv;
|
||||||
lastConfig.plugins.push(new WebpackOnBuildPlugin(onBuildCompleted));
|
|
||||||
config[config.length - 1] = lastConfig;
|
const configName = argv['joplin-plugin-config'];
|
||||||
return config;
|
if (!configName) throw new Error('A config file must be specified via the --joplin-plugin-config flag');
|
||||||
|
|
||||||
|
// Webpack configurations run in parallel, while we need them to run in
|
||||||
|
// sequence, and to do that it seems the only way is to run webpack multiple
|
||||||
|
// times, with different config each time.
|
||||||
|
|
||||||
|
const configs = {
|
||||||
|
// Builds the main src/index.ts and copy the extra content from /src to
|
||||||
|
// /dist including scripts, CSS and any other asset.
|
||||||
|
buildMain: pluginConfig,
|
||||||
|
|
||||||
|
// Builds the extra scripts as defined in plugin.config.json. When doing
|
||||||
|
// so, some JavaScript files that were copied in the previous might be
|
||||||
|
// overwritten here by the compiled version. This is by design. The
|
||||||
|
// result is that JS files that don't need compilation, are simply
|
||||||
|
// copied to /dist, while those that do need it are correctly compiled.
|
||||||
|
buildExtraScripts: buildExtraScriptConfigs(userConfig),
|
||||||
|
|
||||||
|
// Ths config is for creating the .jpl, which is done via the plugin, so
|
||||||
|
// it doesn't actually need an entry and output, however webpack won't
|
||||||
|
// run without this. So we give it an entry that we know is going to
|
||||||
|
// exist and output in the publish dir. Then the plugin will delete this
|
||||||
|
// temporary file before packaging the plugin.
|
||||||
|
createArchive: createArchiveConfig,
|
||||||
|
};
|
||||||
|
|
||||||
|
// If we are running the first config step, we clean up and create the build
|
||||||
|
// directories.
|
||||||
|
if (configName === 'buildMain') {
|
||||||
|
fs.removeSync(distDir);
|
||||||
|
fs.removeSync(publishDir);
|
||||||
|
fs.mkdirpSync(publishDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
return configs[configName];
|
||||||
}
|
}
|
||||||
|
|
||||||
let exportedConfigs = [pluginConfig];
|
let exportedConfigs = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
exportedConfigs = addExtraScriptConfigs(exportedConfigs, userConfig);
|
exportedConfigs = main(process.argv);
|
||||||
exportedConfigs = addLastConfigStep(exportedConfigs);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(chalk.red(error.message));
|
console.error(chalk.red(error.message));
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
dist/
|
dist/
|
||||||
node_modules/
|
node_modules/
|
||||||
publish/
|
publish/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,7 +6,3 @@
|
|||||||
/dist
|
/dist
|
||||||
tsconfig.json
|
tsconfig.json
|
||||||
webpack.config.js
|
webpack.config.js
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,10 +23,18 @@ export default class JoplinContentScripts {
|
|||||||
* * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script)
|
* * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script)
|
||||||
* * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script)
|
* * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script)
|
||||||
*
|
*
|
||||||
|
* See also the [postMessage demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages)
|
||||||
|
*
|
||||||
* @param type Defines how the script will be used. See the type definition for more information about each supported type.
|
* @param type Defines how the script will be used. See the type definition for more information about each supported type.
|
||||||
* @param id A unique ID for the content script.
|
* @param id A unique ID for the content script.
|
||||||
* @param scriptPath Must be a path relative to the plugin main script. For example, if your file content_script.js is next to your index.ts file, you would set `scriptPath` to `"./content_script.js`.
|
* @param scriptPath Must be a path relative to the plugin main script. For example, if your file content_script.js is next to your index.ts file, you would set `scriptPath` to `"./content_script.js`.
|
||||||
*/
|
*/
|
||||||
register(type: ContentScriptType, id: string, scriptPath: string): Promise<void>;
|
register(type: ContentScriptType, id: string, scriptPath: string): Promise<void>;
|
||||||
onMessage(id: string, callback: any): Promise<void>;
|
/**
|
||||||
|
* Listens to a messages sent from the content script using postMessage().
|
||||||
|
* See {@link ContentScriptType} for more information as well as the
|
||||||
|
* [postMessage
|
||||||
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages)
|
||||||
|
*/
|
||||||
|
onMessage(contentScriptId: string, callback: any): Promise<void>;
|
||||||
}
|
}
|
||||||
|
@ -458,7 +458,7 @@ export enum ContentScriptType {
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* See {@link JoplinContentScript.onMessage} for more details, as well as
|
* See {@link JoplinContentScripts.onMessage} for more details, as well as
|
||||||
* the [postMessage
|
* the [postMessage
|
||||||
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
||||||
*
|
*
|
||||||
@ -557,7 +557,7 @@ export enum ContentScriptType {
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* See {@link JoplinContentScript.onMessage} for more details, as well as
|
* See {@link JoplinContentScripts.onMessage} for more details, as well as
|
||||||
* the [postMessage
|
* the [postMessage
|
||||||
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
||||||
*
|
*
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dist": "webpack",
|
"dist": "webpack --joplin-plugin-config buildMain && webpack --joplin-plugin-config buildExtraScripts && webpack --joplin-plugin-config createArchive",
|
||||||
"prepare": "npm run dist",
|
"prepare": "npm run dist",
|
||||||
"update": "npm install -g generator-joplin && yo joplin --update"
|
"update": "npm install -g generator-joplin && yo joplin --update"
|
||||||
},
|
},
|
||||||
@ -22,6 +22,7 @@
|
|||||||
"typescript": "^3.9.3",
|
"typescript": "^3.9.3",
|
||||||
"webpack": "^4.43.0",
|
"webpack": "^4.43.0",
|
||||||
"webpack-cli": "^3.3.11",
|
"webpack-cli": "^3.3.11",
|
||||||
"chalk": "^4.1.0"
|
"chalk": "^4.1.0",
|
||||||
|
"yargs": "^16.2.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -33,10 +33,6 @@ const manifest = readManifest(manifestPath);
|
|||||||
const pluginArchiveFilePath = path.resolve(publishDir, `${manifest.id}.jpl`);
|
const pluginArchiveFilePath = path.resolve(publishDir, `${manifest.id}.jpl`);
|
||||||
const pluginInfoFilePath = path.resolve(publishDir, `${manifest.id}.json`);
|
const pluginInfoFilePath = path.resolve(publishDir, `${manifest.id}.json`);
|
||||||
|
|
||||||
fs.removeSync(distDir);
|
|
||||||
fs.removeSync(publishDir);
|
|
||||||
fs.mkdirpSync(publishDir);
|
|
||||||
|
|
||||||
function validatePackageJson() {
|
function validatePackageJson() {
|
||||||
const content = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
const content = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
||||||
if (!content.name || content.name.indexOf('joplin-plugin-') !== 0) {
|
if (!content.name || content.name.indexOf('joplin-plugin-') !== 0) {
|
||||||
@ -109,6 +105,7 @@ function createPluginInfo(manifestPath, destPath, jplFilePath) {
|
|||||||
|
|
||||||
function onBuildCompleted() {
|
function onBuildCompleted() {
|
||||||
try {
|
try {
|
||||||
|
fs.removeSync(path.resolve(publishDir, 'index.js'));
|
||||||
createPluginArchive(distDir, pluginArchiveFilePath);
|
createPluginArchive(distDir, pluginArchiveFilePath);
|
||||||
createPluginInfo(manifestPath, pluginInfoFilePath, pluginArchiveFilePath);
|
createPluginInfo(manifestPath, pluginInfoFilePath, pluginArchiveFilePath);
|
||||||
validatePackageJson();
|
validatePackageJson();
|
||||||
@ -174,6 +171,16 @@ const extraScriptConfig = Object.assign({}, baseConfig, {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const createArchiveConfig = {
|
||||||
|
stats: 'errors-only',
|
||||||
|
entry: './dist/index.js',
|
||||||
|
output: {
|
||||||
|
filename: 'index.js',
|
||||||
|
path: publishDir,
|
||||||
|
},
|
||||||
|
plugins: [new WebpackOnBuildPlugin(onBuildCompleted)],
|
||||||
|
};
|
||||||
|
|
||||||
function resolveExtraScriptPath(name) {
|
function resolveExtraScriptPath(name) {
|
||||||
const relativePath = `./src/${name}`;
|
const relativePath = `./src/${name}`;
|
||||||
|
|
||||||
@ -196,8 +203,8 @@ function resolveExtraScriptPath(name) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function addExtraScriptConfigs(baseConfig, userConfig) {
|
function buildExtraScriptConfigs(userConfig) {
|
||||||
if (!userConfig.extraScripts.length) return baseConfig;
|
if (!userConfig.extraScripts.length) return [];
|
||||||
|
|
||||||
const output = [];
|
const output = [];
|
||||||
|
|
||||||
@ -209,22 +216,55 @@ function addExtraScriptConfigs(baseConfig, userConfig) {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
return baseConfig.concat(output);
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addLastConfigStep(config) {
|
function main(processArgv) {
|
||||||
const lastConfig = config[config.length - 1];
|
const yargs = require('yargs/yargs');
|
||||||
if (!lastConfig.plugins) lastConfig.plugins = [];
|
const argv = yargs(processArgv).argv;
|
||||||
lastConfig.plugins.push(new WebpackOnBuildPlugin(onBuildCompleted));
|
|
||||||
config[config.length - 1] = lastConfig;
|
const configName = argv['joplin-plugin-config'];
|
||||||
return config;
|
if (!configName) throw new Error('A config file must be specified via the --joplin-plugin-config flag');
|
||||||
|
|
||||||
|
// Webpack configurations run in parallel, while we need them to run in
|
||||||
|
// sequence, and to do that it seems the only way is to run webpack multiple
|
||||||
|
// times, with different config each time.
|
||||||
|
|
||||||
|
const configs = {
|
||||||
|
// Builds the main src/index.ts and copy the extra content from /src to
|
||||||
|
// /dist including scripts, CSS and any other asset.
|
||||||
|
buildMain: pluginConfig,
|
||||||
|
|
||||||
|
// Builds the extra scripts as defined in plugin.config.json. When doing
|
||||||
|
// so, some JavaScript files that were copied in the previous might be
|
||||||
|
// overwritten here by the compiled version. This is by design. The
|
||||||
|
// result is that JS files that don't need compilation, are simply
|
||||||
|
// copied to /dist, while those that do need it are correctly compiled.
|
||||||
|
buildExtraScripts: buildExtraScriptConfigs(userConfig),
|
||||||
|
|
||||||
|
// Ths config is for creating the .jpl, which is done via the plugin, so
|
||||||
|
// it doesn't actually need an entry and output, however webpack won't
|
||||||
|
// run without this. So we give it an entry that we know is going to
|
||||||
|
// exist and output in the publish dir. Then the plugin will delete this
|
||||||
|
// temporary file before packaging the plugin.
|
||||||
|
createArchive: createArchiveConfig,
|
||||||
|
};
|
||||||
|
|
||||||
|
// If we are running the first config step, we clean up and create the build
|
||||||
|
// directories.
|
||||||
|
if (configName === 'buildMain') {
|
||||||
|
fs.removeSync(distDir);
|
||||||
|
fs.removeSync(publishDir);
|
||||||
|
fs.mkdirpSync(publishDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
return configs[configName];
|
||||||
}
|
}
|
||||||
|
|
||||||
let exportedConfigs = [pluginConfig];
|
let exportedConfigs = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
exportedConfigs = addExtraScriptConfigs(exportedConfigs, userConfig);
|
exportedConfigs = main(process.argv);
|
||||||
exportedConfigs = addLastConfigStep(exportedConfigs);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(chalk.red(error.message));
|
console.error(chalk.red(error.message));
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
dist/
|
dist/
|
||||||
node_modules/
|
node_modules/
|
||||||
publish/
|
publish/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,7 +6,3 @@
|
|||||||
/dist
|
/dist
|
||||||
tsconfig.json
|
tsconfig.json
|
||||||
webpack.config.js
|
webpack.config.js
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,10 +23,18 @@ export default class JoplinContentScripts {
|
|||||||
* * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script)
|
* * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script)
|
||||||
* * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script)
|
* * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script)
|
||||||
*
|
*
|
||||||
|
* See also the [postMessage demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages)
|
||||||
|
*
|
||||||
* @param type Defines how the script will be used. See the type definition for more information about each supported type.
|
* @param type Defines how the script will be used. See the type definition for more information about each supported type.
|
||||||
* @param id A unique ID for the content script.
|
* @param id A unique ID for the content script.
|
||||||
* @param scriptPath Must be a path relative to the plugin main script. For example, if your file content_script.js is next to your index.ts file, you would set `scriptPath` to `"./content_script.js`.
|
* @param scriptPath Must be a path relative to the plugin main script. For example, if your file content_script.js is next to your index.ts file, you would set `scriptPath` to `"./content_script.js`.
|
||||||
*/
|
*/
|
||||||
register(type: ContentScriptType, id: string, scriptPath: string): Promise<void>;
|
register(type: ContentScriptType, id: string, scriptPath: string): Promise<void>;
|
||||||
onMessage(id: string, callback: any): Promise<void>;
|
/**
|
||||||
|
* Listens to a messages sent from the content script using postMessage().
|
||||||
|
* See {@link ContentScriptType} for more information as well as the
|
||||||
|
* [postMessage
|
||||||
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages)
|
||||||
|
*/
|
||||||
|
onMessage(contentScriptId: string, callback: any): Promise<void>;
|
||||||
}
|
}
|
||||||
|
@ -458,7 +458,7 @@ export enum ContentScriptType {
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* See {@link JoplinContentScript.onMessage} for more details, as well as
|
* See {@link JoplinContentScripts.onMessage} for more details, as well as
|
||||||
* the [postMessage
|
* the [postMessage
|
||||||
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
||||||
*
|
*
|
||||||
@ -557,7 +557,7 @@ export enum ContentScriptType {
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* See {@link JoplinContentScript.onMessage} for more details, as well as
|
* See {@link JoplinContentScripts.onMessage} for more details, as well as
|
||||||
* the [postMessage
|
* the [postMessage
|
||||||
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
||||||
*
|
*
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dist": "webpack",
|
"dist": "webpack --joplin-plugin-config buildMain && webpack --joplin-plugin-config buildExtraScripts && webpack --joplin-plugin-config createArchive",
|
||||||
"prepare": "npm run dist",
|
"prepare": "npm run dist",
|
||||||
"update": "npm install -g generator-joplin && yo joplin --update"
|
"update": "npm install -g generator-joplin && yo joplin --update"
|
||||||
},
|
},
|
||||||
@ -22,6 +22,7 @@
|
|||||||
"typescript": "^3.9.3",
|
"typescript": "^3.9.3",
|
||||||
"webpack": "^4.43.0",
|
"webpack": "^4.43.0",
|
||||||
"webpack-cli": "^3.3.11",
|
"webpack-cli": "^3.3.11",
|
||||||
"chalk": "^4.1.0"
|
"chalk": "^4.1.0",
|
||||||
|
"yargs": "^16.2.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -33,10 +33,6 @@ const manifest = readManifest(manifestPath);
|
|||||||
const pluginArchiveFilePath = path.resolve(publishDir, `${manifest.id}.jpl`);
|
const pluginArchiveFilePath = path.resolve(publishDir, `${manifest.id}.jpl`);
|
||||||
const pluginInfoFilePath = path.resolve(publishDir, `${manifest.id}.json`);
|
const pluginInfoFilePath = path.resolve(publishDir, `${manifest.id}.json`);
|
||||||
|
|
||||||
fs.removeSync(distDir);
|
|
||||||
fs.removeSync(publishDir);
|
|
||||||
fs.mkdirpSync(publishDir);
|
|
||||||
|
|
||||||
function validatePackageJson() {
|
function validatePackageJson() {
|
||||||
const content = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
const content = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
||||||
if (!content.name || content.name.indexOf('joplin-plugin-') !== 0) {
|
if (!content.name || content.name.indexOf('joplin-plugin-') !== 0) {
|
||||||
@ -109,6 +105,7 @@ function createPluginInfo(manifestPath, destPath, jplFilePath) {
|
|||||||
|
|
||||||
function onBuildCompleted() {
|
function onBuildCompleted() {
|
||||||
try {
|
try {
|
||||||
|
fs.removeSync(path.resolve(publishDir, 'index.js'));
|
||||||
createPluginArchive(distDir, pluginArchiveFilePath);
|
createPluginArchive(distDir, pluginArchiveFilePath);
|
||||||
createPluginInfo(manifestPath, pluginInfoFilePath, pluginArchiveFilePath);
|
createPluginInfo(manifestPath, pluginInfoFilePath, pluginArchiveFilePath);
|
||||||
validatePackageJson();
|
validatePackageJson();
|
||||||
@ -174,6 +171,16 @@ const extraScriptConfig = Object.assign({}, baseConfig, {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const createArchiveConfig = {
|
||||||
|
stats: 'errors-only',
|
||||||
|
entry: './dist/index.js',
|
||||||
|
output: {
|
||||||
|
filename: 'index.js',
|
||||||
|
path: publishDir,
|
||||||
|
},
|
||||||
|
plugins: [new WebpackOnBuildPlugin(onBuildCompleted)],
|
||||||
|
};
|
||||||
|
|
||||||
function resolveExtraScriptPath(name) {
|
function resolveExtraScriptPath(name) {
|
||||||
const relativePath = `./src/${name}`;
|
const relativePath = `./src/${name}`;
|
||||||
|
|
||||||
@ -196,8 +203,8 @@ function resolveExtraScriptPath(name) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function addExtraScriptConfigs(baseConfig, userConfig) {
|
function buildExtraScriptConfigs(userConfig) {
|
||||||
if (!userConfig.extraScripts.length) return baseConfig;
|
if (!userConfig.extraScripts.length) return [];
|
||||||
|
|
||||||
const output = [];
|
const output = [];
|
||||||
|
|
||||||
@ -209,22 +216,55 @@ function addExtraScriptConfigs(baseConfig, userConfig) {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
return baseConfig.concat(output);
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addLastConfigStep(config) {
|
function main(processArgv) {
|
||||||
const lastConfig = config[config.length - 1];
|
const yargs = require('yargs/yargs');
|
||||||
if (!lastConfig.plugins) lastConfig.plugins = [];
|
const argv = yargs(processArgv).argv;
|
||||||
lastConfig.plugins.push(new WebpackOnBuildPlugin(onBuildCompleted));
|
|
||||||
config[config.length - 1] = lastConfig;
|
const configName = argv['joplin-plugin-config'];
|
||||||
return config;
|
if (!configName) throw new Error('A config file must be specified via the --joplin-plugin-config flag');
|
||||||
|
|
||||||
|
// Webpack configurations run in parallel, while we need them to run in
|
||||||
|
// sequence, and to do that it seems the only way is to run webpack multiple
|
||||||
|
// times, with different config each time.
|
||||||
|
|
||||||
|
const configs = {
|
||||||
|
// Builds the main src/index.ts and copy the extra content from /src to
|
||||||
|
// /dist including scripts, CSS and any other asset.
|
||||||
|
buildMain: pluginConfig,
|
||||||
|
|
||||||
|
// Builds the extra scripts as defined in plugin.config.json. When doing
|
||||||
|
// so, some JavaScript files that were copied in the previous might be
|
||||||
|
// overwritten here by the compiled version. This is by design. The
|
||||||
|
// result is that JS files that don't need compilation, are simply
|
||||||
|
// copied to /dist, while those that do need it are correctly compiled.
|
||||||
|
buildExtraScripts: buildExtraScriptConfigs(userConfig),
|
||||||
|
|
||||||
|
// Ths config is for creating the .jpl, which is done via the plugin, so
|
||||||
|
// it doesn't actually need an entry and output, however webpack won't
|
||||||
|
// run without this. So we give it an entry that we know is going to
|
||||||
|
// exist and output in the publish dir. Then the plugin will delete this
|
||||||
|
// temporary file before packaging the plugin.
|
||||||
|
createArchive: createArchiveConfig,
|
||||||
|
};
|
||||||
|
|
||||||
|
// If we are running the first config step, we clean up and create the build
|
||||||
|
// directories.
|
||||||
|
if (configName === 'buildMain') {
|
||||||
|
fs.removeSync(distDir);
|
||||||
|
fs.removeSync(publishDir);
|
||||||
|
fs.mkdirpSync(publishDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
return configs[configName];
|
||||||
}
|
}
|
||||||
|
|
||||||
let exportedConfigs = [pluginConfig];
|
let exportedConfigs = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
exportedConfigs = addExtraScriptConfigs(exportedConfigs, userConfig);
|
exportedConfigs = main(process.argv);
|
||||||
exportedConfigs = addLastConfigStep(exportedConfigs);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(chalk.red(error.message));
|
console.error(chalk.red(error.message));
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
dist/
|
dist/
|
||||||
node_modules/
|
node_modules/
|
||||||
publish/
|
publish/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,7 +6,3 @@
|
|||||||
/dist
|
/dist
|
||||||
tsconfig.json
|
tsconfig.json
|
||||||
webpack.config.js
|
webpack.config.js
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,10 +23,18 @@ export default class JoplinContentScripts {
|
|||||||
* * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script)
|
* * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script)
|
||||||
* * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script)
|
* * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script)
|
||||||
*
|
*
|
||||||
|
* See also the [postMessage demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages)
|
||||||
|
*
|
||||||
* @param type Defines how the script will be used. See the type definition for more information about each supported type.
|
* @param type Defines how the script will be used. See the type definition for more information about each supported type.
|
||||||
* @param id A unique ID for the content script.
|
* @param id A unique ID for the content script.
|
||||||
* @param scriptPath Must be a path relative to the plugin main script. For example, if your file content_script.js is next to your index.ts file, you would set `scriptPath` to `"./content_script.js`.
|
* @param scriptPath Must be a path relative to the plugin main script. For example, if your file content_script.js is next to your index.ts file, you would set `scriptPath` to `"./content_script.js`.
|
||||||
*/
|
*/
|
||||||
register(type: ContentScriptType, id: string, scriptPath: string): Promise<void>;
|
register(type: ContentScriptType, id: string, scriptPath: string): Promise<void>;
|
||||||
onMessage(id: string, callback: any): Promise<void>;
|
/**
|
||||||
|
* Listens to a messages sent from the content script using postMessage().
|
||||||
|
* See {@link ContentScriptType} for more information as well as the
|
||||||
|
* [postMessage
|
||||||
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages)
|
||||||
|
*/
|
||||||
|
onMessage(contentScriptId: string, callback: any): Promise<void>;
|
||||||
}
|
}
|
||||||
|
@ -458,7 +458,7 @@ export enum ContentScriptType {
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* See {@link JoplinContentScript.onMessage} for more details, as well as
|
* See {@link JoplinContentScripts.onMessage} for more details, as well as
|
||||||
* the [postMessage
|
* the [postMessage
|
||||||
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
||||||
*
|
*
|
||||||
@ -557,7 +557,7 @@ export enum ContentScriptType {
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* See {@link JoplinContentScript.onMessage} for more details, as well as
|
* See {@link JoplinContentScripts.onMessage} for more details, as well as
|
||||||
* the [postMessage
|
* the [postMessage
|
||||||
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
||||||
*
|
*
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dist": "webpack",
|
"dist": "webpack --joplin-plugin-config buildMain && webpack --joplin-plugin-config buildExtraScripts && webpack --joplin-plugin-config createArchive",
|
||||||
"prepare": "npm run dist",
|
"prepare": "npm run dist",
|
||||||
"update": "npm install -g generator-joplin && yo joplin --update"
|
"update": "npm install -g generator-joplin && yo joplin --update"
|
||||||
},
|
},
|
||||||
@ -22,6 +22,7 @@
|
|||||||
"typescript": "^3.9.3",
|
"typescript": "^3.9.3",
|
||||||
"webpack": "^4.43.0",
|
"webpack": "^4.43.0",
|
||||||
"webpack-cli": "^3.3.11",
|
"webpack-cli": "^3.3.11",
|
||||||
"chalk": "^4.1.0"
|
"chalk": "^4.1.0",
|
||||||
|
"yargs": "^16.2.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -33,10 +33,6 @@ const manifest = readManifest(manifestPath);
|
|||||||
const pluginArchiveFilePath = path.resolve(publishDir, `${manifest.id}.jpl`);
|
const pluginArchiveFilePath = path.resolve(publishDir, `${manifest.id}.jpl`);
|
||||||
const pluginInfoFilePath = path.resolve(publishDir, `${manifest.id}.json`);
|
const pluginInfoFilePath = path.resolve(publishDir, `${manifest.id}.json`);
|
||||||
|
|
||||||
fs.removeSync(distDir);
|
|
||||||
fs.removeSync(publishDir);
|
|
||||||
fs.mkdirpSync(publishDir);
|
|
||||||
|
|
||||||
function validatePackageJson() {
|
function validatePackageJson() {
|
||||||
const content = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
const content = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
||||||
if (!content.name || content.name.indexOf('joplin-plugin-') !== 0) {
|
if (!content.name || content.name.indexOf('joplin-plugin-') !== 0) {
|
||||||
@ -109,6 +105,7 @@ function createPluginInfo(manifestPath, destPath, jplFilePath) {
|
|||||||
|
|
||||||
function onBuildCompleted() {
|
function onBuildCompleted() {
|
||||||
try {
|
try {
|
||||||
|
fs.removeSync(path.resolve(publishDir, 'index.js'));
|
||||||
createPluginArchive(distDir, pluginArchiveFilePath);
|
createPluginArchive(distDir, pluginArchiveFilePath);
|
||||||
createPluginInfo(manifestPath, pluginInfoFilePath, pluginArchiveFilePath);
|
createPluginInfo(manifestPath, pluginInfoFilePath, pluginArchiveFilePath);
|
||||||
validatePackageJson();
|
validatePackageJson();
|
||||||
@ -174,6 +171,16 @@ const extraScriptConfig = Object.assign({}, baseConfig, {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const createArchiveConfig = {
|
||||||
|
stats: 'errors-only',
|
||||||
|
entry: './dist/index.js',
|
||||||
|
output: {
|
||||||
|
filename: 'index.js',
|
||||||
|
path: publishDir,
|
||||||
|
},
|
||||||
|
plugins: [new WebpackOnBuildPlugin(onBuildCompleted)],
|
||||||
|
};
|
||||||
|
|
||||||
function resolveExtraScriptPath(name) {
|
function resolveExtraScriptPath(name) {
|
||||||
const relativePath = `./src/${name}`;
|
const relativePath = `./src/${name}`;
|
||||||
|
|
||||||
@ -196,8 +203,8 @@ function resolveExtraScriptPath(name) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function addExtraScriptConfigs(baseConfig, userConfig) {
|
function buildExtraScriptConfigs(userConfig) {
|
||||||
if (!userConfig.extraScripts.length) return baseConfig;
|
if (!userConfig.extraScripts.length) return [];
|
||||||
|
|
||||||
const output = [];
|
const output = [];
|
||||||
|
|
||||||
@ -209,22 +216,55 @@ function addExtraScriptConfigs(baseConfig, userConfig) {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
return baseConfig.concat(output);
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addLastConfigStep(config) {
|
function main(processArgv) {
|
||||||
const lastConfig = config[config.length - 1];
|
const yargs = require('yargs/yargs');
|
||||||
if (!lastConfig.plugins) lastConfig.plugins = [];
|
const argv = yargs(processArgv).argv;
|
||||||
lastConfig.plugins.push(new WebpackOnBuildPlugin(onBuildCompleted));
|
|
||||||
config[config.length - 1] = lastConfig;
|
const configName = argv['joplin-plugin-config'];
|
||||||
return config;
|
if (!configName) throw new Error('A config file must be specified via the --joplin-plugin-config flag');
|
||||||
|
|
||||||
|
// Webpack configurations run in parallel, while we need them to run in
|
||||||
|
// sequence, and to do that it seems the only way is to run webpack multiple
|
||||||
|
// times, with different config each time.
|
||||||
|
|
||||||
|
const configs = {
|
||||||
|
// Builds the main src/index.ts and copy the extra content from /src to
|
||||||
|
// /dist including scripts, CSS and any other asset.
|
||||||
|
buildMain: pluginConfig,
|
||||||
|
|
||||||
|
// Builds the extra scripts as defined in plugin.config.json. When doing
|
||||||
|
// so, some JavaScript files that were copied in the previous might be
|
||||||
|
// overwritten here by the compiled version. This is by design. The
|
||||||
|
// result is that JS files that don't need compilation, are simply
|
||||||
|
// copied to /dist, while those that do need it are correctly compiled.
|
||||||
|
buildExtraScripts: buildExtraScriptConfigs(userConfig),
|
||||||
|
|
||||||
|
// Ths config is for creating the .jpl, which is done via the plugin, so
|
||||||
|
// it doesn't actually need an entry and output, however webpack won't
|
||||||
|
// run without this. So we give it an entry that we know is going to
|
||||||
|
// exist and output in the publish dir. Then the plugin will delete this
|
||||||
|
// temporary file before packaging the plugin.
|
||||||
|
createArchive: createArchiveConfig,
|
||||||
|
};
|
||||||
|
|
||||||
|
// If we are running the first config step, we clean up and create the build
|
||||||
|
// directories.
|
||||||
|
if (configName === 'buildMain') {
|
||||||
|
fs.removeSync(distDir);
|
||||||
|
fs.removeSync(publishDir);
|
||||||
|
fs.mkdirpSync(publishDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
return configs[configName];
|
||||||
}
|
}
|
||||||
|
|
||||||
let exportedConfigs = [pluginConfig];
|
let exportedConfigs = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
exportedConfigs = addExtraScriptConfigs(exportedConfigs, userConfig);
|
exportedConfigs = main(process.argv);
|
||||||
exportedConfigs = addLastConfigStep(exportedConfigs);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(chalk.red(error.message));
|
console.error(chalk.red(error.message));
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
dist/
|
dist/
|
||||||
node_modules/
|
node_modules/
|
||||||
publish/
|
publish/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,7 +6,3 @@
|
|||||||
/dist
|
/dist
|
||||||
tsconfig.json
|
tsconfig.json
|
||||||
webpack.config.js
|
webpack.config.js
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,10 +23,18 @@ export default class JoplinContentScripts {
|
|||||||
* * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script)
|
* * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script)
|
||||||
* * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script)
|
* * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script)
|
||||||
*
|
*
|
||||||
|
* See also the [postMessage demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages)
|
||||||
|
*
|
||||||
* @param type Defines how the script will be used. See the type definition for more information about each supported type.
|
* @param type Defines how the script will be used. See the type definition for more information about each supported type.
|
||||||
* @param id A unique ID for the content script.
|
* @param id A unique ID for the content script.
|
||||||
* @param scriptPath Must be a path relative to the plugin main script. For example, if your file content_script.js is next to your index.ts file, you would set `scriptPath` to `"./content_script.js`.
|
* @param scriptPath Must be a path relative to the plugin main script. For example, if your file content_script.js is next to your index.ts file, you would set `scriptPath` to `"./content_script.js`.
|
||||||
*/
|
*/
|
||||||
register(type: ContentScriptType, id: string, scriptPath: string): Promise<void>;
|
register(type: ContentScriptType, id: string, scriptPath: string): Promise<void>;
|
||||||
onMessage(id: string, callback: any): Promise<void>;
|
/**
|
||||||
|
* Listens to a messages sent from the content script using postMessage().
|
||||||
|
* See {@link ContentScriptType} for more information as well as the
|
||||||
|
* [postMessage
|
||||||
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages)
|
||||||
|
*/
|
||||||
|
onMessage(contentScriptId: string, callback: any): Promise<void>;
|
||||||
}
|
}
|
||||||
|
@ -458,7 +458,7 @@ export enum ContentScriptType {
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* See {@link JoplinContentScript.onMessage} for more details, as well as
|
* See {@link JoplinContentScripts.onMessage} for more details, as well as
|
||||||
* the [postMessage
|
* the [postMessage
|
||||||
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
||||||
*
|
*
|
||||||
@ -557,7 +557,7 @@ export enum ContentScriptType {
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* See {@link JoplinContentScript.onMessage} for more details, as well as
|
* See {@link JoplinContentScripts.onMessage} for more details, as well as
|
||||||
* the [postMessage
|
* the [postMessage
|
||||||
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
||||||
*
|
*
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dist": "webpack",
|
"dist": "webpack --joplin-plugin-config buildMain && webpack --joplin-plugin-config buildExtraScripts && webpack --joplin-plugin-config createArchive",
|
||||||
"prepare": "npm run dist",
|
"prepare": "npm run dist",
|
||||||
"update": "npm install -g generator-joplin && yo joplin --update"
|
"update": "npm install -g generator-joplin && yo joplin --update"
|
||||||
},
|
},
|
||||||
@ -22,6 +22,7 @@
|
|||||||
"typescript": "^3.9.3",
|
"typescript": "^3.9.3",
|
||||||
"webpack": "^4.43.0",
|
"webpack": "^4.43.0",
|
||||||
"webpack-cli": "^3.3.11",
|
"webpack-cli": "^3.3.11",
|
||||||
"chalk": "^4.1.0"
|
"chalk": "^4.1.0",
|
||||||
|
"yargs": "^16.2.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -33,10 +33,6 @@ const manifest = readManifest(manifestPath);
|
|||||||
const pluginArchiveFilePath = path.resolve(publishDir, `${manifest.id}.jpl`);
|
const pluginArchiveFilePath = path.resolve(publishDir, `${manifest.id}.jpl`);
|
||||||
const pluginInfoFilePath = path.resolve(publishDir, `${manifest.id}.json`);
|
const pluginInfoFilePath = path.resolve(publishDir, `${manifest.id}.json`);
|
||||||
|
|
||||||
fs.removeSync(distDir);
|
|
||||||
fs.removeSync(publishDir);
|
|
||||||
fs.mkdirpSync(publishDir);
|
|
||||||
|
|
||||||
function validatePackageJson() {
|
function validatePackageJson() {
|
||||||
const content = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
const content = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
||||||
if (!content.name || content.name.indexOf('joplin-plugin-') !== 0) {
|
if (!content.name || content.name.indexOf('joplin-plugin-') !== 0) {
|
||||||
@ -109,6 +105,7 @@ function createPluginInfo(manifestPath, destPath, jplFilePath) {
|
|||||||
|
|
||||||
function onBuildCompleted() {
|
function onBuildCompleted() {
|
||||||
try {
|
try {
|
||||||
|
fs.removeSync(path.resolve(publishDir, 'index.js'));
|
||||||
createPluginArchive(distDir, pluginArchiveFilePath);
|
createPluginArchive(distDir, pluginArchiveFilePath);
|
||||||
createPluginInfo(manifestPath, pluginInfoFilePath, pluginArchiveFilePath);
|
createPluginInfo(manifestPath, pluginInfoFilePath, pluginArchiveFilePath);
|
||||||
validatePackageJson();
|
validatePackageJson();
|
||||||
@ -174,6 +171,16 @@ const extraScriptConfig = Object.assign({}, baseConfig, {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const createArchiveConfig = {
|
||||||
|
stats: 'errors-only',
|
||||||
|
entry: './dist/index.js',
|
||||||
|
output: {
|
||||||
|
filename: 'index.js',
|
||||||
|
path: publishDir,
|
||||||
|
},
|
||||||
|
plugins: [new WebpackOnBuildPlugin(onBuildCompleted)],
|
||||||
|
};
|
||||||
|
|
||||||
function resolveExtraScriptPath(name) {
|
function resolveExtraScriptPath(name) {
|
||||||
const relativePath = `./src/${name}`;
|
const relativePath = `./src/${name}`;
|
||||||
|
|
||||||
@ -196,8 +203,8 @@ function resolveExtraScriptPath(name) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function addExtraScriptConfigs(baseConfig, userConfig) {
|
function buildExtraScriptConfigs(userConfig) {
|
||||||
if (!userConfig.extraScripts.length) return baseConfig;
|
if (!userConfig.extraScripts.length) return [];
|
||||||
|
|
||||||
const output = [];
|
const output = [];
|
||||||
|
|
||||||
@ -209,22 +216,55 @@ function addExtraScriptConfigs(baseConfig, userConfig) {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
return baseConfig.concat(output);
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addLastConfigStep(config) {
|
function main(processArgv) {
|
||||||
const lastConfig = config[config.length - 1];
|
const yargs = require('yargs/yargs');
|
||||||
if (!lastConfig.plugins) lastConfig.plugins = [];
|
const argv = yargs(processArgv).argv;
|
||||||
lastConfig.plugins.push(new WebpackOnBuildPlugin(onBuildCompleted));
|
|
||||||
config[config.length - 1] = lastConfig;
|
const configName = argv['joplin-plugin-config'];
|
||||||
return config;
|
if (!configName) throw new Error('A config file must be specified via the --joplin-plugin-config flag');
|
||||||
|
|
||||||
|
// Webpack configurations run in parallel, while we need them to run in
|
||||||
|
// sequence, and to do that it seems the only way is to run webpack multiple
|
||||||
|
// times, with different config each time.
|
||||||
|
|
||||||
|
const configs = {
|
||||||
|
// Builds the main src/index.ts and copy the extra content from /src to
|
||||||
|
// /dist including scripts, CSS and any other asset.
|
||||||
|
buildMain: pluginConfig,
|
||||||
|
|
||||||
|
// Builds the extra scripts as defined in plugin.config.json. When doing
|
||||||
|
// so, some JavaScript files that were copied in the previous might be
|
||||||
|
// overwritten here by the compiled version. This is by design. The
|
||||||
|
// result is that JS files that don't need compilation, are simply
|
||||||
|
// copied to /dist, while those that do need it are correctly compiled.
|
||||||
|
buildExtraScripts: buildExtraScriptConfigs(userConfig),
|
||||||
|
|
||||||
|
// Ths config is for creating the .jpl, which is done via the plugin, so
|
||||||
|
// it doesn't actually need an entry and output, however webpack won't
|
||||||
|
// run without this. So we give it an entry that we know is going to
|
||||||
|
// exist and output in the publish dir. Then the plugin will delete this
|
||||||
|
// temporary file before packaging the plugin.
|
||||||
|
createArchive: createArchiveConfig,
|
||||||
|
};
|
||||||
|
|
||||||
|
// If we are running the first config step, we clean up and create the build
|
||||||
|
// directories.
|
||||||
|
if (configName === 'buildMain') {
|
||||||
|
fs.removeSync(distDir);
|
||||||
|
fs.removeSync(publishDir);
|
||||||
|
fs.mkdirpSync(publishDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
return configs[configName];
|
||||||
}
|
}
|
||||||
|
|
||||||
let exportedConfigs = [pluginConfig];
|
let exportedConfigs = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
exportedConfigs = addExtraScriptConfigs(exportedConfigs, userConfig);
|
exportedConfigs = main(process.argv);
|
||||||
exportedConfigs = addLastConfigStep(exportedConfigs);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(chalk.red(error.message));
|
console.error(chalk.red(error.message));
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
dist/
|
dist/
|
||||||
node_modules/
|
node_modules/
|
||||||
publish/
|
publish/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,7 +6,3 @@
|
|||||||
/dist
|
/dist
|
||||||
tsconfig.json
|
tsconfig.json
|
||||||
webpack.config.js
|
webpack.config.js
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,10 +23,18 @@ export default class JoplinContentScripts {
|
|||||||
* * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script)
|
* * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script)
|
||||||
* * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script)
|
* * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script)
|
||||||
*
|
*
|
||||||
|
* See also the [postMessage demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages)
|
||||||
|
*
|
||||||
* @param type Defines how the script will be used. See the type definition for more information about each supported type.
|
* @param type Defines how the script will be used. See the type definition for more information about each supported type.
|
||||||
* @param id A unique ID for the content script.
|
* @param id A unique ID for the content script.
|
||||||
* @param scriptPath Must be a path relative to the plugin main script. For example, if your file content_script.js is next to your index.ts file, you would set `scriptPath` to `"./content_script.js`.
|
* @param scriptPath Must be a path relative to the plugin main script. For example, if your file content_script.js is next to your index.ts file, you would set `scriptPath` to `"./content_script.js`.
|
||||||
*/
|
*/
|
||||||
register(type: ContentScriptType, id: string, scriptPath: string): Promise<void>;
|
register(type: ContentScriptType, id: string, scriptPath: string): Promise<void>;
|
||||||
onMessage(id: string, callback: any): Promise<void>;
|
/**
|
||||||
|
* Listens to a messages sent from the content script using postMessage().
|
||||||
|
* See {@link ContentScriptType} for more information as well as the
|
||||||
|
* [postMessage
|
||||||
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages)
|
||||||
|
*/
|
||||||
|
onMessage(contentScriptId: string, callback: any): Promise<void>;
|
||||||
}
|
}
|
||||||
|
@ -458,7 +458,7 @@ export enum ContentScriptType {
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* See {@link JoplinContentScript.onMessage} for more details, as well as
|
* See {@link JoplinContentScripts.onMessage} for more details, as well as
|
||||||
* the [postMessage
|
* the [postMessage
|
||||||
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
||||||
*
|
*
|
||||||
@ -557,7 +557,7 @@ export enum ContentScriptType {
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* See {@link JoplinContentScript.onMessage} for more details, as well as
|
* See {@link JoplinContentScripts.onMessage} for more details, as well as
|
||||||
* the [postMessage
|
* the [postMessage
|
||||||
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
||||||
*
|
*
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dist": "webpack",
|
"dist": "webpack --joplin-plugin-config buildMain && webpack --joplin-plugin-config buildExtraScripts && webpack --joplin-plugin-config createArchive",
|
||||||
"prepare": "npm run dist",
|
"prepare": "npm run dist",
|
||||||
"update": "npm install -g generator-joplin && yo joplin --update"
|
"update": "npm install -g generator-joplin && yo joplin --update"
|
||||||
},
|
},
|
||||||
@ -22,6 +22,7 @@
|
|||||||
"typescript": "^3.9.3",
|
"typescript": "^3.9.3",
|
||||||
"webpack": "^4.43.0",
|
"webpack": "^4.43.0",
|
||||||
"webpack-cli": "^3.3.11",
|
"webpack-cli": "^3.3.11",
|
||||||
"chalk": "^4.1.0"
|
"chalk": "^4.1.0",
|
||||||
|
"yargs": "^16.2.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -33,10 +33,6 @@ const manifest = readManifest(manifestPath);
|
|||||||
const pluginArchiveFilePath = path.resolve(publishDir, `${manifest.id}.jpl`);
|
const pluginArchiveFilePath = path.resolve(publishDir, `${manifest.id}.jpl`);
|
||||||
const pluginInfoFilePath = path.resolve(publishDir, `${manifest.id}.json`);
|
const pluginInfoFilePath = path.resolve(publishDir, `${manifest.id}.json`);
|
||||||
|
|
||||||
fs.removeSync(distDir);
|
|
||||||
fs.removeSync(publishDir);
|
|
||||||
fs.mkdirpSync(publishDir);
|
|
||||||
|
|
||||||
function validatePackageJson() {
|
function validatePackageJson() {
|
||||||
const content = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
const content = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
||||||
if (!content.name || content.name.indexOf('joplin-plugin-') !== 0) {
|
if (!content.name || content.name.indexOf('joplin-plugin-') !== 0) {
|
||||||
@ -109,6 +105,7 @@ function createPluginInfo(manifestPath, destPath, jplFilePath) {
|
|||||||
|
|
||||||
function onBuildCompleted() {
|
function onBuildCompleted() {
|
||||||
try {
|
try {
|
||||||
|
fs.removeSync(path.resolve(publishDir, 'index.js'));
|
||||||
createPluginArchive(distDir, pluginArchiveFilePath);
|
createPluginArchive(distDir, pluginArchiveFilePath);
|
||||||
createPluginInfo(manifestPath, pluginInfoFilePath, pluginArchiveFilePath);
|
createPluginInfo(manifestPath, pluginInfoFilePath, pluginArchiveFilePath);
|
||||||
validatePackageJson();
|
validatePackageJson();
|
||||||
@ -174,6 +171,16 @@ const extraScriptConfig = Object.assign({}, baseConfig, {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const createArchiveConfig = {
|
||||||
|
stats: 'errors-only',
|
||||||
|
entry: './dist/index.js',
|
||||||
|
output: {
|
||||||
|
filename: 'index.js',
|
||||||
|
path: publishDir,
|
||||||
|
},
|
||||||
|
plugins: [new WebpackOnBuildPlugin(onBuildCompleted)],
|
||||||
|
};
|
||||||
|
|
||||||
function resolveExtraScriptPath(name) {
|
function resolveExtraScriptPath(name) {
|
||||||
const relativePath = `./src/${name}`;
|
const relativePath = `./src/${name}`;
|
||||||
|
|
||||||
@ -196,8 +203,8 @@ function resolveExtraScriptPath(name) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function addExtraScriptConfigs(baseConfig, userConfig) {
|
function buildExtraScriptConfigs(userConfig) {
|
||||||
if (!userConfig.extraScripts.length) return baseConfig;
|
if (!userConfig.extraScripts.length) return [];
|
||||||
|
|
||||||
const output = [];
|
const output = [];
|
||||||
|
|
||||||
@ -209,22 +216,55 @@ function addExtraScriptConfigs(baseConfig, userConfig) {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
return baseConfig.concat(output);
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addLastConfigStep(config) {
|
function main(processArgv) {
|
||||||
const lastConfig = config[config.length - 1];
|
const yargs = require('yargs/yargs');
|
||||||
if (!lastConfig.plugins) lastConfig.plugins = [];
|
const argv = yargs(processArgv).argv;
|
||||||
lastConfig.plugins.push(new WebpackOnBuildPlugin(onBuildCompleted));
|
|
||||||
config[config.length - 1] = lastConfig;
|
const configName = argv['joplin-plugin-config'];
|
||||||
return config;
|
if (!configName) throw new Error('A config file must be specified via the --joplin-plugin-config flag');
|
||||||
|
|
||||||
|
// Webpack configurations run in parallel, while we need them to run in
|
||||||
|
// sequence, and to do that it seems the only way is to run webpack multiple
|
||||||
|
// times, with different config each time.
|
||||||
|
|
||||||
|
const configs = {
|
||||||
|
// Builds the main src/index.ts and copy the extra content from /src to
|
||||||
|
// /dist including scripts, CSS and any other asset.
|
||||||
|
buildMain: pluginConfig,
|
||||||
|
|
||||||
|
// Builds the extra scripts as defined in plugin.config.json. When doing
|
||||||
|
// so, some JavaScript files that were copied in the previous might be
|
||||||
|
// overwritten here by the compiled version. This is by design. The
|
||||||
|
// result is that JS files that don't need compilation, are simply
|
||||||
|
// copied to /dist, while those that do need it are correctly compiled.
|
||||||
|
buildExtraScripts: buildExtraScriptConfigs(userConfig),
|
||||||
|
|
||||||
|
// Ths config is for creating the .jpl, which is done via the plugin, so
|
||||||
|
// it doesn't actually need an entry and output, however webpack won't
|
||||||
|
// run without this. So we give it an entry that we know is going to
|
||||||
|
// exist and output in the publish dir. Then the plugin will delete this
|
||||||
|
// temporary file before packaging the plugin.
|
||||||
|
createArchive: createArchiveConfig,
|
||||||
|
};
|
||||||
|
|
||||||
|
// If we are running the first config step, we clean up and create the build
|
||||||
|
// directories.
|
||||||
|
if (configName === 'buildMain') {
|
||||||
|
fs.removeSync(distDir);
|
||||||
|
fs.removeSync(publishDir);
|
||||||
|
fs.mkdirpSync(publishDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
return configs[configName];
|
||||||
}
|
}
|
||||||
|
|
||||||
let exportedConfigs = [pluginConfig];
|
let exportedConfigs = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
exportedConfigs = addExtraScriptConfigs(exportedConfigs, userConfig);
|
exportedConfigs = main(process.argv);
|
||||||
exportedConfigs = addLastConfigStep(exportedConfigs);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(chalk.red(error.message));
|
console.error(chalk.red(error.message));
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
dist/
|
dist/
|
||||||
node_modules/
|
node_modules/
|
||||||
publish/
|
publish/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,7 +6,3 @@
|
|||||||
/dist
|
/dist
|
||||||
tsconfig.json
|
tsconfig.json
|
||||||
webpack.config.js
|
webpack.config.js
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,10 +23,18 @@ export default class JoplinContentScripts {
|
|||||||
* * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script)
|
* * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script)
|
||||||
* * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script)
|
* * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script)
|
||||||
*
|
*
|
||||||
|
* See also the [postMessage demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages)
|
||||||
|
*
|
||||||
* @param type Defines how the script will be used. See the type definition for more information about each supported type.
|
* @param type Defines how the script will be used. See the type definition for more information about each supported type.
|
||||||
* @param id A unique ID for the content script.
|
* @param id A unique ID for the content script.
|
||||||
* @param scriptPath Must be a path relative to the plugin main script. For example, if your file content_script.js is next to your index.ts file, you would set `scriptPath` to `"./content_script.js`.
|
* @param scriptPath Must be a path relative to the plugin main script. For example, if your file content_script.js is next to your index.ts file, you would set `scriptPath` to `"./content_script.js`.
|
||||||
*/
|
*/
|
||||||
register(type: ContentScriptType, id: string, scriptPath: string): Promise<void>;
|
register(type: ContentScriptType, id: string, scriptPath: string): Promise<void>;
|
||||||
onMessage(id: string, callback: any): Promise<void>;
|
/**
|
||||||
|
* Listens to a messages sent from the content script using postMessage().
|
||||||
|
* See {@link ContentScriptType} for more information as well as the
|
||||||
|
* [postMessage
|
||||||
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages)
|
||||||
|
*/
|
||||||
|
onMessage(contentScriptId: string, callback: any): Promise<void>;
|
||||||
}
|
}
|
||||||
|
@ -458,7 +458,7 @@ export enum ContentScriptType {
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* See {@link JoplinContentScript.onMessage} for more details, as well as
|
* See {@link JoplinContentScripts.onMessage} for more details, as well as
|
||||||
* the [postMessage
|
* the [postMessage
|
||||||
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
||||||
*
|
*
|
||||||
@ -557,7 +557,7 @@ export enum ContentScriptType {
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* See {@link JoplinContentScript.onMessage} for more details, as well as
|
* See {@link JoplinContentScripts.onMessage} for more details, as well as
|
||||||
* the [postMessage
|
* the [postMessage
|
||||||
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
||||||
*
|
*
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dist": "webpack",
|
"dist": "webpack --joplin-plugin-config buildMain && webpack --joplin-plugin-config buildExtraScripts && webpack --joplin-plugin-config createArchive",
|
||||||
"prepare": "npm run dist",
|
"prepare": "npm run dist",
|
||||||
"update": "npm install -g generator-joplin && yo joplin --update"
|
"update": "npm install -g generator-joplin && yo joplin --update"
|
||||||
},
|
},
|
||||||
@ -22,6 +22,7 @@
|
|||||||
"typescript": "^3.9.3",
|
"typescript": "^3.9.3",
|
||||||
"webpack": "^4.43.0",
|
"webpack": "^4.43.0",
|
||||||
"webpack-cli": "^3.3.11",
|
"webpack-cli": "^3.3.11",
|
||||||
"chalk": "^4.1.0"
|
"chalk": "^4.1.0",
|
||||||
|
"yargs": "^16.2.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -33,10 +33,6 @@ const manifest = readManifest(manifestPath);
|
|||||||
const pluginArchiveFilePath = path.resolve(publishDir, `${manifest.id}.jpl`);
|
const pluginArchiveFilePath = path.resolve(publishDir, `${manifest.id}.jpl`);
|
||||||
const pluginInfoFilePath = path.resolve(publishDir, `${manifest.id}.json`);
|
const pluginInfoFilePath = path.resolve(publishDir, `${manifest.id}.json`);
|
||||||
|
|
||||||
fs.removeSync(distDir);
|
|
||||||
fs.removeSync(publishDir);
|
|
||||||
fs.mkdirpSync(publishDir);
|
|
||||||
|
|
||||||
function validatePackageJson() {
|
function validatePackageJson() {
|
||||||
const content = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
const content = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
||||||
if (!content.name || content.name.indexOf('joplin-plugin-') !== 0) {
|
if (!content.name || content.name.indexOf('joplin-plugin-') !== 0) {
|
||||||
@ -109,6 +105,7 @@ function createPluginInfo(manifestPath, destPath, jplFilePath) {
|
|||||||
|
|
||||||
function onBuildCompleted() {
|
function onBuildCompleted() {
|
||||||
try {
|
try {
|
||||||
|
fs.removeSync(path.resolve(publishDir, 'index.js'));
|
||||||
createPluginArchive(distDir, pluginArchiveFilePath);
|
createPluginArchive(distDir, pluginArchiveFilePath);
|
||||||
createPluginInfo(manifestPath, pluginInfoFilePath, pluginArchiveFilePath);
|
createPluginInfo(manifestPath, pluginInfoFilePath, pluginArchiveFilePath);
|
||||||
validatePackageJson();
|
validatePackageJson();
|
||||||
@ -174,6 +171,16 @@ const extraScriptConfig = Object.assign({}, baseConfig, {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const createArchiveConfig = {
|
||||||
|
stats: 'errors-only',
|
||||||
|
entry: './dist/index.js',
|
||||||
|
output: {
|
||||||
|
filename: 'index.js',
|
||||||
|
path: publishDir,
|
||||||
|
},
|
||||||
|
plugins: [new WebpackOnBuildPlugin(onBuildCompleted)],
|
||||||
|
};
|
||||||
|
|
||||||
function resolveExtraScriptPath(name) {
|
function resolveExtraScriptPath(name) {
|
||||||
const relativePath = `./src/${name}`;
|
const relativePath = `./src/${name}`;
|
||||||
|
|
||||||
@ -196,8 +203,8 @@ function resolveExtraScriptPath(name) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function addExtraScriptConfigs(baseConfig, userConfig) {
|
function buildExtraScriptConfigs(userConfig) {
|
||||||
if (!userConfig.extraScripts.length) return baseConfig;
|
if (!userConfig.extraScripts.length) return [];
|
||||||
|
|
||||||
const output = [];
|
const output = [];
|
||||||
|
|
||||||
@ -209,22 +216,55 @@ function addExtraScriptConfigs(baseConfig, userConfig) {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
return baseConfig.concat(output);
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addLastConfigStep(config) {
|
function main(processArgv) {
|
||||||
const lastConfig = config[config.length - 1];
|
const yargs = require('yargs/yargs');
|
||||||
if (!lastConfig.plugins) lastConfig.plugins = [];
|
const argv = yargs(processArgv).argv;
|
||||||
lastConfig.plugins.push(new WebpackOnBuildPlugin(onBuildCompleted));
|
|
||||||
config[config.length - 1] = lastConfig;
|
const configName = argv['joplin-plugin-config'];
|
||||||
return config;
|
if (!configName) throw new Error('A config file must be specified via the --joplin-plugin-config flag');
|
||||||
|
|
||||||
|
// Webpack configurations run in parallel, while we need them to run in
|
||||||
|
// sequence, and to do that it seems the only way is to run webpack multiple
|
||||||
|
// times, with different config each time.
|
||||||
|
|
||||||
|
const configs = {
|
||||||
|
// Builds the main src/index.ts and copy the extra content from /src to
|
||||||
|
// /dist including scripts, CSS and any other asset.
|
||||||
|
buildMain: pluginConfig,
|
||||||
|
|
||||||
|
// Builds the extra scripts as defined in plugin.config.json. When doing
|
||||||
|
// so, some JavaScript files that were copied in the previous might be
|
||||||
|
// overwritten here by the compiled version. This is by design. The
|
||||||
|
// result is that JS files that don't need compilation, are simply
|
||||||
|
// copied to /dist, while those that do need it are correctly compiled.
|
||||||
|
buildExtraScripts: buildExtraScriptConfigs(userConfig),
|
||||||
|
|
||||||
|
// Ths config is for creating the .jpl, which is done via the plugin, so
|
||||||
|
// it doesn't actually need an entry and output, however webpack won't
|
||||||
|
// run without this. So we give it an entry that we know is going to
|
||||||
|
// exist and output in the publish dir. Then the plugin will delete this
|
||||||
|
// temporary file before packaging the plugin.
|
||||||
|
createArchive: createArchiveConfig,
|
||||||
|
};
|
||||||
|
|
||||||
|
// If we are running the first config step, we clean up and create the build
|
||||||
|
// directories.
|
||||||
|
if (configName === 'buildMain') {
|
||||||
|
fs.removeSync(distDir);
|
||||||
|
fs.removeSync(publishDir);
|
||||||
|
fs.mkdirpSync(publishDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
return configs[configName];
|
||||||
}
|
}
|
||||||
|
|
||||||
let exportedConfigs = [pluginConfig];
|
let exportedConfigs = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
exportedConfigs = addExtraScriptConfigs(exportedConfigs, userConfig);
|
exportedConfigs = main(process.argv);
|
||||||
exportedConfigs = addLastConfigStep(exportedConfigs);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(chalk.red(error.message));
|
console.error(chalk.red(error.message));
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
dist/
|
dist/
|
||||||
node_modules/
|
node_modules/
|
||||||
publish/
|
publish/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,7 +6,3 @@
|
|||||||
/dist
|
/dist
|
||||||
tsconfig.json
|
tsconfig.json
|
||||||
webpack.config.js
|
webpack.config.js
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,10 +23,18 @@ export default class JoplinContentScripts {
|
|||||||
* * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script)
|
* * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script)
|
||||||
* * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script)
|
* * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script)
|
||||||
*
|
*
|
||||||
|
* See also the [postMessage demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages)
|
||||||
|
*
|
||||||
* @param type Defines how the script will be used. See the type definition for more information about each supported type.
|
* @param type Defines how the script will be used. See the type definition for more information about each supported type.
|
||||||
* @param id A unique ID for the content script.
|
* @param id A unique ID for the content script.
|
||||||
* @param scriptPath Must be a path relative to the plugin main script. For example, if your file content_script.js is next to your index.ts file, you would set `scriptPath` to `"./content_script.js`.
|
* @param scriptPath Must be a path relative to the plugin main script. For example, if your file content_script.js is next to your index.ts file, you would set `scriptPath` to `"./content_script.js`.
|
||||||
*/
|
*/
|
||||||
register(type: ContentScriptType, id: string, scriptPath: string): Promise<void>;
|
register(type: ContentScriptType, id: string, scriptPath: string): Promise<void>;
|
||||||
onMessage(id: string, callback: any): Promise<void>;
|
/**
|
||||||
|
* Listens to a messages sent from the content script using postMessage().
|
||||||
|
* See {@link ContentScriptType} for more information as well as the
|
||||||
|
* [postMessage
|
||||||
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages)
|
||||||
|
*/
|
||||||
|
onMessage(contentScriptId: string, callback: any): Promise<void>;
|
||||||
}
|
}
|
||||||
|
@ -458,7 +458,7 @@ export enum ContentScriptType {
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* See {@link JoplinContentScript.onMessage} for more details, as well as
|
* See {@link JoplinContentScripts.onMessage} for more details, as well as
|
||||||
* the [postMessage
|
* the [postMessage
|
||||||
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
||||||
*
|
*
|
||||||
@ -557,7 +557,7 @@ export enum ContentScriptType {
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* See {@link JoplinContentScript.onMessage} for more details, as well as
|
* See {@link JoplinContentScripts.onMessage} for more details, as well as
|
||||||
* the [postMessage
|
* the [postMessage
|
||||||
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
||||||
*
|
*
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dist": "webpack",
|
"dist": "webpack --joplin-plugin-config buildMain && webpack --joplin-plugin-config buildExtraScripts && webpack --joplin-plugin-config createArchive",
|
||||||
"prepare": "npm run dist",
|
"prepare": "npm run dist",
|
||||||
"update": "npm install -g generator-joplin && yo joplin --update"
|
"update": "npm install -g generator-joplin && yo joplin --update"
|
||||||
},
|
},
|
||||||
@ -22,6 +22,7 @@
|
|||||||
"typescript": "^3.9.3",
|
"typescript": "^3.9.3",
|
||||||
"webpack": "^4.43.0",
|
"webpack": "^4.43.0",
|
||||||
"webpack-cli": "^3.3.11",
|
"webpack-cli": "^3.3.11",
|
||||||
"chalk": "^4.1.0"
|
"chalk": "^4.1.0",
|
||||||
|
"yargs": "^16.2.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -33,10 +33,6 @@ const manifest = readManifest(manifestPath);
|
|||||||
const pluginArchiveFilePath = path.resolve(publishDir, `${manifest.id}.jpl`);
|
const pluginArchiveFilePath = path.resolve(publishDir, `${manifest.id}.jpl`);
|
||||||
const pluginInfoFilePath = path.resolve(publishDir, `${manifest.id}.json`);
|
const pluginInfoFilePath = path.resolve(publishDir, `${manifest.id}.json`);
|
||||||
|
|
||||||
fs.removeSync(distDir);
|
|
||||||
fs.removeSync(publishDir);
|
|
||||||
fs.mkdirpSync(publishDir);
|
|
||||||
|
|
||||||
function validatePackageJson() {
|
function validatePackageJson() {
|
||||||
const content = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
const content = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
||||||
if (!content.name || content.name.indexOf('joplin-plugin-') !== 0) {
|
if (!content.name || content.name.indexOf('joplin-plugin-') !== 0) {
|
||||||
@ -109,6 +105,7 @@ function createPluginInfo(manifestPath, destPath, jplFilePath) {
|
|||||||
|
|
||||||
function onBuildCompleted() {
|
function onBuildCompleted() {
|
||||||
try {
|
try {
|
||||||
|
fs.removeSync(path.resolve(publishDir, 'index.js'));
|
||||||
createPluginArchive(distDir, pluginArchiveFilePath);
|
createPluginArchive(distDir, pluginArchiveFilePath);
|
||||||
createPluginInfo(manifestPath, pluginInfoFilePath, pluginArchiveFilePath);
|
createPluginInfo(manifestPath, pluginInfoFilePath, pluginArchiveFilePath);
|
||||||
validatePackageJson();
|
validatePackageJson();
|
||||||
@ -174,6 +171,16 @@ const extraScriptConfig = Object.assign({}, baseConfig, {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const createArchiveConfig = {
|
||||||
|
stats: 'errors-only',
|
||||||
|
entry: './dist/index.js',
|
||||||
|
output: {
|
||||||
|
filename: 'index.js',
|
||||||
|
path: publishDir,
|
||||||
|
},
|
||||||
|
plugins: [new WebpackOnBuildPlugin(onBuildCompleted)],
|
||||||
|
};
|
||||||
|
|
||||||
function resolveExtraScriptPath(name) {
|
function resolveExtraScriptPath(name) {
|
||||||
const relativePath = `./src/${name}`;
|
const relativePath = `./src/${name}`;
|
||||||
|
|
||||||
@ -196,8 +203,8 @@ function resolveExtraScriptPath(name) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function addExtraScriptConfigs(baseConfig, userConfig) {
|
function buildExtraScriptConfigs(userConfig) {
|
||||||
if (!userConfig.extraScripts.length) return baseConfig;
|
if (!userConfig.extraScripts.length) return [];
|
||||||
|
|
||||||
const output = [];
|
const output = [];
|
||||||
|
|
||||||
@ -209,22 +216,55 @@ function addExtraScriptConfigs(baseConfig, userConfig) {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
return baseConfig.concat(output);
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addLastConfigStep(config) {
|
function main(processArgv) {
|
||||||
const lastConfig = config[config.length - 1];
|
const yargs = require('yargs/yargs');
|
||||||
if (!lastConfig.plugins) lastConfig.plugins = [];
|
const argv = yargs(processArgv).argv;
|
||||||
lastConfig.plugins.push(new WebpackOnBuildPlugin(onBuildCompleted));
|
|
||||||
config[config.length - 1] = lastConfig;
|
const configName = argv['joplin-plugin-config'];
|
||||||
return config;
|
if (!configName) throw new Error('A config file must be specified via the --joplin-plugin-config flag');
|
||||||
|
|
||||||
|
// Webpack configurations run in parallel, while we need them to run in
|
||||||
|
// sequence, and to do that it seems the only way is to run webpack multiple
|
||||||
|
// times, with different config each time.
|
||||||
|
|
||||||
|
const configs = {
|
||||||
|
// Builds the main src/index.ts and copy the extra content from /src to
|
||||||
|
// /dist including scripts, CSS and any other asset.
|
||||||
|
buildMain: pluginConfig,
|
||||||
|
|
||||||
|
// Builds the extra scripts as defined in plugin.config.json. When doing
|
||||||
|
// so, some JavaScript files that were copied in the previous might be
|
||||||
|
// overwritten here by the compiled version. This is by design. The
|
||||||
|
// result is that JS files that don't need compilation, are simply
|
||||||
|
// copied to /dist, while those that do need it are correctly compiled.
|
||||||
|
buildExtraScripts: buildExtraScriptConfigs(userConfig),
|
||||||
|
|
||||||
|
// Ths config is for creating the .jpl, which is done via the plugin, so
|
||||||
|
// it doesn't actually need an entry and output, however webpack won't
|
||||||
|
// run without this. So we give it an entry that we know is going to
|
||||||
|
// exist and output in the publish dir. Then the plugin will delete this
|
||||||
|
// temporary file before packaging the plugin.
|
||||||
|
createArchive: createArchiveConfig,
|
||||||
|
};
|
||||||
|
|
||||||
|
// If we are running the first config step, we clean up and create the build
|
||||||
|
// directories.
|
||||||
|
if (configName === 'buildMain') {
|
||||||
|
fs.removeSync(distDir);
|
||||||
|
fs.removeSync(publishDir);
|
||||||
|
fs.mkdirpSync(publishDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
return configs[configName];
|
||||||
}
|
}
|
||||||
|
|
||||||
let exportedConfigs = [pluginConfig];
|
let exportedConfigs = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
exportedConfigs = addExtraScriptConfigs(exportedConfigs, userConfig);
|
exportedConfigs = main(process.argv);
|
||||||
exportedConfigs = addLastConfigStep(exportedConfigs);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(chalk.red(error.message));
|
console.error(chalk.red(error.message));
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
dist/
|
dist/
|
||||||
node_modules/
|
node_modules/
|
||||||
publish/
|
publish/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,6 +6,3 @@
|
|||||||
/dist
|
/dist
|
||||||
tsconfig.json
|
tsconfig.json
|
||||||
webpack.config.js
|
webpack.config.js
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,10 +23,18 @@ export default class JoplinContentScripts {
|
|||||||
* * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script)
|
* * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script)
|
||||||
* * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script)
|
* * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script)
|
||||||
*
|
*
|
||||||
|
* See also the [postMessage demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages)
|
||||||
|
*
|
||||||
* @param type Defines how the script will be used. See the type definition for more information about each supported type.
|
* @param type Defines how the script will be used. See the type definition for more information about each supported type.
|
||||||
* @param id A unique ID for the content script.
|
* @param id A unique ID for the content script.
|
||||||
* @param scriptPath Must be a path relative to the plugin main script. For example, if your file content_script.js is next to your index.ts file, you would set `scriptPath` to `"./content_script.js`.
|
* @param scriptPath Must be a path relative to the plugin main script. For example, if your file content_script.js is next to your index.ts file, you would set `scriptPath` to `"./content_script.js`.
|
||||||
*/
|
*/
|
||||||
register(type: ContentScriptType, id: string, scriptPath: string): Promise<void>;
|
register(type: ContentScriptType, id: string, scriptPath: string): Promise<void>;
|
||||||
onMessage(id: string, callback: any): Promise<void>;
|
/**
|
||||||
|
* Listens to a messages sent from the content script using postMessage().
|
||||||
|
* See {@link ContentScriptType} for more information as well as the
|
||||||
|
* [postMessage
|
||||||
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages)
|
||||||
|
*/
|
||||||
|
onMessage(contentScriptId: string, callback: any): Promise<void>;
|
||||||
}
|
}
|
||||||
|
@ -458,7 +458,7 @@ export enum ContentScriptType {
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* See {@link JoplinContentScript.onMessage} for more details, as well as
|
* See {@link JoplinContentScripts.onMessage} for more details, as well as
|
||||||
* the [postMessage
|
* the [postMessage
|
||||||
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
||||||
*
|
*
|
||||||
@ -557,7 +557,7 @@ export enum ContentScriptType {
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* See {@link JoplinContentScript.onMessage} for more details, as well as
|
* See {@link JoplinContentScripts.onMessage} for more details, as well as
|
||||||
* the [postMessage
|
* the [postMessage
|
||||||
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
||||||
*
|
*
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"name": "joplin-plugin-postmessage-demo",
|
"name": "joplin-plugin-postmessage-demo",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dist": "webpack",
|
"dist": "webpack --joplin-plugin-config buildMain && webpack --joplin-plugin-config buildExtraScripts && webpack --joplin-plugin-config createArchive",
|
||||||
"prepare": "npm run dist",
|
"prepare": "npm run dist",
|
||||||
"update": "npm install -g generator-joplin && yo joplin --update"
|
"update": "npm install -g generator-joplin && yo joplin --update"
|
||||||
},
|
},
|
||||||
@ -21,6 +21,7 @@
|
|||||||
"ts-loader": "^7.0.5",
|
"ts-loader": "^7.0.5",
|
||||||
"typescript": "^3.9.3",
|
"typescript": "^3.9.3",
|
||||||
"webpack": "^4.43.0",
|
"webpack": "^4.43.0",
|
||||||
"webpack-cli": "^3.3.11"
|
"webpack-cli": "^3.3.11",
|
||||||
|
"yargs": "^16.2.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -33,10 +33,6 @@ const manifest = readManifest(manifestPath);
|
|||||||
const pluginArchiveFilePath = path.resolve(publishDir, `${manifest.id}.jpl`);
|
const pluginArchiveFilePath = path.resolve(publishDir, `${manifest.id}.jpl`);
|
||||||
const pluginInfoFilePath = path.resolve(publishDir, `${manifest.id}.json`);
|
const pluginInfoFilePath = path.resolve(publishDir, `${manifest.id}.json`);
|
||||||
|
|
||||||
fs.removeSync(distDir);
|
|
||||||
fs.removeSync(publishDir);
|
|
||||||
fs.mkdirpSync(publishDir);
|
|
||||||
|
|
||||||
function validatePackageJson() {
|
function validatePackageJson() {
|
||||||
const content = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
const content = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
||||||
if (!content.name || content.name.indexOf('joplin-plugin-') !== 0) {
|
if (!content.name || content.name.indexOf('joplin-plugin-') !== 0) {
|
||||||
@ -109,6 +105,7 @@ function createPluginInfo(manifestPath, destPath, jplFilePath) {
|
|||||||
|
|
||||||
function onBuildCompleted() {
|
function onBuildCompleted() {
|
||||||
try {
|
try {
|
||||||
|
fs.removeSync(path.resolve(publishDir, 'index.js'));
|
||||||
createPluginArchive(distDir, pluginArchiveFilePath);
|
createPluginArchive(distDir, pluginArchiveFilePath);
|
||||||
createPluginInfo(manifestPath, pluginInfoFilePath, pluginArchiveFilePath);
|
createPluginInfo(manifestPath, pluginInfoFilePath, pluginArchiveFilePath);
|
||||||
validatePackageJson();
|
validatePackageJson();
|
||||||
@ -174,6 +171,16 @@ const extraScriptConfig = Object.assign({}, baseConfig, {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const createArchiveConfig = {
|
||||||
|
stats: 'errors-only',
|
||||||
|
entry: './dist/index.js',
|
||||||
|
output: {
|
||||||
|
filename: 'index.js',
|
||||||
|
path: publishDir,
|
||||||
|
},
|
||||||
|
plugins: [new WebpackOnBuildPlugin(onBuildCompleted)],
|
||||||
|
};
|
||||||
|
|
||||||
function resolveExtraScriptPath(name) {
|
function resolveExtraScriptPath(name) {
|
||||||
const relativePath = `./src/${name}`;
|
const relativePath = `./src/${name}`;
|
||||||
|
|
||||||
@ -196,8 +203,8 @@ function resolveExtraScriptPath(name) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function addExtraScriptConfigs(baseConfig, userConfig) {
|
function buildExtraScriptConfigs(userConfig) {
|
||||||
if (!userConfig.extraScripts.length) return baseConfig;
|
if (!userConfig.extraScripts.length) return [];
|
||||||
|
|
||||||
const output = [];
|
const output = [];
|
||||||
|
|
||||||
@ -209,22 +216,55 @@ function addExtraScriptConfigs(baseConfig, userConfig) {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
return baseConfig.concat(output);
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addLastConfigStep(config) {
|
function main(processArgv) {
|
||||||
const lastConfig = config[config.length - 1];
|
const yargs = require('yargs/yargs');
|
||||||
if (!lastConfig.plugins) lastConfig.plugins = [];
|
const argv = yargs(processArgv).argv;
|
||||||
lastConfig.plugins.push(new WebpackOnBuildPlugin(onBuildCompleted));
|
|
||||||
config[config.length - 1] = lastConfig;
|
const configName = argv['joplin-plugin-config'];
|
||||||
return config;
|
if (!configName) throw new Error('A config file must be specified via the --joplin-plugin-config flag');
|
||||||
|
|
||||||
|
// Webpack configurations run in parallel, while we need them to run in
|
||||||
|
// sequence, and to do that it seems the only way is to run webpack multiple
|
||||||
|
// times, with different config each time.
|
||||||
|
|
||||||
|
const configs = {
|
||||||
|
// Builds the main src/index.ts and copy the extra content from /src to
|
||||||
|
// /dist including scripts, CSS and any other asset.
|
||||||
|
buildMain: pluginConfig,
|
||||||
|
|
||||||
|
// Builds the extra scripts as defined in plugin.config.json. When doing
|
||||||
|
// so, some JavaScript files that were copied in the previous might be
|
||||||
|
// overwritten here by the compiled version. This is by design. The
|
||||||
|
// result is that JS files that don't need compilation, are simply
|
||||||
|
// copied to /dist, while those that do need it are correctly compiled.
|
||||||
|
buildExtraScripts: buildExtraScriptConfigs(userConfig),
|
||||||
|
|
||||||
|
// Ths config is for creating the .jpl, which is done via the plugin, so
|
||||||
|
// it doesn't actually need an entry and output, however webpack won't
|
||||||
|
// run without this. So we give it an entry that we know is going to
|
||||||
|
// exist and output in the publish dir. Then the plugin will delete this
|
||||||
|
// temporary file before packaging the plugin.
|
||||||
|
createArchive: createArchiveConfig,
|
||||||
|
};
|
||||||
|
|
||||||
|
// If we are running the first config step, we clean up and create the build
|
||||||
|
// directories.
|
||||||
|
if (configName === 'buildMain') {
|
||||||
|
fs.removeSync(distDir);
|
||||||
|
fs.removeSync(publishDir);
|
||||||
|
fs.mkdirpSync(publishDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
return configs[configName];
|
||||||
}
|
}
|
||||||
|
|
||||||
let exportedConfigs = [pluginConfig];
|
let exportedConfigs = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
exportedConfigs = addExtraScriptConfigs(exportedConfigs, userConfig);
|
exportedConfigs = main(process.argv);
|
||||||
exportedConfigs = addLastConfigStep(exportedConfigs);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(chalk.red(error.message));
|
console.error(chalk.red(error.message));
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
dist/
|
dist/
|
||||||
node_modules/
|
node_modules/
|
||||||
publish/
|
publish/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,7 +6,3 @@
|
|||||||
/dist
|
/dist
|
||||||
tsconfig.json
|
tsconfig.json
|
||||||
webpack.config.js
|
webpack.config.js
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,10 +23,18 @@ export default class JoplinContentScripts {
|
|||||||
* * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script)
|
* * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script)
|
||||||
* * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script)
|
* * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script)
|
||||||
*
|
*
|
||||||
|
* See also the [postMessage demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages)
|
||||||
|
*
|
||||||
* @param type Defines how the script will be used. See the type definition for more information about each supported type.
|
* @param type Defines how the script will be used. See the type definition for more information about each supported type.
|
||||||
* @param id A unique ID for the content script.
|
* @param id A unique ID for the content script.
|
||||||
* @param scriptPath Must be a path relative to the plugin main script. For example, if your file content_script.js is next to your index.ts file, you would set `scriptPath` to `"./content_script.js`.
|
* @param scriptPath Must be a path relative to the plugin main script. For example, if your file content_script.js is next to your index.ts file, you would set `scriptPath` to `"./content_script.js`.
|
||||||
*/
|
*/
|
||||||
register(type: ContentScriptType, id: string, scriptPath: string): Promise<void>;
|
register(type: ContentScriptType, id: string, scriptPath: string): Promise<void>;
|
||||||
onMessage(id: string, callback: any): Promise<void>;
|
/**
|
||||||
|
* Listens to a messages sent from the content script using postMessage().
|
||||||
|
* See {@link ContentScriptType} for more information as well as the
|
||||||
|
* [postMessage
|
||||||
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages)
|
||||||
|
*/
|
||||||
|
onMessage(contentScriptId: string, callback: any): Promise<void>;
|
||||||
}
|
}
|
||||||
|
@ -458,7 +458,7 @@ export enum ContentScriptType {
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* See {@link JoplinContentScript.onMessage} for more details, as well as
|
* See {@link JoplinContentScripts.onMessage} for more details, as well as
|
||||||
* the [postMessage
|
* the [postMessage
|
||||||
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
||||||
*
|
*
|
||||||
@ -557,7 +557,7 @@ export enum ContentScriptType {
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* See {@link JoplinContentScript.onMessage} for more details, as well as
|
* See {@link JoplinContentScripts.onMessage} for more details, as well as
|
||||||
* the [postMessage
|
* the [postMessage
|
||||||
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
||||||
*
|
*
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dist": "webpack",
|
"dist": "webpack --joplin-plugin-config buildMain && webpack --joplin-plugin-config buildExtraScripts && webpack --joplin-plugin-config createArchive",
|
||||||
"prepare": "npm run dist",
|
"prepare": "npm run dist",
|
||||||
"update": "npm install -g generator-joplin && yo joplin --update"
|
"update": "npm install -g generator-joplin && yo joplin --update"
|
||||||
},
|
},
|
||||||
@ -22,6 +22,7 @@
|
|||||||
"typescript": "^3.9.3",
|
"typescript": "^3.9.3",
|
||||||
"webpack": "^4.43.0",
|
"webpack": "^4.43.0",
|
||||||
"webpack-cli": "^3.3.11",
|
"webpack-cli": "^3.3.11",
|
||||||
"chalk": "^4.1.0"
|
"chalk": "^4.1.0",
|
||||||
|
"yargs": "^16.2.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -33,10 +33,6 @@ const manifest = readManifest(manifestPath);
|
|||||||
const pluginArchiveFilePath = path.resolve(publishDir, `${manifest.id}.jpl`);
|
const pluginArchiveFilePath = path.resolve(publishDir, `${manifest.id}.jpl`);
|
||||||
const pluginInfoFilePath = path.resolve(publishDir, `${manifest.id}.json`);
|
const pluginInfoFilePath = path.resolve(publishDir, `${manifest.id}.json`);
|
||||||
|
|
||||||
fs.removeSync(distDir);
|
|
||||||
fs.removeSync(publishDir);
|
|
||||||
fs.mkdirpSync(publishDir);
|
|
||||||
|
|
||||||
function validatePackageJson() {
|
function validatePackageJson() {
|
||||||
const content = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
const content = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
||||||
if (!content.name || content.name.indexOf('joplin-plugin-') !== 0) {
|
if (!content.name || content.name.indexOf('joplin-plugin-') !== 0) {
|
||||||
@ -109,6 +105,7 @@ function createPluginInfo(manifestPath, destPath, jplFilePath) {
|
|||||||
|
|
||||||
function onBuildCompleted() {
|
function onBuildCompleted() {
|
||||||
try {
|
try {
|
||||||
|
fs.removeSync(path.resolve(publishDir, 'index.js'));
|
||||||
createPluginArchive(distDir, pluginArchiveFilePath);
|
createPluginArchive(distDir, pluginArchiveFilePath);
|
||||||
createPluginInfo(manifestPath, pluginInfoFilePath, pluginArchiveFilePath);
|
createPluginInfo(manifestPath, pluginInfoFilePath, pluginArchiveFilePath);
|
||||||
validatePackageJson();
|
validatePackageJson();
|
||||||
@ -174,6 +171,16 @@ const extraScriptConfig = Object.assign({}, baseConfig, {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const createArchiveConfig = {
|
||||||
|
stats: 'errors-only',
|
||||||
|
entry: './dist/index.js',
|
||||||
|
output: {
|
||||||
|
filename: 'index.js',
|
||||||
|
path: publishDir,
|
||||||
|
},
|
||||||
|
plugins: [new WebpackOnBuildPlugin(onBuildCompleted)],
|
||||||
|
};
|
||||||
|
|
||||||
function resolveExtraScriptPath(name) {
|
function resolveExtraScriptPath(name) {
|
||||||
const relativePath = `./src/${name}`;
|
const relativePath = `./src/${name}`;
|
||||||
|
|
||||||
@ -196,8 +203,8 @@ function resolveExtraScriptPath(name) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function addExtraScriptConfigs(baseConfig, userConfig) {
|
function buildExtraScriptConfigs(userConfig) {
|
||||||
if (!userConfig.extraScripts.length) return baseConfig;
|
if (!userConfig.extraScripts.length) return [];
|
||||||
|
|
||||||
const output = [];
|
const output = [];
|
||||||
|
|
||||||
@ -209,22 +216,55 @@ function addExtraScriptConfigs(baseConfig, userConfig) {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
return baseConfig.concat(output);
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addLastConfigStep(config) {
|
function main(processArgv) {
|
||||||
const lastConfig = config[config.length - 1];
|
const yargs = require('yargs/yargs');
|
||||||
if (!lastConfig.plugins) lastConfig.plugins = [];
|
const argv = yargs(processArgv).argv;
|
||||||
lastConfig.plugins.push(new WebpackOnBuildPlugin(onBuildCompleted));
|
|
||||||
config[config.length - 1] = lastConfig;
|
const configName = argv['joplin-plugin-config'];
|
||||||
return config;
|
if (!configName) throw new Error('A config file must be specified via the --joplin-plugin-config flag');
|
||||||
|
|
||||||
|
// Webpack configurations run in parallel, while we need them to run in
|
||||||
|
// sequence, and to do that it seems the only way is to run webpack multiple
|
||||||
|
// times, with different config each time.
|
||||||
|
|
||||||
|
const configs = {
|
||||||
|
// Builds the main src/index.ts and copy the extra content from /src to
|
||||||
|
// /dist including scripts, CSS and any other asset.
|
||||||
|
buildMain: pluginConfig,
|
||||||
|
|
||||||
|
// Builds the extra scripts as defined in plugin.config.json. When doing
|
||||||
|
// so, some JavaScript files that were copied in the previous might be
|
||||||
|
// overwritten here by the compiled version. This is by design. The
|
||||||
|
// result is that JS files that don't need compilation, are simply
|
||||||
|
// copied to /dist, while those that do need it are correctly compiled.
|
||||||
|
buildExtraScripts: buildExtraScriptConfigs(userConfig),
|
||||||
|
|
||||||
|
// Ths config is for creating the .jpl, which is done via the plugin, so
|
||||||
|
// it doesn't actually need an entry and output, however webpack won't
|
||||||
|
// run without this. So we give it an entry that we know is going to
|
||||||
|
// exist and output in the publish dir. Then the plugin will delete this
|
||||||
|
// temporary file before packaging the plugin.
|
||||||
|
createArchive: createArchiveConfig,
|
||||||
|
};
|
||||||
|
|
||||||
|
// If we are running the first config step, we clean up and create the build
|
||||||
|
// directories.
|
||||||
|
if (configName === 'buildMain') {
|
||||||
|
fs.removeSync(distDir);
|
||||||
|
fs.removeSync(publishDir);
|
||||||
|
fs.mkdirpSync(publishDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
return configs[configName];
|
||||||
}
|
}
|
||||||
|
|
||||||
let exportedConfigs = [pluginConfig];
|
let exportedConfigs = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
exportedConfigs = addExtraScriptConfigs(exportedConfigs, userConfig);
|
exportedConfigs = main(process.argv);
|
||||||
exportedConfigs = addLastConfigStep(exportedConfigs);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(chalk.red(error.message));
|
console.error(chalk.red(error.message));
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
dist/
|
dist/
|
||||||
node_modules/
|
node_modules/
|
||||||
publish/
|
publish/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,7 +6,3 @@
|
|||||||
/dist
|
/dist
|
||||||
tsconfig.json
|
tsconfig.json
|
||||||
webpack.config.js
|
webpack.config.js
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,10 +23,18 @@ export default class JoplinContentScripts {
|
|||||||
* * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script)
|
* * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script)
|
||||||
* * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script)
|
* * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script)
|
||||||
*
|
*
|
||||||
|
* See also the [postMessage demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages)
|
||||||
|
*
|
||||||
* @param type Defines how the script will be used. See the type definition for more information about each supported type.
|
* @param type Defines how the script will be used. See the type definition for more information about each supported type.
|
||||||
* @param id A unique ID for the content script.
|
* @param id A unique ID for the content script.
|
||||||
* @param scriptPath Must be a path relative to the plugin main script. For example, if your file content_script.js is next to your index.ts file, you would set `scriptPath` to `"./content_script.js`.
|
* @param scriptPath Must be a path relative to the plugin main script. For example, if your file content_script.js is next to your index.ts file, you would set `scriptPath` to `"./content_script.js`.
|
||||||
*/
|
*/
|
||||||
register(type: ContentScriptType, id: string, scriptPath: string): Promise<void>;
|
register(type: ContentScriptType, id: string, scriptPath: string): Promise<void>;
|
||||||
onMessage(id: string, callback: any): Promise<void>;
|
/**
|
||||||
|
* Listens to a messages sent from the content script using postMessage().
|
||||||
|
* See {@link ContentScriptType} for more information as well as the
|
||||||
|
* [postMessage
|
||||||
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages)
|
||||||
|
*/
|
||||||
|
onMessage(contentScriptId: string, callback: any): Promise<void>;
|
||||||
}
|
}
|
||||||
|
@ -458,7 +458,7 @@ export enum ContentScriptType {
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* See {@link JoplinContentScript.onMessage} for more details, as well as
|
* See {@link JoplinContentScripts.onMessage} for more details, as well as
|
||||||
* the [postMessage
|
* the [postMessage
|
||||||
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
||||||
*
|
*
|
||||||
@ -557,7 +557,7 @@ export enum ContentScriptType {
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* See {@link JoplinContentScript.onMessage} for more details, as well as
|
* See {@link JoplinContentScripts.onMessage} for more details, as well as
|
||||||
* the [postMessage
|
* the [postMessage
|
||||||
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
||||||
*
|
*
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dist": "webpack",
|
"dist": "webpack --joplin-plugin-config buildMain && webpack --joplin-plugin-config buildExtraScripts && webpack --joplin-plugin-config createArchive",
|
||||||
"prepare": "npm run dist",
|
"prepare": "npm run dist",
|
||||||
"update": "npm install -g generator-joplin && yo joplin --update"
|
"update": "npm install -g generator-joplin && yo joplin --update"
|
||||||
},
|
},
|
||||||
@ -22,6 +22,7 @@
|
|||||||
"typescript": "^3.9.3",
|
"typescript": "^3.9.3",
|
||||||
"webpack": "^4.43.0",
|
"webpack": "^4.43.0",
|
||||||
"webpack-cli": "^3.3.11",
|
"webpack-cli": "^3.3.11",
|
||||||
"chalk": "^4.1.0"
|
"chalk": "^4.1.0",
|
||||||
|
"yargs": "^16.2.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -33,10 +33,6 @@ const manifest = readManifest(manifestPath);
|
|||||||
const pluginArchiveFilePath = path.resolve(publishDir, `${manifest.id}.jpl`);
|
const pluginArchiveFilePath = path.resolve(publishDir, `${manifest.id}.jpl`);
|
||||||
const pluginInfoFilePath = path.resolve(publishDir, `${manifest.id}.json`);
|
const pluginInfoFilePath = path.resolve(publishDir, `${manifest.id}.json`);
|
||||||
|
|
||||||
fs.removeSync(distDir);
|
|
||||||
fs.removeSync(publishDir);
|
|
||||||
fs.mkdirpSync(publishDir);
|
|
||||||
|
|
||||||
function validatePackageJson() {
|
function validatePackageJson() {
|
||||||
const content = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
const content = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
||||||
if (!content.name || content.name.indexOf('joplin-plugin-') !== 0) {
|
if (!content.name || content.name.indexOf('joplin-plugin-') !== 0) {
|
||||||
@ -109,6 +105,7 @@ function createPluginInfo(manifestPath, destPath, jplFilePath) {
|
|||||||
|
|
||||||
function onBuildCompleted() {
|
function onBuildCompleted() {
|
||||||
try {
|
try {
|
||||||
|
fs.removeSync(path.resolve(publishDir, 'index.js'));
|
||||||
createPluginArchive(distDir, pluginArchiveFilePath);
|
createPluginArchive(distDir, pluginArchiveFilePath);
|
||||||
createPluginInfo(manifestPath, pluginInfoFilePath, pluginArchiveFilePath);
|
createPluginInfo(manifestPath, pluginInfoFilePath, pluginArchiveFilePath);
|
||||||
validatePackageJson();
|
validatePackageJson();
|
||||||
@ -174,6 +171,16 @@ const extraScriptConfig = Object.assign({}, baseConfig, {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const createArchiveConfig = {
|
||||||
|
stats: 'errors-only',
|
||||||
|
entry: './dist/index.js',
|
||||||
|
output: {
|
||||||
|
filename: 'index.js',
|
||||||
|
path: publishDir,
|
||||||
|
},
|
||||||
|
plugins: [new WebpackOnBuildPlugin(onBuildCompleted)],
|
||||||
|
};
|
||||||
|
|
||||||
function resolveExtraScriptPath(name) {
|
function resolveExtraScriptPath(name) {
|
||||||
const relativePath = `./src/${name}`;
|
const relativePath = `./src/${name}`;
|
||||||
|
|
||||||
@ -196,8 +203,8 @@ function resolveExtraScriptPath(name) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function addExtraScriptConfigs(baseConfig, userConfig) {
|
function buildExtraScriptConfigs(userConfig) {
|
||||||
if (!userConfig.extraScripts.length) return baseConfig;
|
if (!userConfig.extraScripts.length) return [];
|
||||||
|
|
||||||
const output = [];
|
const output = [];
|
||||||
|
|
||||||
@ -209,22 +216,55 @@ function addExtraScriptConfigs(baseConfig, userConfig) {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
return baseConfig.concat(output);
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addLastConfigStep(config) {
|
function main(processArgv) {
|
||||||
const lastConfig = config[config.length - 1];
|
const yargs = require('yargs/yargs');
|
||||||
if (!lastConfig.plugins) lastConfig.plugins = [];
|
const argv = yargs(processArgv).argv;
|
||||||
lastConfig.plugins.push(new WebpackOnBuildPlugin(onBuildCompleted));
|
|
||||||
config[config.length - 1] = lastConfig;
|
const configName = argv['joplin-plugin-config'];
|
||||||
return config;
|
if (!configName) throw new Error('A config file must be specified via the --joplin-plugin-config flag');
|
||||||
|
|
||||||
|
// Webpack configurations run in parallel, while we need them to run in
|
||||||
|
// sequence, and to do that it seems the only way is to run webpack multiple
|
||||||
|
// times, with different config each time.
|
||||||
|
|
||||||
|
const configs = {
|
||||||
|
// Builds the main src/index.ts and copy the extra content from /src to
|
||||||
|
// /dist including scripts, CSS and any other asset.
|
||||||
|
buildMain: pluginConfig,
|
||||||
|
|
||||||
|
// Builds the extra scripts as defined in plugin.config.json. When doing
|
||||||
|
// so, some JavaScript files that were copied in the previous might be
|
||||||
|
// overwritten here by the compiled version. This is by design. The
|
||||||
|
// result is that JS files that don't need compilation, are simply
|
||||||
|
// copied to /dist, while those that do need it are correctly compiled.
|
||||||
|
buildExtraScripts: buildExtraScriptConfigs(userConfig),
|
||||||
|
|
||||||
|
// Ths config is for creating the .jpl, which is done via the plugin, so
|
||||||
|
// it doesn't actually need an entry and output, however webpack won't
|
||||||
|
// run without this. So we give it an entry that we know is going to
|
||||||
|
// exist and output in the publish dir. Then the plugin will delete this
|
||||||
|
// temporary file before packaging the plugin.
|
||||||
|
createArchive: createArchiveConfig,
|
||||||
|
};
|
||||||
|
|
||||||
|
// If we are running the first config step, we clean up and create the build
|
||||||
|
// directories.
|
||||||
|
if (configName === 'buildMain') {
|
||||||
|
fs.removeSync(distDir);
|
||||||
|
fs.removeSync(publishDir);
|
||||||
|
fs.mkdirpSync(publishDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
return configs[configName];
|
||||||
}
|
}
|
||||||
|
|
||||||
let exportedConfigs = [pluginConfig];
|
let exportedConfigs = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
exportedConfigs = addExtraScriptConfigs(exportedConfigs, userConfig);
|
exportedConfigs = main(process.argv);
|
||||||
exportedConfigs = addLastConfigStep(exportedConfigs);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(chalk.red(error.message));
|
console.error(chalk.red(error.message));
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
dist/
|
dist/
|
||||||
node_modules/
|
node_modules/
|
||||||
publish/
|
publish/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,7 +6,3 @@
|
|||||||
/dist
|
/dist
|
||||||
tsconfig.json
|
tsconfig.json
|
||||||
webpack.config.js
|
webpack.config.js
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,10 +23,18 @@ export default class JoplinContentScripts {
|
|||||||
* * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script)
|
* * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script)
|
||||||
* * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script)
|
* * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script)
|
||||||
*
|
*
|
||||||
|
* See also the [postMessage demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages)
|
||||||
|
*
|
||||||
* @param type Defines how the script will be used. See the type definition for more information about each supported type.
|
* @param type Defines how the script will be used. See the type definition for more information about each supported type.
|
||||||
* @param id A unique ID for the content script.
|
* @param id A unique ID for the content script.
|
||||||
* @param scriptPath Must be a path relative to the plugin main script. For example, if your file content_script.js is next to your index.ts file, you would set `scriptPath` to `"./content_script.js`.
|
* @param scriptPath Must be a path relative to the plugin main script. For example, if your file content_script.js is next to your index.ts file, you would set `scriptPath` to `"./content_script.js`.
|
||||||
*/
|
*/
|
||||||
register(type: ContentScriptType, id: string, scriptPath: string): Promise<void>;
|
register(type: ContentScriptType, id: string, scriptPath: string): Promise<void>;
|
||||||
onMessage(id: string, callback: any): Promise<void>;
|
/**
|
||||||
|
* Listens to a messages sent from the content script using postMessage().
|
||||||
|
* See {@link ContentScriptType} for more information as well as the
|
||||||
|
* [postMessage
|
||||||
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages)
|
||||||
|
*/
|
||||||
|
onMessage(contentScriptId: string, callback: any): Promise<void>;
|
||||||
}
|
}
|
||||||
|
@ -458,7 +458,7 @@ export enum ContentScriptType {
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* See {@link JoplinContentScript.onMessage} for more details, as well as
|
* See {@link JoplinContentScripts.onMessage} for more details, as well as
|
||||||
* the [postMessage
|
* the [postMessage
|
||||||
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
||||||
*
|
*
|
||||||
@ -557,7 +557,7 @@ export enum ContentScriptType {
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* See {@link JoplinContentScript.onMessage} for more details, as well as
|
* See {@link JoplinContentScripts.onMessage} for more details, as well as
|
||||||
* the [postMessage
|
* the [postMessage
|
||||||
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
||||||
*
|
*
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dist": "webpack",
|
"dist": "webpack --joplin-plugin-config buildMain && webpack --joplin-plugin-config buildExtraScripts && webpack --joplin-plugin-config createArchive",
|
||||||
"prepare": "npm run dist",
|
"prepare": "npm run dist",
|
||||||
"update": "npm install -g generator-joplin && yo joplin --update"
|
"update": "npm install -g generator-joplin && yo joplin --update"
|
||||||
},
|
},
|
||||||
@ -22,6 +22,7 @@
|
|||||||
"typescript": "^3.9.3",
|
"typescript": "^3.9.3",
|
||||||
"webpack": "^4.43.0",
|
"webpack": "^4.43.0",
|
||||||
"webpack-cli": "^3.3.11",
|
"webpack-cli": "^3.3.11",
|
||||||
"chalk": "^4.1.0"
|
"chalk": "^4.1.0",
|
||||||
|
"yargs": "^16.2.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -33,10 +33,6 @@ const manifest = readManifest(manifestPath);
|
|||||||
const pluginArchiveFilePath = path.resolve(publishDir, `${manifest.id}.jpl`);
|
const pluginArchiveFilePath = path.resolve(publishDir, `${manifest.id}.jpl`);
|
||||||
const pluginInfoFilePath = path.resolve(publishDir, `${manifest.id}.json`);
|
const pluginInfoFilePath = path.resolve(publishDir, `${manifest.id}.json`);
|
||||||
|
|
||||||
fs.removeSync(distDir);
|
|
||||||
fs.removeSync(publishDir);
|
|
||||||
fs.mkdirpSync(publishDir);
|
|
||||||
|
|
||||||
function validatePackageJson() {
|
function validatePackageJson() {
|
||||||
const content = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
const content = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
||||||
if (!content.name || content.name.indexOf('joplin-plugin-') !== 0) {
|
if (!content.name || content.name.indexOf('joplin-plugin-') !== 0) {
|
||||||
@ -109,6 +105,7 @@ function createPluginInfo(manifestPath, destPath, jplFilePath) {
|
|||||||
|
|
||||||
function onBuildCompleted() {
|
function onBuildCompleted() {
|
||||||
try {
|
try {
|
||||||
|
fs.removeSync(path.resolve(publishDir, 'index.js'));
|
||||||
createPluginArchive(distDir, pluginArchiveFilePath);
|
createPluginArchive(distDir, pluginArchiveFilePath);
|
||||||
createPluginInfo(manifestPath, pluginInfoFilePath, pluginArchiveFilePath);
|
createPluginInfo(manifestPath, pluginInfoFilePath, pluginArchiveFilePath);
|
||||||
validatePackageJson();
|
validatePackageJson();
|
||||||
@ -174,6 +171,16 @@ const extraScriptConfig = Object.assign({}, baseConfig, {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const createArchiveConfig = {
|
||||||
|
stats: 'errors-only',
|
||||||
|
entry: './dist/index.js',
|
||||||
|
output: {
|
||||||
|
filename: 'index.js',
|
||||||
|
path: publishDir,
|
||||||
|
},
|
||||||
|
plugins: [new WebpackOnBuildPlugin(onBuildCompleted)],
|
||||||
|
};
|
||||||
|
|
||||||
function resolveExtraScriptPath(name) {
|
function resolveExtraScriptPath(name) {
|
||||||
const relativePath = `./src/${name}`;
|
const relativePath = `./src/${name}`;
|
||||||
|
|
||||||
@ -196,8 +203,8 @@ function resolveExtraScriptPath(name) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function addExtraScriptConfigs(baseConfig, userConfig) {
|
function buildExtraScriptConfigs(userConfig) {
|
||||||
if (!userConfig.extraScripts.length) return baseConfig;
|
if (!userConfig.extraScripts.length) return [];
|
||||||
|
|
||||||
const output = [];
|
const output = [];
|
||||||
|
|
||||||
@ -209,22 +216,55 @@ function addExtraScriptConfigs(baseConfig, userConfig) {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
return baseConfig.concat(output);
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addLastConfigStep(config) {
|
function main(processArgv) {
|
||||||
const lastConfig = config[config.length - 1];
|
const yargs = require('yargs/yargs');
|
||||||
if (!lastConfig.plugins) lastConfig.plugins = [];
|
const argv = yargs(processArgv).argv;
|
||||||
lastConfig.plugins.push(new WebpackOnBuildPlugin(onBuildCompleted));
|
|
||||||
config[config.length - 1] = lastConfig;
|
const configName = argv['joplin-plugin-config'];
|
||||||
return config;
|
if (!configName) throw new Error('A config file must be specified via the --joplin-plugin-config flag');
|
||||||
|
|
||||||
|
// Webpack configurations run in parallel, while we need them to run in
|
||||||
|
// sequence, and to do that it seems the only way is to run webpack multiple
|
||||||
|
// times, with different config each time.
|
||||||
|
|
||||||
|
const configs = {
|
||||||
|
// Builds the main src/index.ts and copy the extra content from /src to
|
||||||
|
// /dist including scripts, CSS and any other asset.
|
||||||
|
buildMain: pluginConfig,
|
||||||
|
|
||||||
|
// Builds the extra scripts as defined in plugin.config.json. When doing
|
||||||
|
// so, some JavaScript files that were copied in the previous might be
|
||||||
|
// overwritten here by the compiled version. This is by design. The
|
||||||
|
// result is that JS files that don't need compilation, are simply
|
||||||
|
// copied to /dist, while those that do need it are correctly compiled.
|
||||||
|
buildExtraScripts: buildExtraScriptConfigs(userConfig),
|
||||||
|
|
||||||
|
// Ths config is for creating the .jpl, which is done via the plugin, so
|
||||||
|
// it doesn't actually need an entry and output, however webpack won't
|
||||||
|
// run without this. So we give it an entry that we know is going to
|
||||||
|
// exist and output in the publish dir. Then the plugin will delete this
|
||||||
|
// temporary file before packaging the plugin.
|
||||||
|
createArchive: createArchiveConfig,
|
||||||
|
};
|
||||||
|
|
||||||
|
// If we are running the first config step, we clean up and create the build
|
||||||
|
// directories.
|
||||||
|
if (configName === 'buildMain') {
|
||||||
|
fs.removeSync(distDir);
|
||||||
|
fs.removeSync(publishDir);
|
||||||
|
fs.mkdirpSync(publishDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
return configs[configName];
|
||||||
}
|
}
|
||||||
|
|
||||||
let exportedConfigs = [pluginConfig];
|
let exportedConfigs = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
exportedConfigs = addExtraScriptConfigs(exportedConfigs, userConfig);
|
exportedConfigs = main(process.argv);
|
||||||
exportedConfigs = addLastConfigStep(exportedConfigs);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(chalk.red(error.message));
|
console.error(chalk.red(error.message));
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
dist/
|
dist/
|
||||||
node_modules/
|
node_modules/
|
||||||
publish/
|
publish/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,7 +6,3 @@
|
|||||||
/dist
|
/dist
|
||||||
tsconfig.json
|
tsconfig.json
|
||||||
webpack.config.js
|
webpack.config.js
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,10 +23,18 @@ export default class JoplinContentScripts {
|
|||||||
* * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script)
|
* * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script)
|
||||||
* * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script)
|
* * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script)
|
||||||
*
|
*
|
||||||
|
* See also the [postMessage demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages)
|
||||||
|
*
|
||||||
* @param type Defines how the script will be used. See the type definition for more information about each supported type.
|
* @param type Defines how the script will be used. See the type definition for more information about each supported type.
|
||||||
* @param id A unique ID for the content script.
|
* @param id A unique ID for the content script.
|
||||||
* @param scriptPath Must be a path relative to the plugin main script. For example, if your file content_script.js is next to your index.ts file, you would set `scriptPath` to `"./content_script.js`.
|
* @param scriptPath Must be a path relative to the plugin main script. For example, if your file content_script.js is next to your index.ts file, you would set `scriptPath` to `"./content_script.js`.
|
||||||
*/
|
*/
|
||||||
register(type: ContentScriptType, id: string, scriptPath: string): Promise<void>;
|
register(type: ContentScriptType, id: string, scriptPath: string): Promise<void>;
|
||||||
onMessage(id: string, callback: any): Promise<void>;
|
/**
|
||||||
|
* Listens to a messages sent from the content script using postMessage().
|
||||||
|
* See {@link ContentScriptType} for more information as well as the
|
||||||
|
* [postMessage
|
||||||
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages)
|
||||||
|
*/
|
||||||
|
onMessage(contentScriptId: string, callback: any): Promise<void>;
|
||||||
}
|
}
|
||||||
|
@ -458,7 +458,7 @@ export enum ContentScriptType {
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* See {@link JoplinContentScript.onMessage} for more details, as well as
|
* See {@link JoplinContentScripts.onMessage} for more details, as well as
|
||||||
* the [postMessage
|
* the [postMessage
|
||||||
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
||||||
*
|
*
|
||||||
@ -557,7 +557,7 @@ export enum ContentScriptType {
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* See {@link JoplinContentScript.onMessage} for more details, as well as
|
* See {@link JoplinContentScripts.onMessage} for more details, as well as
|
||||||
* the [postMessage
|
* the [postMessage
|
||||||
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
||||||
*
|
*
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dist": "webpack",
|
"dist": "webpack --joplin-plugin-config buildMain && webpack --joplin-plugin-config buildExtraScripts && webpack --joplin-plugin-config createArchive",
|
||||||
"prepare": "npm run dist",
|
"prepare": "npm run dist",
|
||||||
"update": "npm install -g generator-joplin && yo joplin --update"
|
"update": "npm install -g generator-joplin && yo joplin --update"
|
||||||
},
|
},
|
||||||
@ -22,9 +22,10 @@
|
|||||||
"typescript": "^3.9.3",
|
"typescript": "^3.9.3",
|
||||||
"webpack": "^4.43.0",
|
"webpack": "^4.43.0",
|
||||||
"webpack-cli": "^3.3.11",
|
"webpack-cli": "^3.3.11",
|
||||||
"chalk": "^4.1.0"
|
"chalk": "^4.1.0",
|
||||||
|
"yargs": "^16.2.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"uslug": "^1.0.4"
|
"uslug": "^1.0.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -33,10 +33,6 @@ const manifest = readManifest(manifestPath);
|
|||||||
const pluginArchiveFilePath = path.resolve(publishDir, `${manifest.id}.jpl`);
|
const pluginArchiveFilePath = path.resolve(publishDir, `${manifest.id}.jpl`);
|
||||||
const pluginInfoFilePath = path.resolve(publishDir, `${manifest.id}.json`);
|
const pluginInfoFilePath = path.resolve(publishDir, `${manifest.id}.json`);
|
||||||
|
|
||||||
fs.removeSync(distDir);
|
|
||||||
fs.removeSync(publishDir);
|
|
||||||
fs.mkdirpSync(publishDir);
|
|
||||||
|
|
||||||
function validatePackageJson() {
|
function validatePackageJson() {
|
||||||
const content = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
const content = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
||||||
if (!content.name || content.name.indexOf('joplin-plugin-') !== 0) {
|
if (!content.name || content.name.indexOf('joplin-plugin-') !== 0) {
|
||||||
@ -109,6 +105,7 @@ function createPluginInfo(manifestPath, destPath, jplFilePath) {
|
|||||||
|
|
||||||
function onBuildCompleted() {
|
function onBuildCompleted() {
|
||||||
try {
|
try {
|
||||||
|
fs.removeSync(path.resolve(publishDir, 'index.js'));
|
||||||
createPluginArchive(distDir, pluginArchiveFilePath);
|
createPluginArchive(distDir, pluginArchiveFilePath);
|
||||||
createPluginInfo(manifestPath, pluginInfoFilePath, pluginArchiveFilePath);
|
createPluginInfo(manifestPath, pluginInfoFilePath, pluginArchiveFilePath);
|
||||||
validatePackageJson();
|
validatePackageJson();
|
||||||
@ -174,6 +171,16 @@ const extraScriptConfig = Object.assign({}, baseConfig, {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const createArchiveConfig = {
|
||||||
|
stats: 'errors-only',
|
||||||
|
entry: './dist/index.js',
|
||||||
|
output: {
|
||||||
|
filename: 'index.js',
|
||||||
|
path: publishDir,
|
||||||
|
},
|
||||||
|
plugins: [new WebpackOnBuildPlugin(onBuildCompleted)],
|
||||||
|
};
|
||||||
|
|
||||||
function resolveExtraScriptPath(name) {
|
function resolveExtraScriptPath(name) {
|
||||||
const relativePath = `./src/${name}`;
|
const relativePath = `./src/${name}`;
|
||||||
|
|
||||||
@ -196,8 +203,8 @@ function resolveExtraScriptPath(name) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function addExtraScriptConfigs(baseConfig, userConfig) {
|
function buildExtraScriptConfigs(userConfig) {
|
||||||
if (!userConfig.extraScripts.length) return baseConfig;
|
if (!userConfig.extraScripts.length) return [];
|
||||||
|
|
||||||
const output = [];
|
const output = [];
|
||||||
|
|
||||||
@ -209,22 +216,55 @@ function addExtraScriptConfigs(baseConfig, userConfig) {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
return baseConfig.concat(output);
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addLastConfigStep(config) {
|
function main(processArgv) {
|
||||||
const lastConfig = config[config.length - 1];
|
const yargs = require('yargs/yargs');
|
||||||
if (!lastConfig.plugins) lastConfig.plugins = [];
|
const argv = yargs(processArgv).argv;
|
||||||
lastConfig.plugins.push(new WebpackOnBuildPlugin(onBuildCompleted));
|
|
||||||
config[config.length - 1] = lastConfig;
|
const configName = argv['joplin-plugin-config'];
|
||||||
return config;
|
if (!configName) throw new Error('A config file must be specified via the --joplin-plugin-config flag');
|
||||||
|
|
||||||
|
// Webpack configurations run in parallel, while we need them to run in
|
||||||
|
// sequence, and to do that it seems the only way is to run webpack multiple
|
||||||
|
// times, with different config each time.
|
||||||
|
|
||||||
|
const configs = {
|
||||||
|
// Builds the main src/index.ts and copy the extra content from /src to
|
||||||
|
// /dist including scripts, CSS and any other asset.
|
||||||
|
buildMain: pluginConfig,
|
||||||
|
|
||||||
|
// Builds the extra scripts as defined in plugin.config.json. When doing
|
||||||
|
// so, some JavaScript files that were copied in the previous might be
|
||||||
|
// overwritten here by the compiled version. This is by design. The
|
||||||
|
// result is that JS files that don't need compilation, are simply
|
||||||
|
// copied to /dist, while those that do need it are correctly compiled.
|
||||||
|
buildExtraScripts: buildExtraScriptConfigs(userConfig),
|
||||||
|
|
||||||
|
// Ths config is for creating the .jpl, which is done via the plugin, so
|
||||||
|
// it doesn't actually need an entry and output, however webpack won't
|
||||||
|
// run without this. So we give it an entry that we know is going to
|
||||||
|
// exist and output in the publish dir. Then the plugin will delete this
|
||||||
|
// temporary file before packaging the plugin.
|
||||||
|
createArchive: createArchiveConfig,
|
||||||
|
};
|
||||||
|
|
||||||
|
// If we are running the first config step, we clean up and create the build
|
||||||
|
// directories.
|
||||||
|
if (configName === 'buildMain') {
|
||||||
|
fs.removeSync(distDir);
|
||||||
|
fs.removeSync(publishDir);
|
||||||
|
fs.mkdirpSync(publishDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
return configs[configName];
|
||||||
}
|
}
|
||||||
|
|
||||||
let exportedConfigs = [pluginConfig];
|
let exportedConfigs = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
exportedConfigs = addExtraScriptConfigs(exportedConfigs, userConfig);
|
exportedConfigs = main(process.argv);
|
||||||
exportedConfigs = addLastConfigStep(exportedConfigs);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(chalk.red(error.message));
|
console.error(chalk.red(error.message));
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
dist/
|
dist/
|
||||||
node_modules/
|
node_modules/
|
||||||
publish/
|
publish/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,7 +6,3 @@
|
|||||||
/dist
|
/dist
|
||||||
tsconfig.json
|
tsconfig.json
|
||||||
webpack.config.js
|
webpack.config.js
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,10 +23,18 @@ export default class JoplinContentScripts {
|
|||||||
* * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script)
|
* * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script)
|
||||||
* * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script)
|
* * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script)
|
||||||
*
|
*
|
||||||
|
* See also the [postMessage demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages)
|
||||||
|
*
|
||||||
* @param type Defines how the script will be used. See the type definition for more information about each supported type.
|
* @param type Defines how the script will be used. See the type definition for more information about each supported type.
|
||||||
* @param id A unique ID for the content script.
|
* @param id A unique ID for the content script.
|
||||||
* @param scriptPath Must be a path relative to the plugin main script. For example, if your file content_script.js is next to your index.ts file, you would set `scriptPath` to `"./content_script.js`.
|
* @param scriptPath Must be a path relative to the plugin main script. For example, if your file content_script.js is next to your index.ts file, you would set `scriptPath` to `"./content_script.js`.
|
||||||
*/
|
*/
|
||||||
register(type: ContentScriptType, id: string, scriptPath: string): Promise<void>;
|
register(type: ContentScriptType, id: string, scriptPath: string): Promise<void>;
|
||||||
onMessage(id: string, callback: any): Promise<void>;
|
/**
|
||||||
|
* Listens to a messages sent from the content script using postMessage().
|
||||||
|
* See {@link ContentScriptType} for more information as well as the
|
||||||
|
* [postMessage
|
||||||
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages)
|
||||||
|
*/
|
||||||
|
onMessage(contentScriptId: string, callback: any): Promise<void>;
|
||||||
}
|
}
|
||||||
|
@ -458,7 +458,7 @@ export enum ContentScriptType {
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* See {@link JoplinContentScript.onMessage} for more details, as well as
|
* See {@link JoplinContentScripts.onMessage} for more details, as well as
|
||||||
* the [postMessage
|
* the [postMessage
|
||||||
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
||||||
*
|
*
|
||||||
@ -557,7 +557,7 @@ export enum ContentScriptType {
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* See {@link JoplinContentScript.onMessage} for more details, as well as
|
* See {@link JoplinContentScripts.onMessage} for more details, as well as
|
||||||
* the [postMessage
|
* the [postMessage
|
||||||
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
||||||
*
|
*
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dist": "webpack",
|
"dist": "webpack --joplin-plugin-config buildMain && webpack --joplin-plugin-config buildExtraScripts && webpack --joplin-plugin-config createArchive",
|
||||||
"prepare": "npm run dist",
|
"prepare": "npm run dist",
|
||||||
"update": "npm install -g generator-joplin && yo joplin --update"
|
"update": "npm install -g generator-joplin && yo joplin --update"
|
||||||
},
|
},
|
||||||
@ -22,7 +22,8 @@
|
|||||||
"typescript": "^3.9.3",
|
"typescript": "^3.9.3",
|
||||||
"webpack": "^4.43.0",
|
"webpack": "^4.43.0",
|
||||||
"webpack-cli": "^3.3.11",
|
"webpack-cli": "^3.3.11",
|
||||||
"chalk": "^4.1.0"
|
"chalk": "^4.1.0",
|
||||||
|
"yargs": "^16.2.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"left-pad": "^1.3.0"
|
"left-pad": "^1.3.0"
|
||||||
|
@ -33,10 +33,6 @@ const manifest = readManifest(manifestPath);
|
|||||||
const pluginArchiveFilePath = path.resolve(publishDir, `${manifest.id}.jpl`);
|
const pluginArchiveFilePath = path.resolve(publishDir, `${manifest.id}.jpl`);
|
||||||
const pluginInfoFilePath = path.resolve(publishDir, `${manifest.id}.json`);
|
const pluginInfoFilePath = path.resolve(publishDir, `${manifest.id}.json`);
|
||||||
|
|
||||||
fs.removeSync(distDir);
|
|
||||||
fs.removeSync(publishDir);
|
|
||||||
fs.mkdirpSync(publishDir);
|
|
||||||
|
|
||||||
function validatePackageJson() {
|
function validatePackageJson() {
|
||||||
const content = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
const content = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
||||||
if (!content.name || content.name.indexOf('joplin-plugin-') !== 0) {
|
if (!content.name || content.name.indexOf('joplin-plugin-') !== 0) {
|
||||||
@ -109,6 +105,7 @@ function createPluginInfo(manifestPath, destPath, jplFilePath) {
|
|||||||
|
|
||||||
function onBuildCompleted() {
|
function onBuildCompleted() {
|
||||||
try {
|
try {
|
||||||
|
fs.removeSync(path.resolve(publishDir, 'index.js'));
|
||||||
createPluginArchive(distDir, pluginArchiveFilePath);
|
createPluginArchive(distDir, pluginArchiveFilePath);
|
||||||
createPluginInfo(manifestPath, pluginInfoFilePath, pluginArchiveFilePath);
|
createPluginInfo(manifestPath, pluginInfoFilePath, pluginArchiveFilePath);
|
||||||
validatePackageJson();
|
validatePackageJson();
|
||||||
@ -174,6 +171,16 @@ const extraScriptConfig = Object.assign({}, baseConfig, {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const createArchiveConfig = {
|
||||||
|
stats: 'errors-only',
|
||||||
|
entry: './dist/index.js',
|
||||||
|
output: {
|
||||||
|
filename: 'index.js',
|
||||||
|
path: publishDir,
|
||||||
|
},
|
||||||
|
plugins: [new WebpackOnBuildPlugin(onBuildCompleted)],
|
||||||
|
};
|
||||||
|
|
||||||
function resolveExtraScriptPath(name) {
|
function resolveExtraScriptPath(name) {
|
||||||
const relativePath = `./src/${name}`;
|
const relativePath = `./src/${name}`;
|
||||||
|
|
||||||
@ -196,8 +203,8 @@ function resolveExtraScriptPath(name) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function addExtraScriptConfigs(baseConfig, userConfig) {
|
function buildExtraScriptConfigs(userConfig) {
|
||||||
if (!userConfig.extraScripts.length) return baseConfig;
|
if (!userConfig.extraScripts.length) return [];
|
||||||
|
|
||||||
const output = [];
|
const output = [];
|
||||||
|
|
||||||
@ -209,22 +216,55 @@ function addExtraScriptConfigs(baseConfig, userConfig) {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
return baseConfig.concat(output);
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addLastConfigStep(config) {
|
function main(processArgv) {
|
||||||
const lastConfig = config[config.length - 1];
|
const yargs = require('yargs/yargs');
|
||||||
if (!lastConfig.plugins) lastConfig.plugins = [];
|
const argv = yargs(processArgv).argv;
|
||||||
lastConfig.plugins.push(new WebpackOnBuildPlugin(onBuildCompleted));
|
|
||||||
config[config.length - 1] = lastConfig;
|
const configName = argv['joplin-plugin-config'];
|
||||||
return config;
|
if (!configName) throw new Error('A config file must be specified via the --joplin-plugin-config flag');
|
||||||
|
|
||||||
|
// Webpack configurations run in parallel, while we need them to run in
|
||||||
|
// sequence, and to do that it seems the only way is to run webpack multiple
|
||||||
|
// times, with different config each time.
|
||||||
|
|
||||||
|
const configs = {
|
||||||
|
// Builds the main src/index.ts and copy the extra content from /src to
|
||||||
|
// /dist including scripts, CSS and any other asset.
|
||||||
|
buildMain: pluginConfig,
|
||||||
|
|
||||||
|
// Builds the extra scripts as defined in plugin.config.json. When doing
|
||||||
|
// so, some JavaScript files that were copied in the previous might be
|
||||||
|
// overwritten here by the compiled version. This is by design. The
|
||||||
|
// result is that JS files that don't need compilation, are simply
|
||||||
|
// copied to /dist, while those that do need it are correctly compiled.
|
||||||
|
buildExtraScripts: buildExtraScriptConfigs(userConfig),
|
||||||
|
|
||||||
|
// Ths config is for creating the .jpl, which is done via the plugin, so
|
||||||
|
// it doesn't actually need an entry and output, however webpack won't
|
||||||
|
// run without this. So we give it an entry that we know is going to
|
||||||
|
// exist and output in the publish dir. Then the plugin will delete this
|
||||||
|
// temporary file before packaging the plugin.
|
||||||
|
createArchive: createArchiveConfig,
|
||||||
|
};
|
||||||
|
|
||||||
|
// If we are running the first config step, we clean up and create the build
|
||||||
|
// directories.
|
||||||
|
if (configName === 'buildMain') {
|
||||||
|
fs.removeSync(distDir);
|
||||||
|
fs.removeSync(publishDir);
|
||||||
|
fs.mkdirpSync(publishDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
return configs[configName];
|
||||||
}
|
}
|
||||||
|
|
||||||
let exportedConfigs = [pluginConfig];
|
let exportedConfigs = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
exportedConfigs = addExtraScriptConfigs(exportedConfigs, userConfig);
|
exportedConfigs = main(process.argv);
|
||||||
exportedConfigs = addLastConfigStep(exportedConfigs);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(chalk.red(error.message));
|
console.error(chalk.red(error.message));
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
@ -23,10 +23,18 @@ export default class JoplinContentScripts {
|
|||||||
* * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script)
|
* * [View the renderer demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script)
|
||||||
* * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script)
|
* * [View the editor demo plugin](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script)
|
||||||
*
|
*
|
||||||
|
* See also the [postMessage demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages)
|
||||||
|
*
|
||||||
* @param type Defines how the script will be used. See the type definition for more information about each supported type.
|
* @param type Defines how the script will be used. See the type definition for more information about each supported type.
|
||||||
* @param id A unique ID for the content script.
|
* @param id A unique ID for the content script.
|
||||||
* @param scriptPath Must be a path relative to the plugin main script. For example, if your file content_script.js is next to your index.ts file, you would set `scriptPath` to `"./content_script.js`.
|
* @param scriptPath Must be a path relative to the plugin main script. For example, if your file content_script.js is next to your index.ts file, you would set `scriptPath` to `"./content_script.js`.
|
||||||
*/
|
*/
|
||||||
register(type: ContentScriptType, id: string, scriptPath: string): Promise<void>;
|
register(type: ContentScriptType, id: string, scriptPath: string): Promise<void>;
|
||||||
onMessage(id: string, callback: any): Promise<void>;
|
/**
|
||||||
|
* Listens to a messages sent from the content script using postMessage().
|
||||||
|
* See {@link ContentScriptType} for more information as well as the
|
||||||
|
* [postMessage
|
||||||
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages)
|
||||||
|
*/
|
||||||
|
onMessage(contentScriptId: string, callback: any): Promise<void>;
|
||||||
}
|
}
|
||||||
|
@ -458,7 +458,7 @@ export enum ContentScriptType {
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* See {@link JoplinContentScript.onMessage} for more details, as well as
|
* See {@link JoplinContentScripts.onMessage} for more details, as well as
|
||||||
* the [postMessage
|
* the [postMessage
|
||||||
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
||||||
*
|
*
|
||||||
@ -557,7 +557,7 @@ export enum ContentScriptType {
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* See {@link JoplinContentScript.onMessage} for more details, as well as
|
* See {@link JoplinContentScripts.onMessage} for more details, as well as
|
||||||
* the [postMessage
|
* the [postMessage
|
||||||
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages).
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user