Browse Source

fix: Common scss options for theme generator and rollup scss

version-14
Faris Ansari 6 years ago
parent
commit
698bf208ab
3 changed files with 32 additions and 20 deletions
  1. +7
    -12
      generate_bootstrap_theme.js
  2. +11
    -7
      rollup/config.js
  3. +14
    -1
      rollup/rollup.utils.js

+ 7
- 12
generate_bootstrap_theme.js View File

@@ -1,22 +1,16 @@
const sass = require('node-sass'); const sass = require('node-sass');
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
const { get_public_path } = require('./rollup/rollup.utils');
const { apps_list, get_app_path, get_public_path, get_options_for_scss } = require('./rollup/rollup.utils');


const node_modules_path = path.resolve(get_public_path('frappe'), 'node_modules');
const scss_path = path.resolve(get_public_path('frappe'), 'scss');
const website_theme_path = path.resolve(get_public_path('frappe'), 'website_theme');
const custom_theme_name = process.argv[2];
const output_path = process.argv[2];


let scss_content = process.argv[3]; let scss_content = process.argv[3];
scss_content = scss_content.replace(/\\n/g, '\n'); scss_content = scss_content.replace(/\\n/g, '\n');


sass.render({ sass.render({
data: scss_content, data: scss_content,
includePaths: [
node_modules_path,
scss_path
],
outputStyle: 'compact',
importer: function(url) { importer: function(url) {
if (url.startsWith('~')) { if (url.startsWith('~')) {
// strip ~ so that it can resolve from node_modules // strip ~ so that it can resolve from node_modules
@@ -28,16 +22,17 @@ sass.render({
return { return {
file: url file: url
}; };
}
},
...get_options_for_scss()
}, function(err, result) { }, function(err, result) {
if (err) { if (err) {
console.error(err.formatted); // eslint-disable-line console.error(err.formatted); // eslint-disable-line
return; return;
} }


fs.writeFile(path.resolve(website_theme_path, custom_theme_name), result.css, function(err) {
fs.writeFile(output_path, result.css, function(err) {
if (!err) { if (!err) {
console.log(custom_theme_name); // eslint-disable-line
console.log(output_path); // eslint-disable-line
} }
}); });
}); });

+ 11
- 7
rollup/config.js View File

@@ -20,7 +20,8 @@ const {
bench_path, bench_path,
get_public_path, get_public_path,
get_app_path, get_app_path,
get_build_json
get_build_json,
get_options_for_scss
} = require('./rollup.utils'); } = require('./rollup.utils');


function get_rollup_options(output_file, input_files) { function get_rollup_options(output_file, input_files) {
@@ -115,12 +116,15 @@ function get_rollup_options_for_css(output_file, input_files) {
// less -> css // less -> css
postcss({ postcss({
extract: output_path, extract: output_path,
use: [['less', {
// import other less/css files starting from these folders
paths: [
path.resolve(get_public_path('frappe'), 'less')
]
}], 'sass'],
use: [
['less', {
// import other less/css files starting from these folders
paths: [
path.resolve(get_public_path('frappe'), 'less')
]
}],
['sass', get_options_for_scss()]
],
include: [ include: [
path.resolve(bench_path, '**/*.less'), path.resolve(bench_path, '**/*.less'),
path.resolve(bench_path, '**/*.scss'), path.resolve(bench_path, '**/*.scss'),


+ 14
- 1
rollup/rollup.utils.js View File

@@ -69,6 +69,18 @@ function run_serially(tasks) {


const get_app_path = app => app_paths[app]; const get_app_path = app => app_paths[app];


const get_options_for_scss = () => {
const node_modules_path = path.resolve(get_app_path('frappe'), '..', 'node_modules');
const app_paths = apps_list.map(get_app_path).map(app_path => path.resolve(app_path, '..'));

return {
includePaths: [
node_modules_path,
...app_paths
]
}
}

module.exports = { module.exports = {
sites_path, sites_path,
bundle_map, bundle_map,
@@ -80,5 +92,6 @@ module.exports = {
assets_path, assets_path,
bench_path, bench_path,
delete_file, delete_file,
run_serially
run_serially,
get_options_for_scss
}; };

Loading…
Cancel
Save