Skip to content

Commit a5353f0

Browse files
init project 🎉
0 parents  commit a5353f0

File tree

6 files changed

+194
-0
lines changed

6 files changed

+194
-0
lines changed

.editorconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
charset = utf-8
9+
insert_final_newline = true
10+
trim_trailing_whitespace = true

.gitignore

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
4+
# Editor directories and files
5+
.idea
6+
.vscode
7+
*.suo
8+
*.ntvs*
9+
*.njsproj
10+
*.sln
11+
12+
# dependencies
13+
/node_modules
14+
/.pnp
15+
.pnp.js
16+
17+
# testing
18+
/coverage
19+
20+
# production
21+
/build
22+
23+
# misc
24+
.DS_Store
25+
.env.local
26+
.env.development.local
27+
.env.test.local
28+
.env.production.local
29+
30+
npm-debug.log*
31+
yarn-debug.log*
32+
yarn-error.log*
33+
34+
.env
35+
/src/containers/App.tsx
36+
*.etag
37+
/platform/**/*.js
38+
/src/mocks/widgetConfig/index.ts
39+
/src/mocks/snippets/index.ts
40+
41+
# assets mock
42+
/public/file/*

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Oracle CX Commerce webpack plugin

index.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
const fs = require("fs");
2+
const logSymbols = require("log-symbols");
3+
4+
Reset = "\x1b[0m";
5+
Bright = "\x1b[1m";
6+
Dim = "\x1b[2m";
7+
Underscore = "\x1b[4m";
8+
Blink = "\x1b[5m";
9+
Reverse = "\x1b[7m";
10+
Hidden = "\x1b[8m";
11+
12+
FgBlack = "\x1b[30m";
13+
FgRed = "\x1b[31m";
14+
FgGreen = "\x1b[32m";
15+
FgYellow = "\x1b[33m";
16+
FgBlue = "\x1b[34m";
17+
FgMagenta = "\x1b[35m";
18+
FgCyan = "\x1b[36m";
19+
FgWhite = "\x1b[37m";
20+
21+
/**
22+
* @module WebpackOnBuildPlugin
23+
*/
24+
25+
/**
26+
* @constructor
27+
* @param {onBuildCallback} callback - will be called right after build.
28+
*/
29+
function WebpackOnBuildPlugin({ platform }) {
30+
this.platform = platform;
31+
}
32+
33+
/**
34+
* @callback onBuildCallback
35+
* @param {object} stats - webpack stats object
36+
*/
37+
38+
/**
39+
* @param {object} compiler
40+
*/
41+
WebpackOnBuildPlugin.prototype.apply = function(compiler) {
42+
const { platform } = this;
43+
const platformFolderName = platform.split('/').pop();
44+
compiler.hooks.done.tap("WebpackOnBuildPlugin", ({ compilation, ...params }) => {
45+
const testFolder = `${platform}/widget`;
46+
const outputFiles = Array.from(compiler._assetEmittingWrittenFiles.keys());
47+
48+
const leadWidgetConfig = async (widgetName) => require(`${platform}/.ccc/widget/${widgetName}/widget.json`)
49+
50+
fs.readdir(testFolder, async (err, files) => {
51+
console.log("Preparing your " + FgCyan + platformFolderName + Reset + " folder so that it is ready to be deployed...\n");
52+
await Promise.allSettled(
53+
files.map(async (file) => {
54+
const targetDir = `${testFolder}/${file}/js`;
55+
const widgetName = file.toLowerCase();
56+
const widgetConfig = await leadWidgetConfig(widgetName).catch((e) => ({}));
57+
let output = outputFiles.find((fileName) => fileName.includes(`${widgetConfig.javascript}.widget`));
58+
fs.rmdirSync(targetDir, { recursive: true });
59+
if (!output) {
60+
console.log(' ', logSymbols.error, `/widget${FgGreen}/${file}/${Reset}js/${widgetConfig.javascript}.js`);
61+
return;
62+
}
63+
console.log(' ', logSymbols.success, `/widget${FgGreen}/${file}/${Reset}js/${widgetConfig.javascript}.js`);
64+
fs.mkdirSync(targetDir, { recursive: true });
65+
fs.createReadStream(output).pipe(fs.createWriteStream(`${targetDir}/${widgetConfig.javascript}.js`));
66+
}),
67+
);
68+
console.log("\nThe " + FgCyan + platformFolderName + Reset + " folder is ready to be deployed.\n");
69+
console.log("Find out more about deployment here:\n");
70+
});
71+
});
72+
};
73+
74+
module.exports = WebpackOnBuildPlugin;

package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "occ-webpack-build-plugin",
3+
"description": "Oracle CX Commerce webpack plugin",
4+
"version": "1.0.0",
5+
"main": "index.js",
6+
"repository": "https://github.com/oracle-commerce-cloud/occ-webpack-build-plugin.git",
7+
"author": "aboulmane <anassboulmane@gmail.com>",
8+
"license": "MIT",
9+
"dependencies": {
10+
"log-symbols": "^4.0.0"
11+
}
12+
}

yarn.lock

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
"@types/color-name@^1.1.1":
6+
version "1.1.1"
7+
resolved "https://registry.yarnpkg.com/@types/color-name/-/color-name-1.1.1.tgz#1c1261bbeaa10a8055bbc5d8ab84b7b2afc846a0"
8+
integrity sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==
9+
10+
ansi-styles@^4.1.0:
11+
version "4.2.1"
12+
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-4.2.1.tgz#90ae75c424d008d2624c5bf29ead3177ebfcf359"
13+
integrity sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==
14+
dependencies:
15+
"@types/color-name" "^1.1.1"
16+
color-convert "^2.0.1"
17+
18+
chalk@^4.0.0:
19+
version "4.1.0"
20+
resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.0.tgz#4e14870a618d9e2edd97dd8345fd9d9dc315646a"
21+
integrity sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A==
22+
dependencies:
23+
ansi-styles "^4.1.0"
24+
supports-color "^7.1.0"
25+
26+
color-convert@^2.0.1:
27+
version "2.0.1"
28+
resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-2.0.1.tgz#72d3a68d598c9bdb3af2ad1e84f21d896abd4de3"
29+
integrity sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==
30+
dependencies:
31+
color-name "~1.1.4"
32+
33+
color-name@~1.1.4:
34+
version "1.1.4"
35+
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2"
36+
integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==
37+
38+
has-flag@^4.0.0:
39+
version "4.0.0"
40+
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b"
41+
integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==
42+
43+
log-symbols@^4.0.0:
44+
version "4.0.0"
45+
resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-4.0.0.tgz#69b3cc46d20f448eccdb75ea1fa733d9e821c920"
46+
integrity sha512-FN8JBzLx6CzeMrB0tg6pqlGU1wCrXW+ZXGH481kfsBqer0hToTIiHdjH4Mq8xJUbvATujKCvaREGWpGUionraA==
47+
dependencies:
48+
chalk "^4.0.0"
49+
50+
supports-color@^7.1.0:
51+
version "7.1.0"
52+
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-7.1.0.tgz#68e32591df73e25ad1c4b49108a2ec507962bfd1"
53+
integrity sha512-oRSIpR8pxT1Wr2FquTNnGet79b3BWljqOuoW/h4oBhxJ/HUbX5nX6JSruTkvXDCFMwDPvsaTTbvMLKZWSy0R5g==
54+
dependencies:
55+
has-flag "^4.0.0"

0 commit comments

Comments
 (0)