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,GAA+B,MAAxB,EAAS,WAIjB,EAAO,GAHP,EAAQ,EAAE,OAId,GACF,GAEV,CACA,mBAAA,CAAoB,GAChB,MAAM,EAAc,qBACpB,IAAI,GAAQ,EAEZ,MAAM,EAAe,KAAK,SAAS,KAAK,QAAQ,GAAc,KAAK,QAAQ,IAErE,EAAY,aAAe,KAAK,KAAK,EAAc,KAAK,SAAS,IAAgB,QAAQ,MAAO,KAAO,QACvG,EAAc,IAAI,OAAO,EAAW,KAC1C,IAAI,EAAU,GAAG,aAAa,EAAa,QACtC,EAAY,KAAK,KAClB,GAAW,4BAA+B,KAAK,KAAK,EAAc,KAAK,SAAS,IAAgB,QAAQ,MAAO,KAAO,OACtH,GAAQ,GAER,GACA,GAAG,cAAc,EAAa,EAEtC,GAEJ,WAAW,CACP,YAAY,QACb,SAAS,UAAW,MAAO,MAC9B,WAAW,CACP,YAAY,QACb,SAAS,UAAW,SAAU,MACjC,WAAW,CACP,YAAY,QACb,SAAS,UAAW,YAAa,MACpC,WAAW,CACP,YAAY,QACb,SAAS,UAAW,SAAU,MACjC,WAAW,CACP,YAAY,UAAK,EAAW,CAAC,SAAU,YACxC,SAAS,UAAW,QAAS,MAChC,WAAW,CACP,YAAY,UAAK,EAAW,CAAC,WAC9B,SAAS,UAAW,OAAQ,MAC/B,WAAW,CACP,YAAY,QACb,SAAS,UAAW,OAAQ,MAC/B,WAAW,CACP,YAAY,gBACb,SAAS,UAAW,OAAQ,MAC/B,SAAW,WAAW,CAClB,YAAY,aACb,UACH,QAAQ,SAAW","file":"/npm/servicenow-dev-skeleton@2.1.4/dist/tasks.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.19.2.\n * Original file: /npm/servicenow-dev-skeleton@2.1.4/dist/tasks.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\r\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\r\n    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n    if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n    return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n};\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nconst chalk_1 = require(\"chalk\");\r\nconst dotenv = require(\"dotenv\");\r\nconst fs = require(\"fs\");\r\nconst gulp = require(\"gulp\");\r\nconst gulpts = require(\"gulp-typescript\");\r\nconst gulpclass_1 = require(\"gulpclass\");\r\nconst path = require(\"path\");\r\nconst request = require(\"request\");\r\nconst ts_simple_ast_1 = require(\"ts-simple-ast\");\r\nif (fs.existsSync(\".env\")) {\r\n    dotenv.config();\r\n}\r\nlet Gulpfile = class Gulpfile {\r\n    constructor() {\r\n        const path = require(\"path\");\r\n        const configPath = path.resolve(\"./servicenowconfig.js\");\r\n        this.config = require(configPath);\r\n        if (!this.config.src) {\r\n            throw \"servicenowconfig.js missing \\\"src\\\" path property\";\r\n        }\r\n        if (!this.config.out) {\r\n            throw \"servicenowconfig.js missing \\\"out\\\" path property\";\r\n        }\r\n        if (!this.config.tsconfig) {\r\n            throw \"servicenowconfig.js missing \\\"tsconfig\\\" path property\";\r\n        }\r\n    }\r\n    dts() {\r\n        return new Promise((resolve, reject) => {\r\n            if (!this.checkUserSettings()) {\r\n                reject(\"AUTHENTICATION NOT SET\");\r\n                return;\r\n            }\r\n            else {\r\n                const types = this.getAllTypes();\r\n                console.info(chalk_1.default.yellow(\"Requesting type info from SN for: \") + types);\r\n                this.invokeServiceNow(`${this.config.uri}/api/avana/dev_integration/schema`, \"POST\", { tables: types })\r\n                    .then(result => {\r\n                    this.writeDTS(this.config.dts.sndts, this.config.dts.refs, this.config.dts.ignoreFields, result);\r\n                    this.addReferenceToIndex(this.config.dts.sndts);\r\n                    resolve();\r\n                })\r\n                    .catch(reject);\r\n            }\r\n        });\r\n    }\r\n    format() {\r\n        const prettier = require(\"gulp-prettier\");\r\n        return gulp\r\n            .src(this.config.src + \"**/*.ts\")\r\n            .pipe(prettier({\r\n            parser: \"typescript\",\r\n            printWidth: 200,\r\n            tabWidth: 4\r\n        }))\r\n            .pipe(gulp.dest(this.config.src));\r\n    }\r\n    tslintfix() {\r\n        const tslint = require(\"tslint\");\r\n        const gulpTsLint = require(\"gulp-tslint\");\r\n        const program = tslint.Linter.createProgram(\"./tsconfig.json\");\r\n        const tslintOptions = {\r\n            configuration: \"./tslint.json\",\r\n            fix: true,\r\n            formatter: \"stylish\",\r\n            formattersDirectory: null,\r\n            program: program,\r\n            rulesDirectory: null,\r\n            tslint: tslint\r\n        };\r\n        return gulp\r\n            .src(this.config.src + \"**/*.ts\")\r\n            .pipe(gulpTsLint(tslintOptions))\r\n            .pipe(gulpTsLint.report({\r\n            allowWarnings: true\r\n        }));\r\n    }\r\n    tslint() {\r\n        const tslint = require(\"tslint\");\r\n        const gulpTsLint = require(\"gulp-tslint\");\r\n        const program = tslint.Linter.createProgram(\"./tsconfig.json\");\r\n        const tslintOptions = {\r\n            configuration: \"./tslint.json\",\r\n            fix: false,\r\n            formatter: \"stylish\",\r\n            formattersDirectory: null,\r\n            program: program,\r\n            rulesDirectory: null,\r\n            tslint: tslint\r\n        };\r\n        return gulp\r\n            .src(this.config.src + \"**/*.ts\")\r\n            .pipe(gulpTsLint(tslintOptions))\r\n            .pipe(gulpTsLint.report({\r\n            allowWarnings: true\r\n        }));\r\n    }\r\n    build() {\r\n        const tsProject = gulpts.createProject(this.config.tsconfig, {\r\n            typescript: require(\"typescript\")\r\n        });\r\n        if (tsProject.typescript)\r\n            console.log(\"Building with TypeScript compiler version \" + tsProject.typescript.version);\r\n        return gulp\r\n            .src(this.config.src + \"**/*.ts\")\r\n            .pipe(tsProject(gulpts.reporter.defaultReporter()))\r\n            .pipe(gulp.dest(this.config.out));\r\n    }\r\n    push() {\r\n        return this.pushToServiceNow();\r\n    }\r\n    pull() {\r\n        return this.pullFromServiceNow();\r\n    }\r\n    sync() {\r\n        return [\"pull\", \"dts\"];\r\n    }\r\n    pushToServiceNow() {\r\n        const upload = {};\r\n        const mappings = require(path.resolve(this.config.mapping));\r\n        Object.keys(mappings)\r\n            .forEach(id => {\r\n            const item = mappings[id];\r\n            if (!item || !item.fields) {\r\n                return;\r\n            }\r\n            const b = {\r\n                etag: item.etag,\r\n                fields: {},\r\n                id: id,\r\n                table: item.type\r\n            };\r\n            Object.keys(item.fields).forEach(key => {\r\n                let filePath = item.fields[key];\r\n                let ext = path.extname(filePath);\r\n                if (!fs.existsSync(filePath)) {\r\n                    if (ext === \".js\") {\r\n                        filePath = filePath.substring(0, filePath.length - ext.length) + \".ts\";\r\n                        ext = \".ts\";\r\n                        if (!fs.existsSync(filePath)) {\r\n                            throw \"Unable to find mapping with either a .js or .ts extension\" + filePath;\r\n                        }\r\n                    }\r\n                }\r\n                if (ext === \".ts\" && (filePath.indexOf(\".d.ts\") === -1)) {\r\n                    let distPath = filePath.replace(path.normalize(this.config.src), path.normalize(this.config.out));\r\n                    distPath = distPath.substring(0, distPath.length - ext.length) + \".js\";\r\n                    if (!fs.existsSync(distPath)) {\r\n                        throw \"Typescript output file was not found: \" + distPath;\r\n                    }\r\n                    b.fields[key] = fs.readFileSync(distPath, \"utf8\");\r\n                    b.fields[this.config.types[item.type][key].ts_field] = fs.readFileSync(filePath, \"utf8\");\r\n                }\r\n                else {\r\n                    b.fields[key] = fs.readFileSync(filePath, \"utf8\");\r\n                }\r\n            });\r\n            upload[id] = b;\r\n        });\r\n        const uri = `${this.config.uri}/api/avana/dev_integration/application/${this.config.application}/files`;\r\n        return this\r\n            .invokeServiceNow(uri, \"PUT\", upload)\r\n            .then(result => {\r\n            Object.keys(result).forEach(key => {\r\n                const item = result[key];\r\n                if (item.etag_outofdate) {\r\n                    console.warn(chalk_1.default.yellowBright(item.table + \"\\\\\" + item.name +\r\n                        \" is out of date! Use \" +\r\n                        chalk_1.default.white(\"gulp pull\") +\r\n                        \" to syncronize with server\"));\r\n                }\r\n                else if (item.updated) {\r\n                    console.info(item.table + \"\\\\\" + item.name + \" was updated\");\r\n                    mappings[key].etag = item.etag;\r\n                }\r\n            });\r\n            fs.writeFileSync(this.config.mapping, JSON.stringify(mappings, undefined, 3));\r\n        });\r\n    }\r\n    pullFromServiceNow() {\r\n        let mappings = {};\r\n        if (fs.existsSync(this.config.mapping)) {\r\n            mappings = require(path.resolve(this.config.mapping));\r\n        }\r\n        const body = {\r\n            files: Object.keys(this.config.types)\r\n        };\r\n        const uri = `${this.config.uri}/api/avana/dev_integration/application/${this.config.application}/files`;\r\n        return Promise.all([\r\n            this.invokeServiceNow(uri, \"POST\", body)\r\n                .then(r => this.writePullResult(r, mappings))\r\n                .then(m => {\r\n                fs.writeFileSync(this.config.mapping, JSON.stringify(m, undefined, 3));\r\n            }),\r\n            this.getApplicationRefs(this.config.application)\r\n        ]);\r\n    }\r\n    writePullResult(result, mappings) {\r\n        if (!mappings.hasOwnProperty(result.sys_app.id) || (mappings[result.sys_app.id].etag !== result.sys_app.etag)) {\r\n            console.log(\"Updating application typings file\");\r\n            mappings[this.config.application] = {\r\n                etag: result.sys_app.etag,\r\n                fields: {\r\n                    u_dts: this.config.dts.appdts,\r\n                    u_typings: \"typings.json\"\r\n                },\r\n                type: \"sys_app\"\r\n            };\r\n            fs.writeFileSync(\"typings.json\", result.sys_app.fields.u_typings);\r\n            fs.writeFileSync(this.config.dts.appdts, result.sys_app.fields.u_dts);\r\n            this.addReferenceToIndex(this.config.dts.appdts);\r\n            this.addReferenceToIndex(this.config.dts.sndts);\r\n        }\r\n        Object.keys(result.files)\r\n            .forEach(key => {\r\n            const typeFiles = result.files[key];\r\n            typeFiles.forEach(t => {\r\n                // Only update the file if the server version has changed from last sync\r\n                if (!mappings.hasOwnProperty(t.id) || (mappings.hasOwnProperty(t.id) && mappings[t.id].etag !== t.etag)) {\r\n                    console.log(\"Updated: \" + t.table + \"\\\\\" + t.name);\r\n                    const p = this.writeFile(t);\r\n                    if (p) {\r\n                        mappings[t.id] = {\r\n                            etag: t.etag,\r\n                            fields: p,\r\n                            type: t.table\r\n                        };\r\n                    }\r\n                }\r\n            });\r\n        });\r\n        return mappings;\r\n    }\r\n    getApplicationRefs(id) {\r\n        const uri = `${this.config.uri}/api/avana/dev_integration/application/${id}/dependencies`;\r\n        return this.invokeServiceNow(uri, \"GET\")\r\n            .then(result => {\r\n            Object.keys(result).forEach(key => {\r\n                const appref = result[key];\r\n                const dtsPath = \"typings/appdependencies/\" + appref.name + \"/index.d.ts\";\r\n                if (!fs.existsSync(dtsPath)) {\r\n                    this.mkdirpSync(path.dirname(dtsPath));\r\n                }\r\n                fs.writeFileSync(dtsPath, appref.dts);\r\n                this.addReferenceToIndex(dtsPath);\r\n            });\r\n        });\r\n    }\r\n    writeFile(appDataItem) {\r\n        const typeInfo = this.config.types[appDataItem.table];\r\n        const typePaths = {};\r\n        if (!typeInfo) {\r\n            return null;\r\n        }\r\n        const handleType = (fieldName, rootPath, fileName) => {\r\n            const prop = typeInfo[fieldName];\r\n            let content = appDataItem.fields[fieldName];\r\n            let ext = prop.type;\r\n            if (prop.ts_field && appDataItem.fields[prop.ts_field]) {\r\n                content = appDataItem.fields[prop.ts_field];\r\n                ext = \"ts\";\r\n            }\r\n            const filePath = path.join(rootPath, (fileName + \".\" + ext));\r\n            this.mkdirpSync(path.dirname(filePath));\r\n            fs.writeFileSync(filePath, content);\r\n            return filePath;\r\n        };\r\n        const fieldKeys = Object.keys(typeInfo);\r\n        if (fieldKeys.length === 1) {\r\n            const field = fieldKeys[0];\r\n            typePaths[field] = handleType(field, path.join(this.config.src, appDataItem.table), appDataItem.name);\r\n        }\r\n        else {\r\n            fieldKeys.forEach(key => {\r\n                typePaths[key] = handleType(key, path.join(this.config.src, appDataItem.table, appDataItem.name), key);\r\n            });\r\n        }\r\n        return typePaths;\r\n    }\r\n    mkdirpSync(dirpath) {\r\n        const dirPathNormed = path.normalize(dirpath);\r\n        const parts = dirPathNormed.split(path.sep);\r\n        for (let i = 1; i <= parts.length; i++) {\r\n            const p = path.join.apply(null, parts.slice(0, i));\r\n            if (!fs.existsSync(p)) {\r\n                fs.mkdirSync(p);\r\n            }\r\n        }\r\n    }\r\n    getAllTypes() {\r\n        let types = [];\r\n        const srcPath = this.config.src + \"**/*.ts\";\r\n        console.info(`loading types from ts files at ${srcPath}`);\r\n        const project = new ts_simple_ast_1.default({ compilerOptions: { removeComments: false } });\r\n        project.addExistingSourceFiles(srcPath);\r\n        project.getSourceFiles()\r\n            .forEach(file => {\r\n            // find all new expressions and see if they are gliderecord:  const foo = new GlideRecord('sometable');\r\n            const news = file.getDescendantsOfKind(ts_simple_ast_1.SyntaxKind.NewExpression);\r\n            news.forEach(n => {\r\n                const ext = n.getExpression();\r\n                const name = ext.getText();\r\n                if (name === \"GlideRecord\" || name === \"GlideRecordSecure\") {\r\n                    const args = n.getArguments();\r\n                    if (args.length > 0) {\r\n                        const atype = args[0].getType();\r\n                        let aname = atype.getText();\r\n                        if (aname.charAt(0) === \"\\\"\" || aname.charAt(0) === \"'\") {\r\n                            aname = aname.substr(1, aname.length - 2);\r\n                        }\r\n                        if (types.indexOf(aname) === -1 && aname !== \"string\") {\r\n                            types.push(aname);\r\n                        }\r\n                    }\r\n                }\r\n            });\r\n            // Find all dts comment defs: /**dts: tablename1,tablename2 */\r\n            // support multiline\r\n            const dtsregex = new RegExp(/dts:[\\s+]?([\\w,\\d\\s\\r\\n\\*]+)/gi);\r\n            const comments = file.getDescendantsOfKind(ts_simple_ast_1.SyntaxKind.JSDocComment);\r\n            comments.forEach(comment => {\r\n                const content = comment.getText().trim();\r\n                let match = dtsregex.exec(content);\r\n                while (match != null) {\r\n                    const matchtypes = match[1];\r\n                    const matches = matchtypes\r\n                        .trim()\r\n                        .replace(/[\\r\\n\\*]/g, \"\") // remove newline and * characters\r\n                        .split(\",\")\r\n                        .map(m => m.trim())\r\n                        .filter(m => types.indexOf(m) === -1);\r\n                    types = types.concat(matches);\r\n                    match = dtsregex.exec(content);\r\n                }\r\n            });\r\n        });\r\n        return types;\r\n    }\r\n    writeDTS(target, references, ignoreFields, definitions) {\r\n        let dts = references\r\n            .map(ref => `///<reference path=\"${ref}\" />`)\r\n            .join(\"\\r\\n\");\r\n        dts += \"\\r\\n\\r\\ndeclare module sn {\\r\\n\" +\r\n            \"\\texport module Server {\\r\\n\" +\r\n            \"\\t\\texport interface IGlideServerRecord {\\r\\n\";\r\n        const types = Object.keys(definitions).sort();\r\n        types.forEach(type => dts += `\\t\\t\\tnew (type: \"${type}\"): Types.I${type};\\r\\n`);\r\n        dts += \"\\t\\t}\\r\\n\"\r\n            + \"\\t}\\r\\n\"\r\n            + \"\\texport module Types {\\r\\n\";\r\n        types.forEach(type => {\r\n            const def = definitions[type];\r\n            const superclass = def.superclass ? \"I\" + def.superclass : \"Server.IGlideServerRecord\";\r\n            dts += `\\t\\texport interface I${type} extends ${superclass} {\\r\\n`;\r\n            const fields = Object.keys(def.fields).sort();\r\n            fields.forEach(fieldname => {\r\n                const fielddef = def.fields[fieldname];\r\n                if (ignoreFields.indexOf(fieldname) === -1\r\n                    && (!def.superclass\r\n                        || (definitions.hasOwnProperty(def.superclass)\r\n                            && !definitions[def.superclass].fields.hasOwnProperty(fieldname)))) {\r\n                    let type = fielddef.type;\r\n                    if (type.match(/IGlide/g)) {\r\n                        type = `string`;\r\n                    }\r\n                    dts += `\\t\\t\\t${fieldname}: sn.Server.IGlideElement & ${type}`;\r\n                    if (fielddef.reference && definitions.hasOwnProperty(fielddef.reference)) {\r\n                        dts += \" & I\" + fielddef.reference;\r\n                    }\r\n                    dts += \";\\r\\n\";\r\n                }\r\n            });\r\n            dts += \"\\t\\t}\\r\\n\";\r\n        });\r\n        dts += \"\\t}\\r\\n}\";\r\n        const targetdir = path.dirname(target);\r\n        if (!fs.existsSync(targetdir)) {\r\n            fs.mkdirSync(targetdir);\r\n        }\r\n        fs.writeFileSync(target, dts);\r\n        console.log(chalk_1.default.green(\"DTS saved to: \" + target));\r\n    }\r\n    checkUserSettings() {\r\n        if (!process.env.SN_USER || !process.env.SN_PASSWORD) {\r\n            if (!fs.existsSync(\"./.env\")) {\r\n                fs.writeFileSync(\"./.env\", \"SN_USER=\\r\\nSN_PASSWORD=\");\r\n            }\r\n            console.error(chalk_1.default.red(\"ERROR: SN_USER and/or SN_PASSWORD env constiables are not set! Please update your .env file with your ServiceNow basic auth credentials!\"));\r\n            return false;\r\n        }\r\n        return true;\r\n    }\r\n    invokeServiceNow(uri, method, body) {\r\n        return new Promise((resolve, reject) => {\r\n            request({\r\n                body: body,\r\n                headers: {\r\n                    \"Accept\": \"application/json\",\r\n                    \"Authorization\": \"Basic \" + (new Buffer(process.env.SN_USER + \":\" + process.env.SN_PASSWORD)).toString(\"base64\"),\r\n                    \"Content-Type\": \"application/json\"\r\n                },\r\n                json: true,\r\n                method: method,\r\n                url: uri\r\n            }, (err, response, b) => {\r\n                if (!err && response.statusCode === 200) {\r\n                    resolve(b.result);\r\n                }\r\n                else {\r\n                    reject(err);\r\n                }\r\n            });\r\n        });\r\n    }\r\n    addReferenceToIndex(referencePath) {\r\n        const pathToIndex = \"typings/index.d.ts\";\r\n        let write = false;\r\n        // Get the path relative to the index file\r\n        const relativePath = path.relative(path.dirname(pathToIndex), path.dirname(referencePath));\r\n        // Check if the path already exists\r\n        const regexPath = \"path=['\\\"]\" + path.join(relativePath, path.basename(referencePath)).replace(/\\\\/g, \"/\") + \"['\\\"]\";\r\n        const appdtsRegex = new RegExp(regexPath, \"g\");\r\n        let content = fs.readFileSync(pathToIndex, \"utf8\");\r\n        if (!appdtsRegex.test(content)) {\r\n            content += \"\\r\\n/// <reference path=\\\"\" + path.join(relativePath, path.basename(referencePath)).replace(/\\\\/g, \"/\") + \"\\\" />\";\r\n            write = true;\r\n        }\r\n        if (write) {\r\n            fs.writeFileSync(pathToIndex, content);\r\n        }\r\n    }\r\n};\r\n__decorate([\r\n    gulpclass_1.Task()\r\n], Gulpfile.prototype, \"dts\", null);\r\n__decorate([\r\n    gulpclass_1.Task()\r\n], Gulpfile.prototype, \"format\", null);\r\n__decorate([\r\n    gulpclass_1.Task()\r\n], Gulpfile.prototype, \"tslintfix\", null);\r\n__decorate([\r\n    gulpclass_1.Task()\r\n], Gulpfile.prototype, \"tslint\", null);\r\n__decorate([\r\n    gulpclass_1.Task(undefined, [\"tslint\", \"format\"])\r\n], Gulpfile.prototype, \"build\", null);\r\n__decorate([\r\n    gulpclass_1.Task(undefined, [\"build\"])\r\n], Gulpfile.prototype, \"push\", null);\r\n__decorate([\r\n    gulpclass_1.Task()\r\n], Gulpfile.prototype, \"pull\", null);\r\n__decorate([\r\n    gulpclass_1.SequenceTask()\r\n], Gulpfile.prototype, \"sync\", null);\r\nGulpfile = __decorate([\r\n    gulpclass_1.Gulpclass()\r\n], Gulpfile);\r\nexports.Gulpfile = Gulpfile;\r\n"]}