0

I have a configuration file in JS that exports an array of of objects:

const configuration: ConfigData[] = [
    {
        pathToPage: 'some/path',
        pathToComponent: 'components/some-component',
        roles: [Roles.Admin],
    },
    {
        pathToPage: 'some/path/2',
        pathToComponent: iframeLoader,
        roles: [Roles.User],
    },
];

export default configuration;

I'd like to add a new object at the end of the array using a shell script, so that my file looks likes this:

const configuration: ConfigData[] = [
    {
        pathToPage: 'some/path',
        pathToComponent: 'components/some-component',
        roles: [Roles.Admin],
    },
    {
        pathToPage: 'some/path/2',
        pathToComponent: iframeLoader,
        roles: [Roles.User],
    },
    {
        pathToPage: 'some/path/3',
        pathToComponent: iframeLoader,
        roles: [Roles.User, Roles.Admin],
    },
];

export default configuration;

Is that possible? If so, how do I do it?

1 Answer 1

1

awk -v addfile='cfg.add' '/^];$/{ system("cat " addfile) }1' cfg.js inserts the contents of file cfg.add just before the line in cfg.js consisting of ]; and prints the combined output to stdout.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.