ara-cli icon indicating copy to clipboard operation
ara-cli copied to clipboard

Code Generators should have a central place for naming Nova Services

Open tsukhu opened this issue 5 years ago • 2 comments

Currently if we generate the projects using the CLI for example

ara new:nova novas/global -t vue

There are two files we need to modify in case we need to change the name of the nova service from Example (if we are enabling SSR as well)

  • client.js
  • index.js

There is a change that the developer may miss out modifying the name in all places.

Possible Solution

Add a common place where the name is specified for example

constants.js

const NOVA_NAME = 'VueNovaMFE';

export default NOVA_NAME;

Now in each of the files index.js and client.js

include it

import NOVA_NAME from './constants';

The index.js could look like this

hypernova({
  devMode: process.env.NODE_ENV !== 'production',
  getComponent(name) {
    if (name === NOVA_NAME) {
      return renderVue(name, Vue.extend(MonthlySalesChart));
    }
  },
  port: process.env.PORT || 3000,

  createApplication() {
    const app = express();

    app.use('/public', express.static(path.join(process.cwd(), 'dist')));

    return app;
  },
});

Similarly the client.js could look like this

import NOVA_NAME from './constants';

const render = (name, { node, data }) => {
  if (name === NOVA_NAME) {
    return mountComponent(Vue.extend(MonthlySalesChart), node, data);
  }
};

document.addEventListener('NovaMount', ({ detail }) => {
  const { name, id } = detail;

  const payload = loadById(name, id);

  if (payload) {
    render(name, payload);
  }
});

load(NOVA_NAME).forEach(render.bind(null, NOVA_NAME));

tsukhu avatar Apr 30 '20 07:04 tsukhu

The other way is to pick it from package.json and then apply it via env properties .. but it will add a lot of unnecessary code.

@marconi1992 if you find it ok , I can help in contributing the fix.

tsukhu avatar Apr 30 '20 07:04 tsukhu

@tsukhu It's a good idea, It's simple and helpful. Feel free to fix them, I'll really appreciate it.

marconi1992 avatar Apr 30 '20 14:04 marconi1992