UNPKG

26 kBJavaScriptView Raw
1!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@angular-devkit/core"),require("typescript"),require("@angular-devkit/schematics"),require("path"),require("lodash"),require("@ibm-wch-sdk/utils"),require("assert"),require("email-validator"),require("valid-url"),require("rxjs/ajax"),require("rxjs/operators"),require("rxjs"),require("fs"),require("child_process"),require("constants"),require("crypto"),require("os"),require("process"),require("sshpk"),require("semver"),require("@ibm-wch-sdk/api"),require("verror"),require("request"),require("stream"),require("unzip"),require("cheerio")):"function"==typeof define&&define.amd?define("@ibm-wch-sdk/schematics-utils",["exports","@angular-devkit/core","typescript","@angular-devkit/schematics","path","lodash","@ibm-wch-sdk/utils","assert","email-validator","valid-url","rxjs/ajax","rxjs/operators","rxjs","fs","child_process","constants","crypto","os","process","sshpk","semver","@ibm-wch-sdk/api","verror","request","stream","unzip","cheerio"],r):r((e["ibm-wch-sdk"]=e["ibm-wch-sdk"]||{},e["ibm-wch-sdk"]["schematics-utils"]={}),e.core,e.ts,e.schematics,e.path,e.lodash,e.utils,e.Assert,e.emailValidator,e.validUrl,e.rxjs.ajax,e.rxjs.operators,e.rxjs,e.fs,e.child_process,e.constants,e.crypto,e.os,e.process$1,e.sshpk,e.semver,e.api,e.verror,e.request,e.stream,e.unzip,e.cheerio)}(this,function(e,u,v,d,c,i,s,t,r,o,n,l,f,a,p,h,m,g,x,y,w,S,E,b,k,N,T){"use strict";function j(e,r){for(var t=e.getDir("/"+r),n=/\.module\.ts$/,i=/-routing\.module\.ts/;t;){var o=t.subfiles.filter(function(e){return n.test(e)&&!i.test(e)});if(1==o.length)return u.join(t.path,o[0]);if(1<o.length)throw new Error("More than one module matches. Use skip-import option to skip importing the component into the closest module.");t=t.parent}throw new Error("Could not find an NgModule. Use the skip-import option to skip importing in NgModule.")}var P=function(e,r){return(P=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var t in r)r.hasOwnProperty(t)&&(e[t]=r[t])})(e,r)};var A=function(){return(A=Object.assign||function(e){for(var r,t=1,n=arguments.length;t<n;t++)for(var i in r=arguments[t])Object.prototype.hasOwnProperty.call(r,i)&&(e[i]=r[i]);return e}).apply(this,arguments)};function O(e){var r="function"==typeof Symbol&&e[Symbol.iterator],t=0;return r?r.call(e):{next:function(){return e&&t>=e.length&&(e=void 0),{value:e&&e[t++],done:!e}}}}function I(e,r){var t="function"==typeof Symbol&&e[Symbol.iterator];if(!t)return e;var n,i,o=t.call(e),a=[];try{for(;(void 0===r||0<r--)&&!(n=o.next()).done;)a.push(n.value)}catch(u){i={error:u}}finally{try{n&&!n.done&&(t=o["return"])&&t.call(o)}finally{if(i)throw i.error}}return a}function _(){for(var e=[],r=0;r<arguments.length;r++)e=e.concat(I(arguments[r]));return e}function C(e,r){return Object.defineProperty?Object.defineProperty(e,"raw",{value:r}):e.raw=r,e}var L=function(){function e(){this.description="No operation.",this.order=Infinity,this.path=null}return e.prototype.apply=function(){return Promise.resolve()},e}(),M=function(){function e(e,r,t){if(this.path=e,this.pos=r,this.toAdd=t,r<0)throw new Error("Negative positions are invalid");this.description="Inserted "+t+" into position "+r+" of "+e,this.order=r}return e.prototype.apply=function(n){var i=this;return n.read(this.path).then(function(e){var r=e.substring(0,i.pos),t=e.substring(i.pos);return n.write(i.path,""+r+i.toAdd+t)})},e}(),K=function(){function e(e,r,t){if(this.path=e,this.pos=r,this.toRemove=t,r<0)throw new Error("Negative positions are invalid");this.description="Removed "+t+" into position "+r+" of "+e,this.order=r}return e.prototype.apply=function(n){var i=this;return n.read(this.path).then(function(e){var r=e.substring(0,i.pos),t=e.substring(i.pos+i.toRemove.length);return n.write(i.path,""+r+t)})},e}(),R=function(){function e(e,r,t,n){if(this.path=e,this.pos=r,this.oldText=t,this.newText=n,r<0)throw new Error("Negative positions are invalid");this.description="Replaced "+t+" into position "+r+" of "+e+" with "+n,this.order=r}return e.prototype.apply=function(i){var o=this;return i.read(this.path).then(function(e){var r=e.substring(0,o.pos),t=e.substring(o.pos+o.oldText.length),n=e.substring(o.pos,o.pos+o.oldText.length);return n!==o.oldText?Promise.reject(new Error('Invalid replace: "'+n+'" != "'+o.oldText+'".')):i.write(o.path,""+r+o.newText+t)})},e}();function U(e,r,t,n,i){void 0===i&&(i=!1);var o=e,a=z(o,v.SyntaxKind.ImportDeclaration),u=a.filter(function(e){return 1===e.getChildren().filter(function(e){return e.kind===v.SyntaxKind.StringLiteral}).map(function(e){return e.text}).filter(function(e){return e===n}).length});if(0<u.length){var s=!1,c=[];if(u.forEach(function(e){Array.prototype.push.apply(c,z(e,v.SyntaxKind.Identifier)),0<z(e,v.SyntaxKind.AsteriskToken).length&&(s=!0)}),s)return new L;if(0!==c.filter(function(e){return e.text===t}).length)return new L;var l=z(u[0],v.SyntaxKind.CloseBraceToken)[0].getStart()||z(u[0],v.SyntaxKind.FromKeyword)[0].getStart();return V(c,", "+t,r,l)}var f=z(o,v.SyntaxKind.StringLiteral).filter(function(e){return"use strict"===e.text}),p=0;0<f.length&&(p=f[0].end);var d=i?"":"{ ",h=i?"":" }",m=0===a.length&&0===f.length;return V(a,(m?"":";\n")+"import "+d+t+h+" from '"+n+"'"+(m?";\n":""),r,p,v.SyntaxKind.StringLiteral)}function z(e,r,t){var n,i;if(void 0===t&&(t=Infinity),!e||0==t)return[];var o=[];if(e.kind===r&&(o.push(e),t--),0<t)try{for(var a=O(e.getChildren()),u=a.next();!u.done;u=a.next()){if(z(u.value,r,t).forEach(function(e){0<t&&o.push(e),t--}),t<=0)break}}catch(s){n={error:s}}finally{try{u&&!u.done&&(i=a["return"])&&i.call(a)}finally{if(n)throw n.error}}return o}function F(e){for(var r=[e],t=[];0<r.length;){var n=r.shift();n&&(t.push(n),0<=n.getChildCount(e)&&r.unshift.apply(r,_(n.getChildren())))}return t}function D(e,r,t){if(e.kind===r&&e.getText()===t)return e;var n=null;return v.forEachChild(e,function(e){n=n||D(e,r,t)}),n}function q(e,r){return e.getStart()-r.getStart()}function V(e,r,t,n,i){var o=_(e).sort(q).pop();if(!o)throw new Error;if(i&&(o=z(o,i).sort(q).pop()),!o&&n==undefined)throw new Error("tried to insert "+r+" as first occurence with no fallback position");var a=o?o.getEnd():n;return new M(t,a,r)}function J(i,o,a){var u=z(i,v.SyntaxKind.ImportDeclaration).map(function(e){return function a(e,r){var t,n,i=e.moduleSpecifier;switch(i.kind){case v.SyntaxKind.StringLiteral:n=i.text;break;default:return{}}if(!n.startsWith("@angular/"))return{};if(e.importClause){if(e.importClause.name)return{};if(e.importClause.namedBindings){var o=e.importClause.namedBindings;return o.kind==v.SyntaxKind.NamespaceImport?((t={})[o.name.text+"."]=n,t):o.elements.map(function(e){return e.propertyName?e.propertyName.text:e.name.text}).reduce(function(e,r){return e[r]=n,e},{})}return{}}return{}}(e)}).reduce(function(e,r){var t,n;try{for(var i=O(Object.keys(r)),o=i.next();!o.done;o=i.next()){var a=o.value;e[a]=r[a]}}catch(u){t={error:u}}finally{try{o&&!o.done&&(n=i["return"])&&n.call(i)}finally{if(t)throw t.error}}return e},{});return F(i).filter(function(e){return e.kind==v.SyntaxKind.Decorator&&e.expression.kind==v.SyntaxKind.CallExpression}).map(function(e){return e.expression}).filter(function(e){if(e.expression.kind==v.SyntaxKind.Identifier)return(t=e.expression).getFullText(i)==o&&u[t.getFullText(i)]===a;if(e.expression.kind!=v.SyntaxKind.PropertyAccessExpression)return!1;var r=e.expression;if(r.expression.kind!==v.SyntaxKind.Identifier)return!1;var t=r.name.text,n=r.expression.getText(i);return t===o&&u[n+"."]===a}).filter(function(e){return e.arguments[0]&&e.arguments[0].kind==v.SyntaxKind.ObjectLiteralExpression}).map(function(e){return e.arguments[0]})}function W(t,e,n,r,i){void 0===i&&(i=null);var o=J(t,"NgModule","@angular/core")[0];if(!o)return[];var a=o.properties.filter(function(e){return e.kind==v.SyntaxKind.PropertyAssignment}).filter(function(e){var r=e.name;switch(r.kind){case v.SyntaxKind.Identifier:return r.getText(t)==n;case v.SyntaxKind.StringLiteral:return r.text==n}return!1});if(!a)return[];if(0==a.length){var u=void 0,s=void 0;if(0==(d=o).properties.length)u=d.getEnd()-1,s=" "+n+": ["+r+"]\n";else{u=(o=d.properties[d.properties.length-1]).getEnd();var c=(m=o.getFullText(t)).match(/^\r?\n\s*/);s=0<c.length?","+c[0]+n+": ["+r+"]":", "+n+": ["+r+"]"}return null!==i?[new M(e,u,s),U(t,e,r.replace(/\..*$/,""),i)]:[new M(e,u,s)]}var l=a[0];if(l.initializer.kind!==v.SyntaxKind.ArrayLiteralExpression)return[];var f,p=l.initializer;if(!(o=0==p.elements.length?p:p.elements))return console.log("No app module found. Please add your new class to your component."),[];if(Array.isArray(o)){if(0<=o.map(function(e){return e.getText()}).indexOf(r))return[];o=o[o.length-1]}var d,h=o.getEnd();if(o.kind==v.SyntaxKind.ObjectLiteralExpression)f=0==(d=o).properties.length?(h=d.getEnd()-1," "+n+": ["+r+"]\n"):(h=(o=d.properties[d.properties.length-1]).getEnd(),(m=o.getFullText(t)).match("^\r?\r?\n")?","+m.match(/^\r?\n\s+/)[0]+n+": ["+r+"]":", "+n+": ["+r+"]");else if(o.kind==v.SyntaxKind.ArrayLiteralExpression)h--,f=""+r;else{var m;f=(m=o.getFullText(t)).match(/^\r?\n/)?","+m.match(/^\r?\n(\r?)\s+/)[0]+r:", "+r}return null!==i?[new M(e,h,f),U(t,e,r.replace(/\..*$/,""),i)]:[new M(e,h,f)]}function B(e,r,t,n){return W(e,r,"imports",t,n)}function H(r){return["/angular.json","/.angular.json"].filter(function(e){return r.exists(e)})[0]}var G="/.angular-cli.json";function Z(e,r){var t,n,i=e.read(r);if(!i)throw new d.SchematicsException("Main file ("+r+") not found");var o=i.toString("utf-8"),a=F(v.createSourceFile(r,o,v.ScriptTarget.Latest,!0)),u=null;try{for(var s=O(a),c=s.next();!c.done;c=s.next()){var l=c.value,f=null;for(f=D(l,v.SyntaxKind.Identifier,"bootstrapModule");f&&f.parent&&f.parent.kind!==v.SyntaxKind.CallExpression;)f=f.parent;if(null!==f&&f.parent!==undefined&&f.parent.kind===v.SyntaxKind.CallExpression){u=f.parent;break}}}catch(p){t={error:p}}finally{try{c&&!c.done&&(n=s["return"])&&n.call(s)}finally{if(t)throw t.error}}return u}function $(e,r){var t=Z(e,r);if(!t)throw new d.SchematicsException("Bootstrap call not found");var n=t.arguments[0],i=e.read(r);if(!i)throw new d.SchematicsException("Client app main file ("+r+") not found");var o=i.toString("utf-8");return F(v.createSourceFile(r,o,v.ScriptTarget.Latest,!0)).filter(function(e){return e.kind===v.SyntaxKind.ImportDeclaration}).filter(function(e){return D(e,v.SyntaxKind.Identifier,n.getText())}).map(function(e){return e.moduleSpecifier.text})[0]}var X,Y,Q,ee,re=/^[a-zA-Z][.0-9a-zA-Z]*(:?-[a-zA-Z][.0-9a-zA-Z]*)*$/;function te(e){return e.endsWith("/")?e:e+"/"}function ne(e){return!!(e&&i.isString(e)&&e.endsWith("/"))}function ie(e){return s.isString(e)&&!!o.isWebUri(e)}function oe(e){return s.isString(e)&&!!r.validate(e)}function ae(e){return s.isString(e)&&(!!r.validate(e)||"apikey"===e)}function ue(e){return t.ok(ie(e)&&ne(e),"URL [${aValue}] must end with a slash."),e}var se=new RegExp("^(?:\\/api)?\\/([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})(?:\\/)?(?:.*)$"),ce=function(){return new(require("xhr2"))},le=function(e){return n.ajax(A({},e,{responseType:"text",createXHR:ce})).pipe(l.map(function(e){return e.response}))};function fe(e){return le({url:e})}function pe(e){return fe(e).pipe(l.map(function(e){return JSON.parse(e)}))}function de(e,r){return le({method:"POST",url:e,body:r})}function he(e){return f.Observable.create(function(t){a.readFile(e,"utf-8",function(e,r){e?t.error(e):(t.next(r),t.complete())})})}function me(){return{username:x.env.ibm_wch_sdk_cli_username||"",password:x.env.ibm_wch_sdk_cli_password||""}}var ve=h.RSA_PKCS1_PADDING;var ge="base64",xe="utf8";function ye(r){ue(r);var e=c.join(g.homedir(),".ibm-wch-sdk-cli",".credentials"),t=function n(){return he(c.join(g.homedir(),".ssh","id_rsa")).pipe(l.map(function(e){return{key:e,padding:ve}}))}();return he(e).pipe(l.map(function(e){return JSON.parse(e)}),l.map(function(e){return e[r]}),l.mergeMap(function(r){return t.pipe(l.map(function(e){return function t(e,r){return m.privateDecrypt(r,Buffer.from(e,ge)).toString(xe)}(r.password,e)}),l.map(function(e){return r.password=e,r}))}),l.catchError(function(){return f.of({username:"",password:""})}))}function we(e){var t=te(e);return"win32"===g.platform()?function n(e){ue(e);var r='"'+c.normalize(c.join(__dirname,"..","..","..","assets","credman",process.arch,"WchCredMan.exe"))+'" "'+e+'"';return f.Observable.create(function(i){p.exec(r,{encoding:"utf8"},function(e,r,t){if(e)i.error(e);else try{i.next(JSON.parse(r)),i.complete()}catch(n){i.error(n)}})})}(t).pipe(l.mergeMap(function(e){return function r(e){return!!(e&&ae(e.username)&&i.isString(e.password))}(e)?f.of(e):ye(t)}),l.catchError(function(){return ye(t)})):ye(t)}function Se(e){return we(e).pipe(l.map(function(e){return function n(e,r){if(!r)return e;var t=i.cloneDeep(e);return r.username&&(t.username=r.username),r.password&&(t.password=r.password),t}(me(),e)}),l.catchError(function(e){return f.of(me())}))}var Ee={PEER:0,RUNTIME:1,DEVELOPMENT:2};function be(e){return e===Ee.PEER?"peerDependencies":e===Ee.DEVELOPMENT?"devDependencies":"dependencies"}Ee[Ee.PEER]="PEER",Ee[Ee.RUNTIME]="RUNTIME",Ee[Ee.DEVELOPMENT]="DEVELOPMENT";var ke=f.bindNodeCallback(a.readFile);function Ne(r){return ke(c.join(r,"package.json"),"utf-8").pipe(l.map(function(e){return JSON.parse(e)}),l.catchError(function(e){return Ne(c.parse(r).dir)}))}function Te(r){return pe(""+r+S.REL_PATH_CURRENT_USER).pipe(l.catchError(function(e){return function t(e,r){return f.throwError(new E.VError(r,"The API URL [%s] is not a valid WCH API URL.",e))}(r,e)}))}function je(e){return f.throwError(new E.VError("Unable to access credentials for the API URL [%s]. Please follow the directions on https://www.npmjs.com/package/ibm-wch-sdk-cli#credential-management to register credentials.",e))}function Pe(e,r){var t;if(!r||!ae(r.username)||!function o(e){return e&&0<e.length}(r.password))return je(e);var n=""+e+S.REL_PATH_BASICAUTH_LOGIN,i=((t={})[S.KEY_BASICAUTH_LOGIN_USERNAME]=r.username,t[S.KEY_BASICAUTH_LOGIN_PASSWORD]=r.password,t);return de(n,i).pipe(l.map(function(e){return JSON.parse(e)}),l.catchError(function(e){return f.throwError(new E.VError(e,"Unable to login to [%s] with user [%s]. Please check your registered password.",n,r.username))}),l.mapTo(e))}function Ae(e){return e&&e.externalId?f.of(e):f.throwError(new E.VError("Invalid currentuser response"))}var Oe="/package.json",Ie="/data",_e="wchtools-dependencies";function Ce(){return Ne(__dirname).pipe(l.pluck("version"))}function Le(e){var r=e.read(Oe);if(s.isNil(r))return Ie;var t=(JSON.parse(r.toString()).config||{}).data||Ie;return u.resolve("/",t)}var Me=Object.keys,Ke={name:1,description:2,id:3,classification:4};function Re(e){return Ke[e]||Number.MAX_SAFE_INTEGER}function Ue(e,r){var t=function n(e,r){return e<r?-1:r<e?1:0}(Re(e),Re(r));return 0===t&&(t=e.localeCompare(r)),t}function ze(r){if(s.isArray(r)){var t=[];return r.forEach(function(e){return t.push(ze(e))}),t}if(s.isPlainObject(r)){var n={};return Me(r).sort(Ue).forEach(function(e){return n[e]=ze(r[e])}),n}return r}function Fe(e){return e?JSON.stringify(e,undefined,2):undefined}function De(e){return e?e.join("\n"):undefined}function qe(e){return e?e.split("\n"):[]}function Ve(r,e,t){var n=t.read(r);return e(s.isNotNil(n)?n.toString():null,r).pipe(l.first(),l.map(function(e){return s.isNotNil(e)?s.isNotNil(n)?t.overwrite(r,e):t.create(r,e):s.isNotNil(n)?t["delete"](r):undefined}),l.mapTo(r))}var Je=function(r){function e(){var e=null!==r&&r.apply(this,arguments)||this;return e.buffers=[],e}return function n(e,r){function t(){this.constructor=e}P(e,r),e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)}(e,r),e.prototype._write=function(e,r,t){this.buffers.push(e),t()},e.prototype._final=function(e){e(),this.emit("close")},e}(k.Writable);function We(e){return f.of(e.html())}function Be(e,r){var t=e.read(r);if(!t)throw new d.SchematicsException("Could not find "+r+".");var n=t.toString();return v.createSourceFile(r,n,v.ScriptTarget.Latest,!0)}function He(e,t){e.forEach(function(e){if(e instanceof M)t.insertLeft(e.pos,e.toAdd);else if(e instanceof K);else if(e instanceof R){var r=e;t.remove(r.pos,r.oldText.length),t.insertLeft(r.pos,r.newText)}})}function Ge(e,r,t){t.exists(e)||t.create(e,"");var n=t.beginUpdate(e);He(r(e,Be(t,e)),n),t.commitUpdate(n)}function Ze(r,t){return function(e){return e&&e.kind===r&&e.getText()===t}}e.wchGetDeliveryUrlFromApiURL=s.wchGetDeliveryUrlFromApiURL,e.findModuleFromOptions=function $e(e,r){if(r.hasOwnProperty("skipImport")&&r.skipImport)return undefined;if(r.module){var t=u.normalize("/"+r.path+"/"+r.module),n=u.normalize(t).split("/").pop();if(e.exists(t))return u.normalize(t);if(e.exists(t+".ts"))return u.normalize(t+".ts");if(e.exists(t+".module.ts"))return u.normalize(t+".module.ts");if(e.exists(t+"/"+n+".module.ts"))return u.normalize(t+"/"+n+".module.ts");throw new Error("Specified module does not exist")}var i=(r.path||"")+(r.flat?"":"/"+u.strings.dasherize(r.name));return u.normalize(j(e,i))},e.findModule=j,e.buildRelativePath=function Xe(e,r){e=u.normalize(e),r=u.normalize(r);var t=e.split("/"),n=r.split("/");t.pop();var i=n.pop(),o=u.relative(u.normalize(t.join("/")),u.normalize(n.join("/"))),a="";return o?o.startsWith(".")||(a="./"):a=".",a&&!a.endsWith("/")&&(a+="/"),a+(o?o+"/":"")+i},e.insertImport=U,e.findNodes=z,e.getSourceNodes=F,e.findNode=D,e.insertAfterLastOccurrence=V,e.getContentOfKeyLiteral=function Ye(e,r){return r.kind==v.SyntaxKind.Identifier?r.text:r.kind==v.SyntaxKind.StringLiteral?r.text:null},e.getDecoratorMetadata=J,e.getFirstNgModuleName=function Qe(e){var r=J(e,"NgModule","@angular/core");if(0===r.length)return undefined;var t=function n(e){return v.isClassDeclaration(e)?e:e.parent&&n(e.parent)}(r[0]);return t&&t.name?t.name.text:undefined},e.addSymbolToNgModuleMetadata=W,e.addDeclarationToModule=function er(e,r,t,n){return W(e,r,"declarations",t,n)},e.addImportToModule=B,e.addProviderToModule=function rr(e,r,t,n){return W(e,r,"providers",t,n)},e.addExportToModule=function tr(e,r,t,n){return W(e,r,"exports",t,n)},e.addBootstrapToModule=function nr(e,r,t,n){return W(e,r,"bootstrap",t,n)},e.addEntryComponentToModule=function ir(e,r,t,n){return W(e,r,"entryComponents",t,n)},e.isImported=function or(e,r,t){return 0<F(e).filter(function(e){return e.kind===v.SyntaxKind.ImportDeclaration}).filter(function(e){return e.moduleSpecifier.kind===v.SyntaxKind.StringLiteral}).filter(function(e){return e.moduleSpecifier.text===t}).filter(function(e){return!!e.importClause&&0<z(e.importClause,v.SyntaxKind.ImportSpecifier).filter(function(e){return e.getText()===r}).length}).length},e.getWorkspacePath=H,e.getWorkspace=function ar(e){var r=H(e),t=e.read(r);if(null===t)throw new d.SchematicsException("Could not find ("+r+")");var n=t.toString();return u.parseJson(n,u.JsonParseMode.Loose)},e.addProjectToWorkspace=function ur(t,n,i){return function(e,r){if(t.projects[n])throw new Error("Project '"+n+"' already exists in workspace.");t.projects[n]=i,t.defaultProject||1!==Object.keys(t.projects).length||(t.defaultProject=n),e.overwrite(H(e),JSON.stringify(t,null,2))}},e.getConfig=function sr(e){var r=e.read(G);if(null===r)throw new d.SchematicsException("Could not find .angular-cli.json");return u.parseJson(r.toString(),u.JsonParseMode.Loose)},e.getAppFromConfig=function cr(e,r){return e.apps?0<=parseInt(r)?e.apps[parseInt(r)]:e.apps.filter(function(e){return e.name===r})[0]:null},e.configPath=G,e.findBootstrapModuleCall=Z,e.findBootstrapModulePath=$,e.getAppModulePath=function lr(e,r){var t=$(e,r),n=c.dirname(r);return u.normalize("/"+n+"/"+t+".ts")},e.parseName=function fr(e,r){var t=u.basename(r),n=u.dirname(e+"/"+r);return{name:t,path:u.normalize("/"+n)}},e.validateName=function pr(e){if(e&&/^\d/.test(e))throw new d.SchematicsException(u.tags.oneLine(X||(X=C(["name (",")\n can not start with a digit."],["name (",")\n can not start with a digit."])),e))},e.validateHtmlSelector=function dr(e){if(e&&!re.test(e))throw new d.SchematicsException(u.tags.oneLine(Y||(Y=C(["Selector (",")\n is invalid."],["Selector (",")\n is invalid."])),e))},e.validateProjectName=function hr(e){var r=function o(e){/^@.*\/.*/.test(e)&&(e=(e=e.replace(/^@/,"")).replace(/\//g,"-"));var r=0<=e.indexOf("-")?e.split("-"):[e],t=[],n=/^[a-zA-Z][.0-9a-zA-Z]*(-[.0-9a-zA-Z]*)*$/;r.forEach(function(e){e.match(n)&&t.push(e)});var i=t.join("-");return e!==i?i.length:null}(e);if(null!==r){var t=u.tags.oneLine(Q||(Q=C(['\n Project name "','" is not valid. New project names must\n start with a letter, and must contain only alphanumeric characters or dashes.\n When adding a dash the segment after the dash must also start with a letter.\n '],['\n Project name "','" is not valid. New project names must\n start with a letter, and must contain only alphanumeric characters or dashes.\n When adding a dash the segment after the dash must also start with a letter.\n '])),e),n=u.tags.stripIndent(ee||(ee=C(["\n ","\n ","\n ","\n "],["\n ","\n ","\n ","\n "])),t,e,Array(r+1).join(" ")+"^");throw new d.SchematicsException(n)}if(-1!==["test","ember","ember-cli","vendor","app"].indexOf(e))throw new d.SchematicsException("Project name "+JSON.stringify(e)+" is not a supported name.");if(!/^(?:@[a-zA-Z0-9_-]+\/)?[a-zA-Z0-9_-]+$/.test(e))throw new d.SchematicsException("Project name "+JSON.stringify(e)+" is invalid.")},e.htmlSelectorRe=re,e.NoopChange=L,e.InsertChange=M,e.RemoveChange=K,e.ReplaceChange=R,e.assertNotNull=function mr(e,r){t.ok(null!=e,r?"Value ["+r+"] must not be null or undefined.":"Value must not be null or undefined.")},e.assertParameter=function vr(e,r){t.ok(!!e,"Please specify the '--"+r+"' parameter.")},e.isValidUrl=ie,e.assertIsUrl=function gr(e,r){return t.ok(ie(e),r?"Value ["+r+"] must be a valid URL.":"Value must be a valid URL."),e},e.isValidEmail=oe,e.isValidUserName=ae,e.assertIsEmail=function xr(e,r){return t.ok(oe(e),r?"Value ["+r+"] must be a valid e-mail address.":"Value must be a valid e-mail address."),e},e.assertIsValidUserName=function yr(e,r){return t.ok(ae(e),r?"Value ["+r+"] must be a valid e-mail address or the term 'apikey'.":"Value must be a valid e-mail address or the term 'apikey'."),e},e.assertHasTrailingSlash=ue,e.TENANT_BASED_URL_REGEXP=se,e.ensureTrailingSlash=te,e.hasTrailingSlash=ne,e.rxGet=fe,e.rxGetJson=pe,e.rxFormPost=de,e.wchToolsGetCredentials=Se,e.validateCredentials=Pe,e.validateApiUrl=function wr(e,r){if(!o.isUri(e))return f.throwError(new E.VError('Please enter a valid API URL. Copy this URL from the "Hub Information" section of your WCH tenant.'));var t=te(e);if(r){var n=Se(t).pipe(l.catchError(function(e){return je(t)}));return Te(t).pipe(l.switchMap(Ae),l.switchMapTo(n),l.switchMap(function(e){return Pe(t,e)}))}return Te(t).pipe(l.switchMap(Ae),l.mapTo(t))},e.findSdkVersion=function Sr(e){var r=e.read(Oe);if(s.isNil(r))return Ce();var t=JSON.parse(r.toString()),n=t.dependencies||{},i=t.devDependencies||{},o=n["@ibm-wch-sdk/ng"]||i["@ibm-wch-sdk/cli"];return s.isNotNil(o)?function a(e){var r=w.coerce(e);return r?f.of(r.version):Ce()}(o):Ce()},e.findDataDir=Le,e.findWchToolsOptions=function Er(e){return u.resolve(Le(e),".wchtoolsoptions.json")},e.addToWchToolsDependencies=function br(e,r){var t=s.assertArray(_e,r);t.push.apply(t,_(e.filter(function(e){return t.indexOf(e)<0})))},e.WCHTOOLS_DEPENDENCIES=_e,e.rxReadFile=he,e.rxTransformTextFile=Ve,e.rxTransformJsonFile=function kr(e,r,t){var n=r;return Ve(e,function(e,r){return n(e?JSON.parse(e):undefined,r).pipe(l.map(ze),l.map(Fe))},t)},e.rxTransformLinesFile=function Nr(e,r,t){var n=r;return Ve(e,function(e,r){return n(e?qe(e):undefined,r).pipe(l.map(De))},t)},e.serializeJson=Fe,e.updateField=function Tr(e,r,t){var n=t[e];return s.isNil(n)&&(t[e]=r()),t},e.canonicalizeJSON=ze,e.rxUnzipFromUrl=function jr(n,i,o,a){return void 0===a&&(a=0),f.defer(function(){var e=b.get(i).pipe(N.Parse()),r=f.fromEvent(e,"entry"),t=f.fromEvent(e,"close");return r.pipe(l.takeUntil(t),l.mergeMap(function(e){return function s(e,r,t,n){var i=function u(e,r){for(var t=0,n=0;n<r;++n){var i=e.indexOf("/",t);if(!(t<=i))return null;t=i+1}return e.substring(t)}(r.path,n);if(!i)return f.of("").pipe(l.tap(function(){return r.autodrain()}),l.filter(function(){return!1}));var o=c.normalize(c.join(t,i));if("Directory"===r.type)return f.of("").pipe(l.tap(function(){return r.autodrain()}),l.filter(function(){return!1}));var a=r.pipe(new Je);return f.fromEvent(a,"close").pipe(l.first(),l.map(function(){return e.create(o,Buffer.concat(a.buffers))}),l.mapTo(o))}(n,e,o,a)}))})},e.rxTransformHtmlFile=function Pr(e,r,t){var n=r;return Ve(e,function(e,r){return function t(e){return f.of(T.load(s.isNotNil(e)?e:""))}(e).pipe(l.switchMap(function(e){return n(e,r)}),l.switchMap(We))},t)},e.getSourceFile=Be,e.insertChanges=He,e.changeSourceFile=Ge,e.addImportsToModule=function Ar(e,n,r){Object.keys(n).forEach(function(t){return Ge(e,function(e,r){return B(r,e,t,n[t])},r)})},e.byType=function Or(r){return function(e){return e&&e.kind===r}},e.byText=function Ir(r){return function(e){return e&&e.getText()===r}},e.byName=function _r(r){return function(e){return!(!e||!e.name||e.name.getText()!==r)}},e.byTypeAndName=Ze,e.byIdentifier=function Cr(e){return Ze(v.SyntaxKind.Identifier,e)},e.serializeLines=De,e.parseLines=qe,e.insertLines=function Lr(e,r){if(e){var t=new Set(e);return _(e,r.filter(function(e){return!t.has(e)}))}return _(r)},e.getFolderForType=be,e.updateMinVersion=function Mr(e,r,t,n){var i=be(n),o=s.assertObject(i,t),a=o[e];return!s.isNil(a)&&w.satisfies(r,a)||(o[e]="^"+r),t},e.findPackageJson=Ne,e.DEP_TYPE=Ee,Object.defineProperty(e,"__esModule",{value:!0})});
2//# sourceMappingURL=ibm-wch-sdk-schematics-utils.umd.min.js.map
\No newline at end of file