1 | /*
|
2 | * Copyright © 2019 Atomist, Inc.
|
3 | *
|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | * you may not use this file except in compliance with the License.
|
6 | * You may obtain a copy of the License at
|
7 | *
|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
9 | *
|
10 | * Unless required by applicable law or agreed to in writing, software
|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 | * See the License for the specific language governing permissions and
|
14 | * limitations under the License.
|
15 | */
|
16 |
|
17 | import * as camelcaseKeys from "camelcase-keys";
|
18 | import * as changeCase from "change-case";
|
19 | import * as _ from "lodash";
|
20 |
|
21 | /**
|
22 | * Watches the provided paths for changes when in watch mode
|
23 | */
|
24 | export function watchPaths(paths: string[]): void {
|
25 | process.env.ATOMIST_WATCH_PATHS =
|
26 | _.uniq([...(process.env.ATOMIST_WATCH_PATHS?.split(",") || []), ...paths]).join(",");
|
27 | }
|
28 |
|
29 | export function camelCase(obj: any): any {
|
30 | if (typeof obj === "string") {
|
31 | return camelCaseString(obj);
|
32 | } else if (Array.isArray(obj)) {
|
33 | return obj.map(camelCase);
|
34 | } else if (!obj) {
|
35 | return obj;
|
36 | }
|
37 | return camelcaseKeys(obj, { deep: true });
|
38 | }
|
39 |
|
40 | function camelCaseString(key: string): string {
|
41 | return key.split(".").map(k => changeCase.camel(k)).join(".");
|
42 | }
|