hoodoo-digital / acme

The AEM Component Markup Extractor for generating Storybook stories.
Apache License 2.0
21 stars 5 forks source link

Acme init command bug #66

Open jamesdbruner opened 2 years ago

jamesdbruner commented 2 years ago

When running npx @hoodoo/acme init and generating a acme.settings.json file, the user is prompted for their home page and the user inputs /content/my-brand/ they end up with

"homePage": "/content/<your-site>/content/my-brand/",

Which is obviously incorrect. The init script assumes we're inside of an AEM project but that may not always be the case.

jamesdbruner commented 2 years ago

I don't have access to the repo or I'd have put in a PR to fix the issue but this is what I was thinking...

const getSiteName = async () => {
    return fsPromises.readFile('pom.xml').then(
        (data) => {
            return xml2js
                .parseStringPromise(data)
                .then((obj) => obj.project.parent[0].artifactId[0])
        },
        (err) => {
            log(
                `Could not find ${err.path}... you will have to manually enter the policy path.`
            )
            return false
        }
    )
}

const hasSiteName = (siteName, val) => {
    if (Boolean(siteName) === false && val.length < 1) return '/content/<your-site>/'
    return val
}

and then this below

    {
        type: 'text',
        name: 'homePage',
        message: 'What is the path to the home page of your site?',
        initial: '/us/en',
        format: async (val) => {
            return getSiteName().then(
                (siteName) => hasSiteName(siteName, val)
            )
        }
    },