@nx/gatsby
Version:
Gatsby Plugin for Nx
47 lines • 3.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.gatsbyInitSchematic = exports.gatsbyInitGenerator = void 0;
const tslib_1 = require("tslib");
const cypress_1 = require("@nx/cypress");
const devkit_1 = require("@nx/devkit");
const jest_1 = require("@nx/jest");
const react_1 = require("@nx/react");
const versions_1 = require("../../utils/versions");
const run_tasks_in_serial_1 = require("@nx/workspace/src/utilities/run-tasks-in-serial");
function updateDependencies(host) {
(0, devkit_1.updateJson)(host, 'package.json', (json) => {
if (json.dependencies && json.dependencies['@nx/gatsby']) {
delete json.dependencies['@nx/gatsby'];
}
return json;
});
const isPnpm = (0, devkit_1.detectPackageManager)(host.root) === 'pnpm';
return (0, devkit_1.addDependenciesToPackageJson)(host, Object.assign({ gatsby: versions_1.gatsbyVersion, 'gatsby-plugin-image': versions_1.gatsbyPluginImageVersion, 'gatsby-plugin-svgr': versions_1.gatsbyPluginSvgrVersion, 'gatsby-plugin-manifest': versions_1.gatsbyPluginManifestVersion, 'gatsby-plugin-offline': versions_1.gatsbyPluginOfflineVersion, 'gatsby-plugin-react-helmet': versions_1.gatsbyPluginReactHelmetVersion, 'gatsby-plugin-sharp': versions_1.gatsbyPluginSharpVersion, 'gatsby-source-filesystem': versions_1.gatsbySourceFilesystemVersion, 'gatsby-transformer-sharp': versions_1.gatsbyTransformerSharpVersion, 'prop-types': versions_1.propTypesVersion, react: react_1.reactVersion, 'react-dom': react_1.reactDomVersion, 'react-helmet': versions_1.reactHelmetVersion, 'gatsby-plugin-typescript': versions_1.gatsbyPluginTypescriptVersion }, (isPnpm ? { 'gatsby-plugin-pnpm': versions_1.gatsbyPluginPnpm } : {})), {
'@nx/gatsby': versions_1.nxVersion,
'@testing-library/react': versions_1.testingLibraryReactVersion,
'babel-plugin-module-resolver': versions_1.babelPluginModuleResolverVersion,
'babel-preset-gatsby': versions_1.babelPresetGatsbyVersion,
});
}
function gatsbyInitGenerator(host, schema) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const tasks = [];
if (!schema.unitTestRunner || schema.unitTestRunner === 'jest') {
const jestTask = yield (0, jest_1.jestInitGenerator)(host, {});
tasks.push(jestTask);
}
if (!schema.e2eTestRunner || schema.e2eTestRunner === 'cypress') {
const cypressTask = yield (0, cypress_1.cypressInitGenerator)(host, {});
tasks.push(cypressTask);
}
const reactTask = yield (0, react_1.reactInitGenerator)(host, schema);
tasks.push(reactTask);
const installTask = updateDependencies(host);
tasks.push(installTask);
return (0, run_tasks_in_serial_1.runTasksInSerial)(...tasks);
});
}
exports.gatsbyInitGenerator = gatsbyInitGenerator;
exports.default = gatsbyInitGenerator;
exports.gatsbyInitSchematic = (0, devkit_1.convertNxGenerator)(gatsbyInitGenerator);
//# sourceMappingURL=init.js.map