@dcoder-x/next 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ import type { ClippyPluginOptions } from '@clippy/plugin-shared';
2
+ export declare function withClippy(nextConfig: Record<string, any> | undefined, options: ClippyPluginOptions): {
3
+ webpack(config: any, context: any): any;
4
+ };
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.withClippy = withClippy;
4
+ const ClippyWebpackPlugin_1 = require("./ClippyWebpackPlugin");
5
+ function withClippy(nextConfig = {}, options) {
6
+ return {
7
+ ...nextConfig,
8
+ webpack(config, context) {
9
+ if (!context.isServer) {
10
+ config.plugins.push(new ClippyWebpackPlugin_1.ClippyWebpackPlugin(options, context));
11
+ }
12
+ if (typeof nextConfig.webpack === 'function') {
13
+ return nextConfig.webpack(config, context);
14
+ }
15
+ return config;
16
+ },
17
+ };
18
+ }
@@ -0,0 +1,15 @@
1
+ import type { Compiler } from 'webpack';
2
+ import type { ClippyPluginOptions } from '@clippy/plugin-shared';
3
+ interface NextContext {
4
+ dir: string;
5
+ buildId: string;
6
+ isServer: boolean;
7
+ dev: boolean;
8
+ }
9
+ export declare class ClippyWebpackPlugin {
10
+ private options;
11
+ private context;
12
+ constructor(options: ClippyPluginOptions, context: NextContext);
13
+ apply(compiler: Compiler): void;
14
+ }
15
+ export {};
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ClippyWebpackPlugin = void 0;
4
+ const RouteExtractor_1 = require("@clippy/plugin-shared/extractors/RouteExtractor");
5
+ const ComponentExtractor_1 = require("@clippy/plugin-shared/extractors/ComponentExtractor");
6
+ const SelectorGenerator_1 = require("@clippy/plugin-shared/extractors/SelectorGenerator");
7
+ const FlowInferrer_1 = require("@clippy/plugin-shared/extractors/FlowInferrer");
8
+ const PackageBuilder_1 = require("@clippy/plugin-shared/upload/PackageBuilder");
9
+ const PackageWriter_1 = require("@clippy/plugin-shared/upload/PackageWriter");
10
+ const Uploader_1 = require("@clippy/plugin-shared/upload/Uploader");
11
+ class ClippyWebpackPlugin {
12
+ constructor(options, context) {
13
+ this.options = options;
14
+ this.context = context;
15
+ }
16
+ apply(compiler) {
17
+ compiler.hooks.afterEmit.tapPromise('ClippyWebpackPlugin', async (compilation) => {
18
+ if (this.context.dev && this.options.productionOnly)
19
+ return;
20
+ try {
21
+ const routes = await new RouteExtractor_1.RouteExtractor(this.context.dir).extract();
22
+ const components = await new ComponentExtractor_1.ComponentExtractor({ type: 'webpack', compilation }, routes).extract();
23
+ const selectors = new SelectorGenerator_1.SelectorGenerator().generate(components);
24
+ const flows = new FlowInferrer_1.FlowInferrer(routes, components).infer();
25
+ const packageBuilder = new PackageBuilder_1.PackageBuilder();
26
+ const knowledgePackage = packageBuilder.buildPackage({
27
+ buildId: this.context.buildId,
28
+ bundler: 'webpack',
29
+ routes,
30
+ components,
31
+ selectors,
32
+ flows,
33
+ });
34
+ if (this.options.localOutputDir) {
35
+ const written = new PackageWriter_1.PackageWriter().write(this.options.localOutputDir, knowledgePackage);
36
+ console.log(`[Clippy] Knowledge package written: ${written.jsonPath}`);
37
+ }
38
+ const pkg = packageBuilder.build({
39
+ buildId: knowledgePackage.buildId,
40
+ bundler: knowledgePackage.bundler,
41
+ routes: knowledgePackage.routes,
42
+ components: knowledgePackage.components,
43
+ selectors: knowledgePackage.selectors,
44
+ flows: knowledgePackage.flows,
45
+ });
46
+ const uploaded = await new Uploader_1.Uploader(this.options).upload(pkg);
47
+ if (uploaded) {
48
+ console.log('[Clippy] Knowledge package uploaded.');
49
+ }
50
+ else {
51
+ console.log('[Clippy] Knowledge package upload skipped.');
52
+ }
53
+ }
54
+ catch (err) {
55
+ console.warn('[Clippy] Upload failed:', err);
56
+ }
57
+ });
58
+ }
59
+ }
60
+ exports.ClippyWebpackPlugin = ClippyWebpackPlugin;
@@ -0,0 +1 @@
1
+ export { withClippy } from './ClippyNextPlugin';
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.withClippy = void 0;
4
+ var ClippyNextPlugin_1 = require("./ClippyNextPlugin");
5
+ Object.defineProperty(exports, "withClippy", { enumerable: true, get: function () { return ClippyNextPlugin_1.withClippy; } });
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@dcoder-x/next",
3
+ "version": "0.1.0",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
12
+ "dependencies": {
13
+ "@dcoder-x/plugin-shared": "^0.1.0"
14
+ },
15
+ "peerDependencies": {
16
+ "next": ">=13.0.0",
17
+ "webpack": ">=5.0.0",
18
+ "@babel/parser": "^7.0.0",
19
+ "@babel/traverse": "^7.0.0"
20
+ },
21
+ "scripts": {
22
+ "build": "tsc -p tsconfig.json"
23
+ }
24
+ }