@naxodev/gonx
Version:
Modern Nx plugin to use Go in a Nx workspace
60 lines • 2.47 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isProjectUsingNxGo = exports.ensureGoConfigInSharedGlobals = exports.addNxPlugin = void 0;
const devkit_1 = require("@nx/devkit");
const constants_1 = require("../constants");
const go_bridge_1 = require("./go-bridge");
/**
* Adds the gonx plugin to the nx.json if it's not already there.
*
* @param tree project tree object
*/
const addNxPlugin = (tree) => {
var _a;
const nxJson = (0, devkit_1.readNxJson)(tree);
const hasPlugin = (_a = nxJson.plugins) === null || _a === void 0 ? void 0 : _a.some((plugin) => typeof plugin === 'object' && plugin.plugin === constants_1.NX_PLUGIN_NAME);
if (!hasPlugin) {
nxJson.plugins = [
...(nxJson.plugins || []),
{
plugin: '@naxodev/gonx',
options: {
buildTargetName: 'build',
serveTargetName: 'serve',
testTargetName: 'test',
lintTargetName: 'lint',
tidyTargetName: 'tidy',
},
},
];
(0, devkit_1.updateNxJson)(tree, nxJson);
}
};
exports.addNxPlugin = addNxPlugin;
/**
* Ensures that go configuration files are included as a sharedGlobal,
* so any changes will trigger projects to be flagged as affected.
*
* @param tree project tree object
*/
const ensureGoConfigInSharedGlobals = (tree) => {
var _a, _b;
const useWorkspace = (0, go_bridge_1.isGoWorkspace)(tree);
const toAdd = `{workspaceRoot}/${constants_1.GO_WORK_FILE}`;
const nxJson = (0, devkit_1.readNxJson)(tree);
const namedInputs = (_a = nxJson.namedInputs) !== null && _a !== void 0 ? _a : {};
const sharedGlobals = (_b = namedInputs['sharedGlobals']) !== null && _b !== void 0 ? _b : [];
if (!sharedGlobals.includes(toAdd) && useWorkspace) {
namedInputs.sharedGlobals = Array.from(new Set([...sharedGlobals, toAdd]));
(0, devkit_1.updateNxJson)(tree, { ...nxJson, namedInputs });
}
};
exports.ensureGoConfigInSharedGlobals = ensureGoConfigInSharedGlobals;
/**
* Checks if a Nx project is using the naxodev plugin.
*
* @param project project configuration object
*/
const isProjectUsingNxGo = (project) => Object.values(project.targets).some((target) => target.executor.includes(constants_1.NX_PLUGIN_NAME));
exports.isProjectUsingNxGo = isProjectUsingNxGo;
//# sourceMappingURL=nx-bridge.js.map