abelljs/abell

Pass Abell.programInfo variable to .abell files with path configurations from abell.config.js

Closed this issue · 5 comments

Is your feature request related to a problem? Please describe.
Currently, there is no way to tell which is the outputPath set is abell.config.js from .abell file.

This could be neccessary to read/write files from .abell file.

Consider this example:

{{
  const fs = require('fs');
  const sass = require('node-sass');
    
  const outputCSS = sass.renderSync({
    file: 'theme/home.scss',
    outFile: '.debug/home.css'
  });

  fs.writeFileSync('.debug/home.css', outputCSS.css);
}}

<html>
<head>
  <link rel="stylesheet" href="home.css" />
</head>
<body>
  <div class="hello">
    <span>Hello, World!</span>
  </div>

  <span>Bonus Hello</span>
</body>
</html>

In this example we have to set .debug and theme explicitly. The .debug is the outputPath in abell serve.

Describe the solution you'd like
We can pass an object with:

  {
    themePath: 'theme',
    outputPath: 'dist',
    contentPath: 'content',
    task: 'build'
  }

The values I've mentioned are for example.
themePath: value of themePath from abell.config.js
outputPath: task === 'serve' ? '.debug' : value of outputPath from abell.config.js
contentPath: value of contentPath from abell.config.js
task: 'serve' or 'build' depending on which task it is running.

It should be added in a way that users can do

{{ Abell.programInfo.contentPath }} 

to access contentPath value.

Additional context

This is the file that deals with adding variables to .abell files. In programInfo variable you will most likely find all the information you need.

https://github.com/abelljs/abell/blob/main/src/utils/generate-site.js#L58-L66

I am uncertain about the name Abell.env. Before someone starts working on this, It is better to have a discussion about the name.

Hmm, can't we do this already via process.env? Why a separate API here?

I would rather implement .env and .env.local loading in abell like create-react-app does.

There is a sweet package for it as well: https://www.npmjs.com/package/dotenv-flow

Also, we should only allow prefixed env vars in abell due to security reasons: https://create-react-app.dev/docs/adding-custom-environment-variables . CRA uses REACT_APP prefix.

Oh nope I am not talking about process.env. process.env is directly possible in Abell without any extra thing. I am talking about having the basic information about abell in Abell variable.

This is one of the reasons I am uncertain about the Abell.env name since it can be confusing with process.env. Maybe something like Abell.configs but then people will expect it to have variables only from abell.config.js which is not the case since it can have a variables like task which will have serve or build value.

Another alternative will be Abell.programInfo which is also what we use internally.

So the options are

  1. Abell.env
  2. Abell.configs
  3. Abell.programInfo

Oh ok, I get it now. I didn't read the whole thing at first I guess.

I like Abell.programInfo

Let's go ahead with Abell.programInfo then.