@graphcommerce/next-config 9.0.4-canary.8 → 9.0.4
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.
- package/CHANGELOG.md +7 -15
- package/__tests__/commands/copyFiles.ts +5 -8
- package/__tests__/config/utils/__snapshots__/mergeEnvIntoConfig.ts.snap +905 -0
- package/__tests__/config/utils/mergeEnvIntoConfig.ts +2 -9
- package/__tests__/config/utils/rewriteLegancyEnv.ts +0 -1
- package/__tests__/interceptors/findPlugins.ts +0 -1
- package/__tests__/interceptors/generateInterceptors.ts +0 -1
- package/__tests__/utils/resolveDependenciesSync.ts +0 -1
- package/dist/commands/codegen.js +3 -3
- package/dist/commands/copyFiles.js +7 -12
- package/dist/commands/copyRoutes.js +20 -0
- package/dist/config/commands/generateConfig.js +2 -1
- package/dist/config/utils/mergeEnvIntoConfig.js +3 -1
- package/dist/generated/config.js +15 -20
- package/dist/interceptors/writeInterceptors.js +1 -1
- package/package.json +1 -3
- package/src/commands/codegen.ts +3 -3
- package/src/commands/copyFiles.ts +7 -14
- package/src/config/commands/generateConfig.ts +2 -1
- package/src/config/utils/mergeEnvIntoConfig.ts +3 -1
- package/src/generated/config.ts +245 -299
- package/src/interceptors/Visitor.ts +1 -1
- package/src/interceptors/findOriginalSource.ts +1 -1
- package/src/interceptors/writeInterceptors.ts +1 -1
- package/src/utils/resolveDependenciesSync.ts +1 -1
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
import type { GraphCommerceConfig } from '../../../src/generated/config'
|
|
7
7
|
import { GraphCommerceConfigSchema } from '../../../src/generated/config'
|
|
8
8
|
import { removeColor } from './rewriteLegancyEnv'
|
|
9
|
-
|
|
10
9
|
const env = {
|
|
11
10
|
GC_ADVANCED_FILTERS: '0',
|
|
12
11
|
GC_DEMO_MODE: '1',
|
|
@@ -23,13 +22,7 @@ const env = {
|
|
|
23
22
|
}
|
|
24
23
|
it('traverses a schema and returns a list of env variables that match', () => {
|
|
25
24
|
const [envSchema] = configToEnvSchema(GraphCommerceConfigSchema())
|
|
26
|
-
|
|
27
|
-
const keys = Object.keys(envSchema.shape)
|
|
28
|
-
|
|
29
|
-
expect(keys.includes('GC_ADVANCED_FILTERS')).toBe(false)
|
|
30
|
-
expect(keys.includes('GC_STOREFRONT')).toBe(true)
|
|
31
|
-
expect(keys.includes('GC_STOREFRONT_0')).toBe(true)
|
|
32
|
-
expect(keys.includes('GC_STOREFRONT_1')).toBe(true)
|
|
25
|
+
expect(Object.keys(envSchema.shape)).toMatchSnapshot()
|
|
33
26
|
})
|
|
34
27
|
it('parses an env config object', () => {
|
|
35
28
|
const [envSchema] = configToEnvSchema(GraphCommerceConfigSchema())
|
|
@@ -108,7 +101,7 @@ it('converts an env schema to a config schema', () => {
|
|
|
108
101
|
+ GC_STOREFRONT => storefront
|
|
109
102
|
~ GC_STOREFRONT_0_LOCALE => storefront.[0].locale"
|
|
110
103
|
`)
|
|
111
|
-
|
|
104
|
+
// Validate the resulting configura
|
|
112
105
|
const parsed = GraphCommerceConfigSchema().safeParse(mergedConfig)
|
|
113
106
|
expect(parsed.success).toBe(true)
|
|
114
107
|
if (parsed.success) {
|
|
@@ -2,7 +2,6 @@ import { formatAppliedEnv } from '../../../src/config/utils/mergeEnvIntoConfig'
|
|
|
2
2
|
import { rewriteLegacyEnv } from '../../../src/config/utils/rewriteLegacyEnv'
|
|
3
3
|
import type { GraphCommerceConfig } from '../../../src/generated/config'
|
|
4
4
|
import { GraphCommerceConfigSchema } from '../../../src/generated/config'
|
|
5
|
-
|
|
6
5
|
export const removeColor = (str: string) =>
|
|
7
6
|
str.replace(
|
|
8
7
|
new RegExp(
|
|
@@ -5,7 +5,6 @@ import { generateInterceptors } from '../../src/interceptors/generateInterceptor
|
|
|
5
5
|
import { parseStructure } from '../../src/interceptors/parseStructure'
|
|
6
6
|
import { parseSync } from '../../src/interceptors/swc'
|
|
7
7
|
import { resolveDependency } from '../../src/utils/resolveDependency'
|
|
8
|
-
|
|
9
8
|
const projectRoot = `${process.cwd()}/examples/magento-graphcms`
|
|
10
9
|
const startLocation = '/** @see {@link file://'
|
|
11
10
|
const expectImport = (value: string | undefined): jest.JestMatchers<string> =>
|
package/dist/commands/codegen.js
CHANGED
|
@@ -7,12 +7,12 @@ const copyFiles_1 = require("./copyFiles");
|
|
|
7
7
|
/** Run all code generation steps in sequence */
|
|
8
8
|
async function codegen() {
|
|
9
9
|
// Copy files from packages to project
|
|
10
|
-
console.
|
|
10
|
+
console.log('🔄 Copying files from packages to project...');
|
|
11
11
|
await (0, copyFiles_1.copyFiles)();
|
|
12
12
|
// Generate GraphCommerce config types
|
|
13
|
-
console.
|
|
13
|
+
console.log('⚙️ Generating GraphCommerce config types...');
|
|
14
14
|
await (0, generateConfig_1.generateConfig)();
|
|
15
15
|
// Generate interceptors
|
|
16
|
-
console.
|
|
16
|
+
console.log('🔌 Generating interceptors...');
|
|
17
17
|
await (0, codegenInterceptors_1.codegenInterceptors)();
|
|
18
18
|
}
|
|
@@ -12,7 +12,7 @@ const resolveDependenciesSync_1 = require("../utils/resolveDependenciesSync");
|
|
|
12
12
|
// Add debug logging helper
|
|
13
13
|
const debug = (...args) => {
|
|
14
14
|
if (process.env.DEBUG)
|
|
15
|
-
console.
|
|
15
|
+
console.log('[copy-files]', ...args);
|
|
16
16
|
};
|
|
17
17
|
// Add constants for the magic comments
|
|
18
18
|
const MANAGED_BY_GC = '// managed by: graphcommerce';
|
|
@@ -28,11 +28,6 @@ const GITIGNORE_SECTION_END = '# end managed by: graphcommerce';
|
|
|
28
28
|
* - Ensures the file ends with a newline
|
|
29
29
|
*/
|
|
30
30
|
async function updateGitignore(managedFiles) {
|
|
31
|
-
const escapedFiles = managedFiles
|
|
32
|
-
.map((file) =>
|
|
33
|
-
// Escape special characters in file names
|
|
34
|
-
file.replace(/[*+?^${}()|[\]\\]/g, '\\$&'))
|
|
35
|
-
.sort();
|
|
36
31
|
const gitignorePath = path_1.default.join(process.cwd(), '.gitignore');
|
|
37
32
|
let content;
|
|
38
33
|
try {
|
|
@@ -47,10 +42,10 @@ async function updateGitignore(managedFiles) {
|
|
|
47
42
|
const sectionRegex = new RegExp(`${GITIGNORE_SECTION_START}[\\s\\S]*?${GITIGNORE_SECTION_END}\\n?`, 'g');
|
|
48
43
|
content = content.replace(sectionRegex, '');
|
|
49
44
|
// Only add new section if there are files to manage
|
|
50
|
-
if (
|
|
45
|
+
if (managedFiles.length > 0) {
|
|
51
46
|
const newSection = [
|
|
52
47
|
GITIGNORE_SECTION_START,
|
|
53
|
-
...
|
|
48
|
+
...managedFiles.sort(),
|
|
54
49
|
GITIGNORE_SECTION_END,
|
|
55
50
|
'', // Empty line at the end
|
|
56
51
|
].join('\n');
|
|
@@ -185,7 +180,7 @@ Found in packages:
|
|
|
185
180
|
return;
|
|
186
181
|
}
|
|
187
182
|
if (management === 'unmanaged') {
|
|
188
|
-
console.
|
|
183
|
+
console.log(`Note: File ${file} has been modified. Add '${MANAGED_LOCALLY.trim()}' at the top to manage it locally.`);
|
|
189
184
|
debug(`File ${file} doesn't have management comment, skipping`);
|
|
190
185
|
return;
|
|
191
186
|
}
|
|
@@ -197,7 +192,7 @@ Found in packages:
|
|
|
197
192
|
Source: ${sourcePath}`);
|
|
198
193
|
process.exit(1);
|
|
199
194
|
}
|
|
200
|
-
console.
|
|
195
|
+
console.log(`Creating new file: ${file}\nSource: ${sourcePath}`);
|
|
201
196
|
debug('File does not exist yet');
|
|
202
197
|
}
|
|
203
198
|
// Skip if content is identical (including magic comment)
|
|
@@ -209,7 +204,7 @@ Source: ${sourcePath}`);
|
|
|
209
204
|
// Copy the file with magic comment
|
|
210
205
|
await promises_1.default.writeFile(targetPath, contentWithComment);
|
|
211
206
|
if (targetContent) {
|
|
212
|
-
console.
|
|
207
|
+
console.log(`Updated managed file: ${file}`);
|
|
213
208
|
debug(`Overwrote existing file: ${file}`);
|
|
214
209
|
}
|
|
215
210
|
// If the file is managed by GraphCommerce (new or updated), add it to managedFiles
|
|
@@ -263,7 +258,7 @@ Source: ${sourcePath}`);
|
|
|
263
258
|
// Then try to remove the file
|
|
264
259
|
try {
|
|
265
260
|
await promises_1.default.unlink(filePath);
|
|
266
|
-
console.
|
|
261
|
+
console.log(`Removed managed file: ${file}`);
|
|
267
262
|
debug(`Removed file: ${file}`);
|
|
268
263
|
}
|
|
269
264
|
catch (err) {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
7
|
+
// ... earlier code remains the same ...
|
|
8
|
+
try {
|
|
9
|
+
targetContent = await promises_1.default.readFile(targetPath);
|
|
10
|
+
}
|
|
11
|
+
catch (err) {
|
|
12
|
+
if (err.code !== 'ENOENT')
|
|
13
|
+
throw err;
|
|
14
|
+
// File doesn't exist, log that we're creating it
|
|
15
|
+
console.log(`Creating new file: ${file}`);
|
|
16
|
+
}
|
|
17
|
+
// Skip if content is identical
|
|
18
|
+
if (targetContent && Buffer.compare(sourceContent, targetContent) === 0)
|
|
19
|
+
return;
|
|
20
|
+
// ... rest of the code remains the same ...
|
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.generateConfig = generateConfig;
|
|
7
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
7
8
|
const fs_1 = require("fs");
|
|
8
9
|
const cli_1 = require("@graphql-codegen/cli");
|
|
9
10
|
const core_1 = require("@swc/core");
|
|
@@ -50,7 +51,7 @@ async function generateConfig() {
|
|
|
50
51
|
});
|
|
51
52
|
const result = (0, core_1.transformFileSync)(targetTs, {
|
|
52
53
|
module: { type: 'commonjs' },
|
|
53
|
-
env: { targets: { node: '
|
|
54
|
+
env: { targets: { node: '16' } },
|
|
54
55
|
});
|
|
55
56
|
(0, fs_1.writeFileSync)(targetJs, result.code);
|
|
56
57
|
}
|
|
@@ -150,7 +150,9 @@ function mergeEnvIntoConfig(schema, config, env) {
|
|
|
150
150
|
function formatAppliedEnv(applyResult) {
|
|
151
151
|
let hasError = false;
|
|
152
152
|
let hasWarning = false;
|
|
153
|
-
const lines = applyResult.map(({ from, to, envVar, dotVar, error, warning }) => {
|
|
153
|
+
const lines = applyResult.map(({ from, to, envValue, envVar, dotVar, error, warning }) => {
|
|
154
|
+
const fromFmt = chalk_1.default.red(JSON.stringify(from));
|
|
155
|
+
const toFmt = chalk_1.default.green(JSON.stringify(to));
|
|
154
156
|
const envVariableFmt = `${envVar}`;
|
|
155
157
|
const dotVariableFmt = chalk_1.default.bold.underline(`${dotVar}`);
|
|
156
158
|
const baseLog = `${envVariableFmt} => ${dotVariableFmt}`;
|
package/dist/generated/config.js
CHANGED
|
@@ -18,18 +18,14 @@ exports.definedNonNullAnySchema = zod_1.z.any().refine((v) => (0, exports.isDefi
|
|
|
18
18
|
exports.CartPermissionsSchema = zod_1.z.enum(['CUSTOMER_ONLY', 'DISABLED', 'ENABLED']);
|
|
19
19
|
exports.CompareVariantSchema = zod_1.z.enum(['CHECKBOX', 'ICON']);
|
|
20
20
|
exports.ContainerSizingSchema = zod_1.z.enum(['BREAKPOINT', 'FULL_WIDTH']);
|
|
21
|
-
exports.CustomerAccountPermissionsSchema = zod_1.z.enum([
|
|
22
|
-
'DISABLED',
|
|
23
|
-
'DISABLE_REGISTRATION',
|
|
24
|
-
'ENABLED',
|
|
25
|
-
]);
|
|
21
|
+
exports.CustomerAccountPermissionsSchema = zod_1.z.enum(['DISABLED', 'DISABLE_REGISTRATION', 'ENABLED']);
|
|
26
22
|
exports.PaginationVariantSchema = zod_1.z.enum(['COMPACT', 'EXTENDED']);
|
|
27
23
|
exports.ProductFiltersLayoutSchema = zod_1.z.enum(['DEFAULT', 'SIDEBAR']);
|
|
28
24
|
exports.SidebarGalleryPaginationVariantSchema = zod_1.z.enum(['DOTS', 'THUMBNAILS_BOTTOM']);
|
|
29
25
|
exports.WebsitePermissionsSchema = zod_1.z.enum(['ENABLED']);
|
|
30
26
|
function DatalayerConfigSchema() {
|
|
31
27
|
return zod_1.z.object({
|
|
32
|
-
coreWebVitals: zod_1.z.boolean().nullish()
|
|
28
|
+
coreWebVitals: zod_1.z.boolean().nullish()
|
|
33
29
|
});
|
|
34
30
|
}
|
|
35
31
|
function GraphCommerceConfigSchema() {
|
|
@@ -38,11 +34,11 @@ function GraphCommerceConfigSchema() {
|
|
|
38
34
|
canonicalBaseUrl: zod_1.z.string().min(1),
|
|
39
35
|
cartDisplayPricesInclTax: zod_1.z.boolean().nullish(),
|
|
40
36
|
compare: zod_1.z.boolean().nullish(),
|
|
41
|
-
compareVariant: exports.CompareVariantSchema.default(
|
|
37
|
+
compareVariant: exports.CompareVariantSchema.default("ICON").nullish(),
|
|
42
38
|
configurableVariantForSimple: zod_1.z.boolean().default(false).nullish(),
|
|
43
39
|
configurableVariantValues: MagentoConfigurableVariantValuesSchema().nullish(),
|
|
44
|
-
containerSizingContent: exports.ContainerSizingSchema.default(
|
|
45
|
-
containerSizingShell: exports.ContainerSizingSchema.default(
|
|
40
|
+
containerSizingContent: exports.ContainerSizingSchema.default("FULL_WIDTH").nullish(),
|
|
41
|
+
containerSizingShell: exports.ContainerSizingSchema.default("FULL_WIDTH").nullish(),
|
|
46
42
|
crossSellsHideCartItems: zod_1.z.boolean().default(false).nullish(),
|
|
47
43
|
crossSellsRedirectItems: zod_1.z.boolean().default(false).nullish(),
|
|
48
44
|
customerAddressNoteEnable: zod_1.z.boolean().nullish(),
|
|
@@ -57,7 +53,6 @@ function GraphCommerceConfigSchema() {
|
|
|
57
53
|
googlePlaystore: GraphCommerceGooglePlaystoreConfigSchema().nullish(),
|
|
58
54
|
googleRecaptchaKey: zod_1.z.string().nullish(),
|
|
59
55
|
googleTagmanagerId: zod_1.z.string().nullish(),
|
|
60
|
-
graphqlMeshEditMode: zod_1.z.boolean().default(false).nullish(),
|
|
61
56
|
hygraphEndpoint: zod_1.z.string().min(1),
|
|
62
57
|
hygraphManagementApi: zod_1.z.string().nullish(),
|
|
63
58
|
hygraphProjectId: zod_1.z.string().nullish(),
|
|
@@ -67,16 +62,16 @@ function GraphCommerceConfigSchema() {
|
|
|
67
62
|
magentoVersion: zod_1.z.number(),
|
|
68
63
|
permissions: GraphCommercePermissionsSchema().nullish(),
|
|
69
64
|
previewSecret: zod_1.z.string().nullish(),
|
|
70
|
-
productFiltersLayout: exports.ProductFiltersLayoutSchema.default(
|
|
65
|
+
productFiltersLayout: exports.ProductFiltersLayoutSchema.default("DEFAULT").nullish(),
|
|
71
66
|
productFiltersPro: zod_1.z.boolean().nullish(),
|
|
72
|
-
productListPaginationVariant: exports.PaginationVariantSchema.default(
|
|
67
|
+
productListPaginationVariant: exports.PaginationVariantSchema.default("COMPACT").nullish(),
|
|
73
68
|
productRoute: zod_1.z.string().nullish(),
|
|
74
69
|
recentlyViewedProducts: RecentlyViewedProductsConfigSchema().nullish(),
|
|
75
70
|
robotsAllow: zod_1.z.boolean().nullish(),
|
|
76
71
|
sidebarGallery: SidebarGalleryConfigSchema().nullish(),
|
|
77
72
|
storefront: zod_1.z.array(GraphCommerceStorefrontConfigSchema()),
|
|
78
73
|
wishlistHideForGuests: zod_1.z.boolean().nullish(),
|
|
79
|
-
wishlistShowFeedbackMessage: zod_1.z.boolean().nullish()
|
|
74
|
+
wishlistShowFeedbackMessage: zod_1.z.boolean().nullish()
|
|
80
75
|
});
|
|
81
76
|
}
|
|
82
77
|
function GraphCommerceDebugConfigSchema() {
|
|
@@ -85,13 +80,13 @@ function GraphCommerceDebugConfigSchema() {
|
|
|
85
80
|
pluginStatus: zod_1.z.boolean().nullish(),
|
|
86
81
|
sessions: zod_1.z.boolean().nullish(),
|
|
87
82
|
webpackCircularDependencyPlugin: zod_1.z.boolean().nullish(),
|
|
88
|
-
webpackDuplicatesPlugin: zod_1.z.boolean().nullish()
|
|
83
|
+
webpackDuplicatesPlugin: zod_1.z.boolean().nullish()
|
|
89
84
|
});
|
|
90
85
|
}
|
|
91
86
|
function GraphCommerceGooglePlaystoreConfigSchema() {
|
|
92
87
|
return zod_1.z.object({
|
|
93
88
|
packageName: zod_1.z.string().min(1),
|
|
94
|
-
sha256CertificateFingerprint: zod_1.z.string().min(1)
|
|
89
|
+
sha256CertificateFingerprint: zod_1.z.string().min(1)
|
|
95
90
|
});
|
|
96
91
|
}
|
|
97
92
|
function GraphCommercePermissionsSchema() {
|
|
@@ -99,7 +94,7 @@ function GraphCommercePermissionsSchema() {
|
|
|
99
94
|
cart: exports.CartPermissionsSchema.nullish(),
|
|
100
95
|
checkout: exports.CartPermissionsSchema.nullish(),
|
|
101
96
|
customerAccount: exports.CustomerAccountPermissionsSchema.nullish(),
|
|
102
|
-
website: exports.WebsitePermissionsSchema.nullish()
|
|
97
|
+
website: exports.WebsitePermissionsSchema.nullish()
|
|
103
98
|
});
|
|
104
99
|
}
|
|
105
100
|
function GraphCommerceStorefrontConfigSchema() {
|
|
@@ -117,24 +112,24 @@ function GraphCommerceStorefrontConfigSchema() {
|
|
|
117
112
|
locale: zod_1.z.string().min(1),
|
|
118
113
|
magentoStoreCode: zod_1.z.string().min(1),
|
|
119
114
|
permissions: GraphCommercePermissionsSchema().nullish(),
|
|
120
|
-
robotsAllow: zod_1.z.boolean().nullish()
|
|
115
|
+
robotsAllow: zod_1.z.boolean().nullish()
|
|
121
116
|
});
|
|
122
117
|
}
|
|
123
118
|
function MagentoConfigurableVariantValuesSchema() {
|
|
124
119
|
return zod_1.z.object({
|
|
125
120
|
content: zod_1.z.boolean().nullish(),
|
|
126
121
|
gallery: zod_1.z.boolean().nullish(),
|
|
127
|
-
url: zod_1.z.boolean().nullish()
|
|
122
|
+
url: zod_1.z.boolean().nullish()
|
|
128
123
|
});
|
|
129
124
|
}
|
|
130
125
|
function RecentlyViewedProductsConfigSchema() {
|
|
131
126
|
return zod_1.z.object({
|
|
132
127
|
enabled: zod_1.z.boolean().nullish(),
|
|
133
|
-
maxCount: zod_1.z.number().nullish()
|
|
128
|
+
maxCount: zod_1.z.number().nullish()
|
|
134
129
|
});
|
|
135
130
|
}
|
|
136
131
|
function SidebarGalleryConfigSchema() {
|
|
137
132
|
return zod_1.z.object({
|
|
138
|
-
paginationVariant: exports.SidebarGalleryPaginationVariantSchema.nullish()
|
|
133
|
+
paginationVariant: exports.SidebarGalleryPaginationVariantSchema.nullish()
|
|
139
134
|
});
|
|
140
135
|
}
|
|
@@ -5,9 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.writeInterceptors = writeInterceptors;
|
|
7
7
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
8
|
+
const glob_1 = require("glob");
|
|
8
9
|
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
9
10
|
const path_1 = __importDefault(require("path"));
|
|
10
|
-
const glob_1 = require("glob");
|
|
11
11
|
const resolveDependenciesSync_1 = require("../utils/resolveDependenciesSync");
|
|
12
12
|
function checkFileExists(file) {
|
|
13
13
|
return promises_1.default
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/next-config",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "9.0.4
|
|
5
|
+
"version": "9.0.4",
|
|
6
6
|
"type": "commonjs",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"types": "src/index.ts",
|
|
@@ -12,13 +12,11 @@
|
|
|
12
12
|
"prepack": "tsc"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@graphql-codegen/cli": "5.0.3",
|
|
16
15
|
"@swc/core": "1.10.1",
|
|
17
16
|
"@swc/wasm-web": "^1.10.1",
|
|
18
17
|
"@types/circular-dependency-plugin": "^5.0.8",
|
|
19
18
|
"@types/lodash": "^4.17.13",
|
|
20
19
|
"babel-plugin-macros": "^3.1.0",
|
|
21
|
-
"chalk": "^4",
|
|
22
20
|
"circular-dependency-plugin": "^5.2.2",
|
|
23
21
|
"fast-glob": "^3.3.2",
|
|
24
22
|
"glob": "^10.4.5",
|
package/src/commands/codegen.ts
CHANGED
|
@@ -5,14 +5,14 @@ import { copyFiles } from './copyFiles'
|
|
|
5
5
|
/** Run all code generation steps in sequence */
|
|
6
6
|
export async function codegen() {
|
|
7
7
|
// Copy files from packages to project
|
|
8
|
-
console.
|
|
8
|
+
console.log('🔄 Copying files from packages to project...')
|
|
9
9
|
await copyFiles()
|
|
10
10
|
|
|
11
11
|
// Generate GraphCommerce config types
|
|
12
|
-
console.
|
|
12
|
+
console.log('⚙️ Generating GraphCommerce config types...')
|
|
13
13
|
await generateConfig()
|
|
14
14
|
|
|
15
15
|
// Generate interceptors
|
|
16
|
-
console.
|
|
16
|
+
console.log('🔌 Generating interceptors...')
|
|
17
17
|
await codegenInterceptors()
|
|
18
18
|
}
|
|
@@ -6,7 +6,7 @@ import { resolveDependenciesSync } from '../utils/resolveDependenciesSync'
|
|
|
6
6
|
|
|
7
7
|
// Add debug logging helper
|
|
8
8
|
const debug = (...args: unknown[]) => {
|
|
9
|
-
if (process.env.DEBUG) console.
|
|
9
|
+
if (process.env.DEBUG) console.log('[copy-files]', ...args)
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
// Add constants for the magic comments
|
|
@@ -25,13 +25,6 @@ const GITIGNORE_SECTION_END = '# end managed by: graphcommerce'
|
|
|
25
25
|
* - Ensures the file ends with a newline
|
|
26
26
|
*/
|
|
27
27
|
async function updateGitignore(managedFiles: string[]) {
|
|
28
|
-
const escapedFiles = managedFiles
|
|
29
|
-
.map((file) =>
|
|
30
|
-
// Escape special characters in file names
|
|
31
|
-
file.replace(/[*+?^${}()|[\]\\]/g, '\\$&'),
|
|
32
|
-
)
|
|
33
|
-
.sort()
|
|
34
|
-
|
|
35
28
|
const gitignorePath = path.join(process.cwd(), '.gitignore')
|
|
36
29
|
let content: string
|
|
37
30
|
|
|
@@ -51,10 +44,10 @@ async function updateGitignore(managedFiles: string[]) {
|
|
|
51
44
|
content = content.replace(sectionRegex, '')
|
|
52
45
|
|
|
53
46
|
// Only add new section if there are files to manage
|
|
54
|
-
if (
|
|
47
|
+
if (managedFiles.length > 0) {
|
|
55
48
|
const newSection = [
|
|
56
49
|
GITIGNORE_SECTION_START,
|
|
57
|
-
...
|
|
50
|
+
...managedFiles.sort(),
|
|
58
51
|
GITIGNORE_SECTION_END,
|
|
59
52
|
'', // Empty line at the end
|
|
60
53
|
].join('\n')
|
|
@@ -213,7 +206,7 @@ Found in packages:
|
|
|
213
206
|
return
|
|
214
207
|
}
|
|
215
208
|
if (management === 'unmanaged') {
|
|
216
|
-
console.
|
|
209
|
+
console.log(
|
|
217
210
|
`Note: File ${file} has been modified. Add '${MANAGED_LOCALLY.trim()}' at the top to manage it locally.`,
|
|
218
211
|
)
|
|
219
212
|
debug(`File ${file} doesn't have management comment, skipping`)
|
|
@@ -227,7 +220,7 @@ Found in packages:
|
|
|
227
220
|
Source: ${sourcePath}`)
|
|
228
221
|
process.exit(1)
|
|
229
222
|
}
|
|
230
|
-
console.
|
|
223
|
+
console.log(`Creating new file: ${file}\nSource: ${sourcePath}`)
|
|
231
224
|
debug('File does not exist yet')
|
|
232
225
|
}
|
|
233
226
|
|
|
@@ -241,7 +234,7 @@ Source: ${sourcePath}`)
|
|
|
241
234
|
// Copy the file with magic comment
|
|
242
235
|
await fs.writeFile(targetPath, contentWithComment)
|
|
243
236
|
if (targetContent) {
|
|
244
|
-
console.
|
|
237
|
+
console.log(`Updated managed file: ${file}`)
|
|
245
238
|
debug(`Overwrote existing file: ${file}`)
|
|
246
239
|
}
|
|
247
240
|
|
|
@@ -300,7 +293,7 @@ Source: ${sourcePath}`)
|
|
|
300
293
|
// Then try to remove the file
|
|
301
294
|
try {
|
|
302
295
|
await fs.unlink(filePath)
|
|
303
|
-
console.
|
|
296
|
+
console.log(`Removed managed file: ${file}`)
|
|
304
297
|
debug(`Removed file: ${file}`)
|
|
305
298
|
} catch (err) {
|
|
306
299
|
if ((err as { code?: string }).code !== 'ENOENT') {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
1
2
|
import { writeFileSync } from 'fs'
|
|
2
3
|
import { generate } from '@graphql-codegen/cli'
|
|
3
4
|
import { transformFileSync } from '@swc/core'
|
|
@@ -51,7 +52,7 @@ export async function generateConfig() {
|
|
|
51
52
|
|
|
52
53
|
const result = transformFileSync(targetTs, {
|
|
53
54
|
module: { type: 'commonjs' },
|
|
54
|
-
env: { targets: { node: '
|
|
55
|
+
env: { targets: { node: '16' } },
|
|
55
56
|
})
|
|
56
57
|
|
|
57
58
|
writeFileSync(targetJs, result.code)
|
|
@@ -204,7 +204,9 @@ export function mergeEnvIntoConfig(
|
|
|
204
204
|
export function formatAppliedEnv(applyResult: ApplyResult) {
|
|
205
205
|
let hasError = false
|
|
206
206
|
let hasWarning = false
|
|
207
|
-
const lines = applyResult.map(({ from, to, envVar, dotVar, error, warning }) => {
|
|
207
|
+
const lines = applyResult.map(({ from, to, envValue, envVar, dotVar, error, warning }) => {
|
|
208
|
+
const fromFmt = chalk.red(JSON.stringify(from))
|
|
209
|
+
const toFmt = chalk.green(JSON.stringify(to))
|
|
208
210
|
const envVariableFmt = `${envVar}`
|
|
209
211
|
const dotVariableFmt = chalk.bold.underline(`${dotVar}`)
|
|
210
212
|
|