ngx-pesapal
Version:
Angular schematics lib for abstracting Pesapal APIs
32 lines • 1.6 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.ngAdd = void 0;
const schematics_1 = require("@angular-devkit/schematics");
const tasks_1 = require("@angular-devkit/schematics/tasks");
const ast_utils_1 = require("@schematics/angular/utility/ast-utils");
const change_1 = require("@schematics/angular/utility/change");
const ts = require("typescript");
function ngAdd(options) {
return (tree, context) => {
const appModulePath = 'src/app/app.module.ts';
const recorder = tree.beginUpdate(appModulePath);
const text = tree.read(appModulePath);
if (!tree.exists(appModulePath) || !text) {
throw new schematics_1.SchematicsException('File <app.module.ts> could not be found!');
}
if (!options.ipn_id) {
context.logger.warn('Ensure to add your IPN ID for the lib to work!!');
}
const s = ts.createSourceFile(appModulePath, text.toString(), ts.ScriptTarget.Latest, true);
const importModule = 'NgxPesapal';
const importPath = 'ngx-pesapal';
const importStatement = `${importModule}.forRoot('${options.consumer_key}','${options.consumer_secret}','${options.ipn_id}')`;
(0, change_1.applyToUpdateRecorder)(recorder, (0, ast_utils_1.addImportToModule)(s, appModulePath, importStatement, importPath));
tree.commitUpdate(recorder);
context.logger.info('Installing dependencies...');
context.addTask(new tasks_1.NodePackageInstallTask());
return tree;
};
}
exports.ngAdd = ngAdd;
//# sourceMappingURL=index.js.map
;