Skip to content

Commit c1ba4a7

Browse files
authored
Merge pull request #3828 from cpyle0819/corepyle/#3670
Move elwing libs to main js libs folder.
2 parents dabd46c + ff85c38 commit c1ba4a7

File tree

14 files changed

+114
-108
lines changed

14 files changed

+114
-108
lines changed

javascriptv3/example_code/libs/ext-ramda.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
identity,
1414
is,
1515
map,
16-
nth,
1716
prop,
1817
T,
1918
} from "ramda";
@@ -28,6 +27,8 @@ const flipApplyMap = curry((funcs) =>
2827

2928
const concatMap = compose(map, concat);
3029

30+
const nthAdjust = curry((i, fn, list) => fn(list[i]));
31+
3132
const parseString = cond([
3233
[is(String), identity],
3334
[is(Error), prop("message")],
@@ -36,4 +37,12 @@ const parseString = cond([
3637

3738
const promiseAll = bind(Promise.all, Promise);
3839

39-
export { flipApply, flipMap, flipApplyMap, concatMap, parseString, promiseAll };
40+
export {
41+
flipApply,
42+
flipMap,
43+
flipApplyMap,
44+
concatMap,
45+
nthAdjust,
46+
parseString,
47+
promiseAll,
48+
};

javascriptv3/example_code/libs/utils/util-fs.js

+36-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,28 @@
22
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
5-
import { compose, map, tryCatch, always } from "ramda";
5+
import {
6+
compose,
7+
map,
8+
tryCatch,
9+
always,
10+
identity,
11+
ifElse,
12+
invoker,
13+
split,
14+
tap,
15+
pipe,
16+
filter,
17+
prop,
18+
} from "ramda";
619
import { unlink, readFile } from "fs/promises";
720
import {
821
readdirSync,
922
createWriteStream,
1023
readFileSync,
1124
writeFileSync,
25+
existsSync,
26+
mkdirSync,
1227
} from "fs";
1328
import archiver from "archiver";
1429
import { fileURLToPath } from "url";
@@ -40,6 +55,16 @@ const handleZipEnd = (resolve, path) => async () => {
4055
resolve(buffer);
4156
};
4257

58+
const makeDir = ifElse(existsSync, identity, tap(mkdirSync));
59+
60+
const readLines = pipe(readFileSync, invoker(0, "toString"), split("\n"));
61+
62+
const readSubdirSync = pipe(
63+
readdirSync,
64+
filter(invoker(0, "isDirectory")),
65+
map(prop("name"))
66+
);
67+
4368
const zip = (inputPath) =>
4469
new Promise((resolve, reject) => {
4570
try {
@@ -65,4 +90,13 @@ const zip = (inputPath) =>
6590
archive.finalize();
6691
});
6792

68-
export { deleteFiles, dirnameFromMetaUrl, getTmp, setTmp, zip };
93+
export {
94+
deleteFiles,
95+
dirnameFromMetaUrl,
96+
getTmp,
97+
makeDir,
98+
readLines,
99+
readSubdirSync,
100+
setTmp,
101+
zip,
102+
};

javascriptv3/example_code/libs/utils/util-string.js

+27-8
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,39 @@
22
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
5+
import { pipe, adjust, join, split, toLower, map, toUpper } from "ramda";
6+
57
import { v4 as uuidv4 } from "uuid";
68

7-
export const getUniqueName = (name) => `${uuidv4()}-${name.toLowerCase()}`;
9+
const getUniqueName = (name) => `${uuidv4()}-${name.toLowerCase()}`;
810

9-
/**
10-
*
11-
* @param { string } source the string to modify
12-
* @param { string } str the string to affix to the source
13-
* @returns { string } the postfixed source
14-
*/
15-
export const postfix = (source, str) => {
11+
const postfix = (source, str) => {
1612
if (typeof str !== "string") {
1713
throw new Error("Cannot postfix a non-string value.");
1814
}
1915

2016
return `${source}${str}`;
2117
};
18+
19+
const downcaseSplit = pipe(toLower, split("-"));
20+
21+
const capitalize = pipe(Array.from, adjust(0, toUpper), join(""));
22+
23+
const kebabCase = pipe(downcaseSplit, join("-"));
24+
25+
const pascalCase = pipe(downcaseSplit, map(capitalize), join(""));
26+
27+
const snakeCase = pipe(downcaseSplit, join("_"));
28+
29+
const titleCase = pipe(downcaseSplit, map(capitalize), join(" "));
30+
31+
export {
32+
capitalize,
33+
downcaseSplit,
34+
getUniqueName,
35+
kebabCase,
36+
pascalCase,
37+
postfix,
38+
snakeCase,
39+
titleCase,
40+
};

resources/clients/react/elwing/libs/ext-ramda.ts

-12
This file was deleted.

resources/clients/react/elwing/libs/utils/util-fs.ts

-29
This file was deleted.

resources/clients/react/elwing/libs/utils/util-string.ts

-35
This file was deleted.

resources/clients/react/elwing/package-lock.json

+1-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/clients/react/elwing/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "elwing",
33
"version": "0.1.0",
44
"private": true,
5+
"type": "module",
56
"dependencies": {
67
"@cloudscape-design/components": "^3.0.65",
78
"@cloudscape-design/global-styles": "^1.0.1",

resources/clients/react/elwing/src/plugin-creator/content-builder.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import {
99
pascalCase,
1010
snakeCase,
1111
titleCase,
12-
} from "../../libs/utils/util-string";
13-
import { copyright } from "./copyright";
12+
} from "../../../../../../javascriptv3/example_code/libs/utils/util-string.js";
13+
import { copyright } from "./copyright.js";
1414

1515
const makePluginContents = (pluginName: string) => {
1616
const fileData = `

resources/clients/react/elwing/src/plugin-creator/index.ts

+18-8
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,19 @@
44
*/
55

66
import { writeFileSync } from "fs";
7-
import { kebabCase, pascalCase } from "../../libs/utils/util-string";
8-
import { nthAdjust } from "../../libs/ext-ramda";
9-
import { getArgValidationErrors } from "./validations";
10-
import { makePluginPath } from "./path-builder";
11-
import { makeComponentContents, makePluginContents, makePackageJsonContents } from "./content-builder";
12-
import { refreshRegistry } from "./register";
7+
import {
8+
kebabCase,
9+
pascalCase,
10+
} from "../../../../../../javascriptv3/example_code/libs/utils/util-string.js";
11+
import { nthAdjust } from "../../../../../../javascriptv3/example_code/libs/ext-ramda.js";
12+
import { getArgValidationErrors } from "./validations.js";
13+
import { makePluginPath } from "./path-builder.js";
14+
import {
15+
makeComponentContents,
16+
makePluginContents,
17+
makePackageJsonContents,
18+
} from "./content-builder.js";
19+
import { refreshRegistry } from "./register.js";
1320
import { execSync } from "child_process";
1421

1522
(async () => {
@@ -24,10 +31,13 @@ import { execSync } from "child_process";
2431
const path = makePluginPath(pluginName);
2532
const pluginContents = makePluginContents(pluginName);
2633
const componentContents = makeComponentContents(pluginName);
27-
const packageJsonContents = makePackageJsonContents(pluginName)
34+
const packageJsonContents = makePackageJsonContents(pluginName);
2835
writeFileSync(`${path}/package.json`, packageJsonContents);
2936
writeFileSync(`${path}/index.ts`, pluginContents);
30-
writeFileSync(`${path}/${pascalCase(pluginName)}Component.tsx`, componentContents);
37+
writeFileSync(
38+
`${path}/${pascalCase(pluginName)}Component.tsx`,
39+
componentContents
40+
);
3141
writeFileSync(`${path}/.gitignore`, "node_modules");
3242
execSync(`npm i file:src/plugins/${pluginName}`);
3343
refreshRegistry();

resources/clients/react/elwing/src/plugin-creator/path-builder.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44
*/
55

66
import { pipe, concat } from "ramda";
7-
import { makeDir } from "../../libs/utils/util-fs";
8-
import { kebabCase } from "../../libs/utils/util-string";
7+
import {
8+
makeDir,
9+
dirnameFromMetaUrl,
10+
} from "../../../../../../javascriptv3/example_code/libs/utils/util-fs.js";
11+
import { kebabCase } from "../../../../../../javascriptv3/example_code/libs/utils/util-string.js";
12+
13+
const __dirname = dirnameFromMetaUrl(import.meta.url);
914

1015
const makePluginPath = pipe(
1116
kebabCase,

resources/clients/react/elwing/src/plugin-creator/register.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import { writeFileSync } from "fs";
22
import { format } from "prettier";
33
import { concat, join, map, pipe } from "ramda";
4-
import { readSubdirSync } from "../../libs/utils/util-fs";
5-
import { pascalCase } from "../../libs/utils/util-string";
6-
import { copyright } from "./copyright";
4+
import {
5+
dirnameFromMetaUrl,
6+
readSubdirSync,
7+
} from "../../../../../../javascriptv3/example_code/libs/utils/util-fs.js";
8+
import { pascalCase } from "../../../../../../javascriptv3/example_code/libs/utils/util-string.js";
9+
import { copyright } from "./copyright.js";
10+
11+
const __dirname = dirnameFromMetaUrl(import.meta.url);
712

813
const pluginsPath = `${__dirname}/../plugins`;
914
const manifestPath = `${__dirname}/../plugins/manifest.ts`;

resources/clients/react/elwing/src/plugin-creator/validations.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import { pipe, length, equals, nth, test, isNil } from "ramda";
7-
import { validate, validationErrors } from "../../libs/validator";
7+
import { validate, validationErrors } from "../../libs/validator.js";
88

99
const pluginNamePattern = /^[A-Za-z]+-?[A-Za-z]+$/;
1010

resources/clients/react/elwing/tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
"jsx": "react-jsx"
1818
},
1919
"ts-node": {
20+
"esm": true,
2021
"compilerOptions": {
21-
"module": "CommonJS"
22+
"module": "ESNext"
2223
}
2324
},
2425
"include": ["src"]

0 commit comments

Comments
 (0)