@rxap/plugin-web3-storage
Version:
This plugin provides an executor to deploy your application to web3 storage. It also includes a generator to initialize the plugin. It simplifies the process of deploying web applications to decentralized storage.
90 lines (89 loc) • 2.6 kB
JavaScript
import {
FindProjectByPath,
FsTree
} from "@rxap/workspace-utilities";
import { dirname } from "path";
import "colors";
function normalizeOptions(options) {
return options ?? {};
}
const createNodesV2 = [
"**/tsconfig.app.json",
async (configFilePaths, options, context) => {
const normalizedOptions = normalizeOptions(options);
const includedConfigFilePaths = await Promise.all(
configFilePaths.map(async (configFilePath) => {
if (await shouldHaveProjectConfiguration(
configFilePath,
normalizedOptions,
context
)) {
return configFilePath;
}
return void 0;
})
).then(
(configFilePathOrUndefinedList) => configFilePathOrUndefinedList.filter((value) => value !== void 0)
);
const results = await Promise.all(
includedConfigFilePaths.map(async (configFilePath) => {
const [projectPath, projectConfiguration] = await createProjectConfiguration(
configFilePath,
normalizedOptions,
context
);
return [configFilePath, projectPath, projectConfiguration];
})
);
return results.map(
([configFilePath, projectPath, projectConfiguration]) => [
configFilePath,
{
projects: {
[projectPath]: projectConfiguration
}
}
]
);
}
];
async function shouldHaveProjectConfiguration(configFilePath, options, context) {
const projectPath = dirname(configFilePath);
const tree = new FsTree(context.workspaceRoot);
const projectConfiguration = FindProjectByPath(tree, projectPath);
if (!projectConfiguration) {
return false;
}
if (["web3Storage", "web3storage", "web3-storage"].some((tag) => projectConfiguration.tags.includes(tag))) {
return false;
}
return true;
}
async function createProjectConfiguration(configFilePath, options, context) {
const projectPath = dirname(configFilePath);
const targets = {};
const tree = new FsTree(context.workspaceRoot);
const projectConfiguration = FindProjectByPath(tree, projectPath);
if (!projectConfiguration) {
throw new Error(`Could not find project in '${projectPath}'`);
}
targets["deploy"] = createDeployTarget();
return [
projectPath,
{
targets
}
];
}
function createDeployTarget() {
return {
executor: "@rxap/plugin-web3-storage:deploy",
outputs: ["{workspaceRoot}/dist/{projectRoot}/ipfs-cid.txt"],
dependsOn: ["build", "i18n-index-html"]
};
}
export {
createNodesV2,
normalizeOptions
};
//# sourceMappingURL=plugin.js.map