@gluestack-v2/glue-plugin-service-gateway
Version:
Gluestack V2 service Gateway Plugin
88 lines (87 loc) • 4.35 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports", "@gluestack-v2/framework-cli/build/plugin/BaseGluestackPluginInstance", "path", "@gluestack-v2/framework-cli/build/constants/gluestack.v2", "@gluestack-v2/framework-cli/build/helpers/file/write-file"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PluginInstance = void 0;
const BaseGluestackPluginInstance_1 = __importDefault(require("@gluestack-v2/framework-cli/build/plugin/BaseGluestackPluginInstance"));
const path_1 = require("path");
const gluestack_v2_1 = require("@gluestack-v2/framework-cli/build/constants/gluestack.v2");
const write_file_1 = __importDefault(require("@gluestack-v2/framework-cli/build/helpers/file/write-file"));
class PluginInstance extends BaseGluestackPluginInstance_1.default {
constructor(app, callerPlugin, name, gluePluginStore, installationPath) {
super(app, callerPlugin, name, gluePluginStore, installationPath);
}
init() {
//
}
destroy() {
//
}
getName() {
return this.name;
}
getCallerPlugin() {
return this.callerPlugin;
}
// getInstallationPath(): string {
// return this.installationPath;
// }
getSourcePath() {
return (0, path_1.join)(this.callerPlugin.getPackagePath(), 'template');
}
getGeneratedPath() {
return (0, path_1.join)(gluestack_v2_1.GLUE_GENERATED_SERVICES_PATH, this.getName(), 'src', this.getName());
}
getDestinationPath() {
return (0, path_1.join)(process.cwd(), this.getGeneratedPath());
}
build() {
return __awaiter(this, void 0, void 0, function* () {
yield this.app.write(this._sourcePath, this._destinationPath);
yield this.updateDestinationPackageJSON();
yield this.addServiceToWorkspaces((0, path_1.join)(this._workspacePath, this.getName()));
yield this.updateWorkspacePackageJSON();
yield this.boltInit();
yield this.generateEnvFiles();
});
}
//override updateWorkspacePackageJSON
updateWorkspacePackageJSON() {
return __awaiter(this, void 0, void 0, function* () {
// // add package.json with workspaces
const packageFile = (0, path_1.join)(this._workspacePath, 'package.json');
const packageContent = {
name: this.getName(),
private: true,
workspaces: [this.getName(), 'packages/**'],
scripts: {
'install:all': 'npm install --workspaces --if-present --legacy-peer-deps',
'build': 'npm run build --workspaces --if-present --legacy-peer-deps',
'dev': 'npm run dev --workspace @project/' + this.getName(),
},
};
yield (0, write_file_1.default)(packageFile, JSON.stringify(packageContent, null, 2));
});
}
}
exports.PluginInstance = PluginInstance;
});