Skip to content

Commit

Permalink
fixed render function
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinmcfarland committed Aug 7, 2024
1 parent 7745749 commit c065ffb
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 22 deletions.
8 changes: 4 additions & 4 deletions .jsbeautifyrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// {
// "brace_style": "collapse,preserve-inline",
// "indent_with_tabs": true
// }
{
"brace_style": "collapse,preserve-inline",
"indent_with_tabs": true
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ interface Config {

- ### Set or update theme data

`mole.theme( string | object ): void`
`mole.theme( data ): void`

#### Parameters

Expand Down
18 changes: 11 additions & 7 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -158664,23 +158664,27 @@ var Data_default = data;

// src/lib/Theme.js
var import_lodash2 = __toESM(require_lodash2(), 1);
var import_jsonnet = __toESM(require_lib(), 1);
var jsonnet;
try {
jsonnet = await Promise.resolve().then(() => __toESM(require_lib(), 1));
} catch (err2) {
}
var RE_JS = /([a-zA-Z0-9\s_\\.\-\(\):])+(.js)$/im;
var RE_JSONNET = /([a-zA-Z0-9\s_\\.\-\(\):])+(.jsonnet)$/im;
var Theme = class {
constructor() {
return this;
}
set(value, config2) {
async set(value, config2) {
let result;
if (is_default.what(value) === "path" || is_default.what(value) === "file" || is_default.what(value) === "dir") {
let path3 = getThemePath(config2, value);
if (RE_JS.test(path3)) {
result = __require(file);
result = (await import(file)).default;
}
if (RE_JSONNET.test(path3)) {
if (jsonnet && RE_JSONNET.test(path3)) {
const getFile = fs2.readFileSync(path3).toString();
const jsonnetVm = new import_jsonnet.default.Jsonnet();
const jsonnetVm = new jsonnet.Jsonnet();
result = jsonnetVm.eval(getFile);
jsonnetVm.destroy();
}
Expand Down Expand Up @@ -158749,7 +158753,7 @@ var Config = class {
});
result = normaliseOutputs(result);
if (result.theme) {
Theme_default.set(result.rootOnly + result.theme, result);
await Theme_default.set(result.rootOnly + result.theme, result);
}
Object.assign(this, result);
}
Expand Down Expand Up @@ -159097,6 +159101,7 @@ var Mole = class {
});
}
async render() {
await this._outputs();
let files = [];
for (let output2 of things) {
output2 = await output2;
Expand All @@ -159109,7 +159114,6 @@ var Mole = class {
return files;
}
async build() {
await this._outputs();
for (let file3 of await this.render()) {
import_fs_extra3.default.outputFile(file3.path, file3.content, function(err2) {
if (err2) console.log(err2);
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
],
"license": "MIT",
"devDependencies": {
"@unboundedsystems/jsonnet": "^0.9.4-rc6",
"babel-plugin-rewire": "^1.2.0",
"common-tags": "^1.8.0",
"esbuild": "^0.23.0",
Expand All @@ -35,6 +34,9 @@
"rewire": "^7.0.0",
"typescript": "^5.5.4"
},
"optionalDependencies": {
"@unboundedsystems/jsonnet": "^0.9.4-rc6"
},
"dependencies": {
"@babel/preset-env": "^7.25.3"
},
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Config {

// If a theme is specified in the config input then we set the theme
if (result.theme) {
theme.set(result.rootOnly + result.theme, result)
await theme.set(result.rootOnly + result.theme, result)
}
// We assign the new properties to the Config object
Object.assign(this, result)
Expand Down
8 changes: 7 additions & 1 deletion src/lib/Mole.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,27 @@ class Mole {

}
async render() {
await this._outputs()

let files = []

for (let output of things) {

output = await output



let file = {
content: nunjucksEnv.renderString(output.template, output.model),
path: output.path
}
files.push(file)

}

return files
}
async build() {
await this._outputs()

for (let file of await this.render()) {

Expand Down
16 changes: 9 additions & 7 deletions src/lib/Theme.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import fs from 'fs'
// import jsonnet from '@unboundedsystems/jsonnet'
import glob from 'glob'
import is from '../util/is.js'
import data from './Data.js'
import merge from 'lodash.merge'

import jsonnet from '@unboundedsystems/jsonnet';
let jsonnet;

// const jsonnet = require('@unboundedsystems/jsonnet');
try {
jsonnet = await import('@unboundedsystems/jsonnet');
} catch (err) {
// console.log('Optional library not installed. Some features may not be available.');
}

const RE_JS = /([a-zA-Z0-9\s_\\.\-\(\):])+(.js)$/im
const RE_JSONNET = /([a-zA-Z0-9\s_\\.\-\(\):])+(.jsonnet)$/im
Expand All @@ -18,7 +21,7 @@ class Theme {
constructor() {
return this
}
set(value, config) {
async set(value, config) {

// Parses the theme
let result
Expand All @@ -28,10 +31,9 @@ class Theme {
let path = getThemePath(config, value)

if (RE_JS.test(path)) {
result = require(file)

result = (await import(file)).default
}
if (RE_JSONNET.test(path)) {
if (jsonnet && RE_JSONNET.test(path)) {

const getFile = fs.readFileSync(path).toString()

Expand Down

0 comments on commit c065ffb

Please sign in to comment.