-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat Adds Plugins feature #2563
base: main
Are you sure you want to change the base?
Changes from 13 commits
5566380
db80a44
2c1c3dd
dcb8517
97a2bdb
bb8f5c0
f681703
61a18b3
13d7adf
f52d834
7967345
44d41b2
8096ab5
07a7367
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import { CliUx } from '@oclif/core' | |
import { readFileSync, existsSync, writeFileSync } from 'fs-extra' | ||
|
||
import { withBasePath } from './directory' | ||
import { getPluginName, getPluginsList } from './plugins' | ||
|
||
export interface ContentTypeOrSectionDefinition { | ||
id?: string | ||
|
@@ -96,7 +97,8 @@ async function confirmUserChoice( | |
fileName: string | ||
) { | ||
const goAhead = await CliUx.ux.confirm( | ||
`You are about to override default ${fileName.split('.')[0] | ||
`You are about to override default ${ | ||
fileName.split('.')[0] | ||
}:\n\n${duplicates | ||
.map((definition) => definition.id || definition.name) | ||
.join('\n')}\n\nAre you sure? [yes/no]` | ||
|
@@ -110,7 +112,8 @@ async function confirmUserChoice( | |
} | ||
|
||
export async function mergeCMSFile(fileName: string, basePath: string) { | ||
const { coreCMSDir, userCMSDir, tmpCMSDir } = withBasePath(basePath) | ||
const { coreCMSDir, userCMSDir, tmpCMSDir, getPackagePath } = | ||
withBasePath(basePath) | ||
|
||
const coreFilePath = path.join(coreCMSDir, fileName) | ||
const customFilePath = path.join(userCMSDir, fileName) | ||
|
@@ -123,32 +126,44 @@ export async function mergeCMSFile(fileName: string, basePath: string) { | |
|
||
let output: ContentTypeOrSectionDefinition[] = coreDefinitions | ||
|
||
const plugins = await getPluginsList(basePath) | ||
|
||
const pluginCMSFilePaths = plugins.map((plugin) => | ||
getPackagePath(getPluginName(plugin), 'cms', 'faststore', fileName) | ||
) | ||
|
||
const customizations = [...pluginCMSFilePaths, customFilePath].filter( | ||
(pluginCMSFilePath) => existsSync(pluginCMSFilePath) | ||
) | ||
|
||
// TODO: create a validation when the CMS files exist but don't have a component for them | ||
if (existsSync(customFilePath)) { | ||
const customFile = readFileSync(customFilePath, 'utf8') | ||
for (const newFilePath of customizations) { | ||
const customFile = readFileSync(newFilePath, 'utf8') | ||
|
||
try { | ||
const customDefinitions = JSON.parse(customFile) | ||
|
||
const { duplicates, newDefinitions } = splitCustomDefinitions( | ||
coreDefinitions, | ||
output, | ||
customDefinitions, | ||
primaryIdentifierForDefinitions | ||
) | ||
|
||
if (duplicates.length) { | ||
await confirmUserChoice(duplicates, fileName) | ||
if (newFilePath === customFilePath) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain this check here? I'm not getting the reason why. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Customization Files Array includes both Plugin Customization Files and User Customization Files. This check determines if the file is a User Customization File. If it is, the user is prompted to decide whether the file should be overwritten. |
||
await confirmUserChoice(duplicates, fileName) | ||
} | ||
|
||
output = [ | ||
...dedupeAndMergeDefinitions( | ||
coreDefinitions, | ||
output, | ||
duplicates, | ||
primaryIdentifierForDefinitions | ||
), | ||
...newDefinitions, | ||
] | ||
} else { | ||
output = [...coreDefinitions, ...newDefinitions] | ||
output = [...output, ...newDefinitions] | ||
} | ||
} catch (err) { | ||
if (err instanceof SyntaxError) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this variable renamed? If I understood correctly, most changes on this file are cosmetic (indentation) and you're adding the
getPackagePath
entry to the returned object, right? If that's so can you undo the rename of thisconst
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good, it must have been a mistake. Renamed.