1 | /**
|
2 | * @file Defines the BaseMetaDeployHelper class.
|
3 | *
|
4 | * @author Luke Chavers <luke@c2cschools.com>
|
5 | * @since 5.1.30
|
6 | * @license See LICENSE.md for details about licensing.
|
7 | * @copyright 2019 C2C Schools, LLC
|
8 | */
|
9 |
|
10 | ;
|
11 |
|
12 | // Important Note
|
13 | // --------------
|
14 | // This module only loads a single dependency, directly, which is the
|
15 | // parent class for the class defined within. This is intended to force
|
16 | // dependency loading through the parent class, by way of the `$dep()`
|
17 | // method, in order to centralize dependency definition and loading.
|
18 |
|
19 | const BaseClass = require( "@corefw/common" ).common.BaseClass;
|
20 |
|
21 | /**
|
22 | * Something...
|
23 | *
|
24 | * @abstract
|
25 | * @memberOf Deploy
|
26 | * @extends Common.BaseClass
|
27 | */
|
28 | class BaseMetaDeployHelper extends BaseClass {
|
29 |
|
30 |
|
31 | // <editor-fold desc="--- Construction and Initialization ----------------">
|
32 |
|
33 | /**
|
34 | * @inheritDoc
|
35 | */
|
36 | _initialize( cfg ) {
|
37 |
|
38 | // Call parent
|
39 | super._initialize( cfg );
|
40 |
|
41 | }
|
42 |
|
43 | // </editor-fold>
|
44 |
|
45 | // <editor-fold desc="--- Properties -------------------------------------">
|
46 |
|
47 |
|
48 |
|
49 | /**
|
50 | * Returns the MetaDeploymentManager object that spawned this helper class object.
|
51 | *
|
52 | * @access public
|
53 | * @default null
|
54 | * @type {Deploy.MetaDeploymentManager}
|
55 | */
|
56 | get mdm() {
|
57 | return this.getConfigValue( "metaDeploymentManager", null );
|
58 | }
|
59 |
|
60 | set mdm( val ) {
|
61 | this.setConfigValue( "metaDeploymentManager", val );
|
62 | }
|
63 |
|
64 | get packageData() {
|
65 | return this.mdm.packageData;
|
66 | }
|
67 |
|
68 | get serviceRootPath() {
|
69 | return this.mdm.serviceRootPath;
|
70 | }
|
71 |
|
72 |
|
73 | // </editor-fold>
|
74 |
|
75 |
|
76 | // <editor-fold desc="--- Logging ----------------------------------------">
|
77 |
|
78 |
|
79 |
|
80 |
|
81 | /**
|
82 | * @inheritDoc
|
83 | */
|
84 | get logger() {
|
85 |
|
86 | const me = this;
|
87 |
|
88 | if ( me._logger === undefined ) {
|
89 |
|
90 | let parentLogger = super.logger;
|
91 | let prefix = me._logComponentPrefix;
|
92 | let idSuffix = prefix.replace( /[\:\s]+/g, '' ).toLowerCase() + "." + me.constructor.name;
|
93 |
|
94 | me._logger = parentLogger.fork({
|
95 | component: prefix + me.constructor.name,
|
96 | namePrefix : idSuffix
|
97 | });
|
98 |
|
99 | }
|
100 |
|
101 | return me._logger;
|
102 | }
|
103 |
|
104 | /**
|
105 | * @inheritDoc
|
106 | */
|
107 | set logger( val ) {
|
108 | super.logger = val;
|
109 | }
|
110 |
|
111 |
|
112 |
|
113 |
|
114 | // </editor-fold>
|
115 |
|
116 | // <editor-fold desc="--- Utility Methods --------------------------------">
|
117 |
|
118 |
|
119 |
|
120 | resolveLocalAbs( relLocalPath ) {
|
121 |
|
122 | // Locals
|
123 | let me = this;
|
124 | let servicePath = me.serviceRootPath;
|
125 |
|
126 | // Dependencies
|
127 | const PATH = me.$dep("path");
|
128 |
|
129 | return PATH.join( servicePath, relLocalPath );
|
130 |
|
131 | }
|
132 |
|
133 | resolveServiceRel( absLocalPath ) {
|
134 |
|
135 | // Locals
|
136 | let me = this;
|
137 | let servicePath = me.serviceRootPath;
|
138 |
|
139 | // Remove service root and return
|
140 | return absLocalPath.replace( servicePath, "" );
|
141 |
|
142 | }
|
143 |
|
144 | _convertObjectToJson( obj ) {
|
145 |
|
146 | // Locals
|
147 | let me = this;
|
148 |
|
149 | // Dependencies
|
150 | const _ = me.$dep("lodash");
|
151 |
|
152 | // Filter out psuedo-comments (keys prefixed with '//')
|
153 | let replacerFn = function( key, value ) {
|
154 |
|
155 | if( _.startsWith( key, "//" ) ) {
|
156 | return undefined;
|
157 | } else {
|
158 | return value;
|
159 | }
|
160 |
|
161 | };
|
162 |
|
163 | // Convert to JSON and return
|
164 | return JSON.stringify( obj, replacerFn, "\t" );
|
165 |
|
166 | }
|
167 |
|
168 | _convertObjectToYaml( obj ) {
|
169 |
|
170 | // Locals
|
171 | let me = this;
|
172 |
|
173 | // Dependencies
|
174 | const YAML = me.$dep("yaml");
|
175 |
|
176 | // Convert to JSON first, for consistency (replacerFn)
|
177 | let json = me._convertObjectToJson( obj );
|
178 |
|
179 | // Convert back to an Object
|
180 | let parsed = JSON.parse( json );
|
181 |
|
182 | // Convert to YAML and return
|
183 | return YAML.safeDump( parsed );
|
184 |
|
185 | }
|
186 |
|
187 | /**
|
188 | * Convenience alias/proxy for `BaseGenerator#_findFilesWithPattern()`
|
189 | *
|
190 | * @access public
|
191 | * @param {string} basePath - The file system path to search
|
192 | * @param {RegExp} pattern - The regular expression to test each absolute
|
193 | * path against.
|
194 | * @returns {Object} A plain-object, keyed by absolute paths, that
|
195 | * contains information about each file that was matched/found.
|
196 | */
|
197 | findFilesWithPattern( basePath, pattern ) {
|
198 | return this.mdm._findFilesWithPattern( basePath, pattern );
|
199 | }
|
200 |
|
201 | /**
|
202 | * Convenience alias/proxy for `BaseGenerator#_getFilesRecursive()`
|
203 | *
|
204 | * @access public
|
205 | * @param {string} basePath - The file system path to scan/walk.
|
206 | * @returns {Object} A plain-object, keyed by absolute paths, that
|
207 | * contains information about each file within the provided `basePath`.
|
208 | */
|
209 | getFilesRecursive( basePath ) {
|
210 | return this.mdm._getFilesRecursive( basePath );
|
211 | }
|
212 |
|
213 |
|
214 | // </editor-fold>
|
215 |
|
216 | }
|
217 |
|
218 | module.exports = BaseMetaDeployHelper;
|