@naxodev/gonx
Version:
Modern Nx plugin to use Go in a Nx workspace
34 lines • 1.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.hasMainPackage = hasMainPackage;
const devkit_1 = require("@nx/devkit");
const fs_1 = require("fs");
const path_1 = require("path");
/**
* Determines if a Go module contains a main package,
* indicating it is an application rather than a library.
*
* @param projectRoot The root directory of the project
* @returns True if the project is an application, false otherwise
*/
function hasMainPackage(projectRoot) {
try {
// Check if main.go exists in the project root
const mainGoPath = (0, path_1.join)(devkit_1.workspaceRoot, projectRoot, 'main.go');
if ((0, fs_1.existsSync)(mainGoPath)) {
const content = (0, fs_1.readFileSync)(mainGoPath, 'utf-8');
return content.includes('package main') && content.includes('func main(');
}
// Check for cmd directory structure (common Go pattern)
const cmdDirPath = (0, path_1.join)(devkit_1.workspaceRoot, projectRoot, 'cmd');
if ((0, fs_1.existsSync)(cmdDirPath)) {
return true;
}
return false;
}
catch (error) {
// If there's any error, default to treating it as a library
return false;
}
}
//# sourceMappingURL=has-main-package.js.map