Skip to content

Commit

Permalink
bin/less -> gulp
Browse files Browse the repository at this point in the history
  • Loading branch information
smotornyuk committed Jan 8, 2020
1 parent fe604ba commit 013859b
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 75 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ ckan_deb/DEBIAN/prerm

# node.js
node_modules/
package-lock.json

# docker
contrib/docker/.env
39 changes: 0 additions & 39 deletions bin/less

This file was deleted.

29 changes: 8 additions & 21 deletions ckan/cli/less.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,7 @@
name=u'less',
short_help=u'Compile all root less documents into their CSS counterparts')
def less():
command = (u'npm', u'bin')
process = subprocess.Popen(
command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True)
output = process.communicate()
directory = output[0].strip()
if not directory:
error_shout(u'Command "{}" returned nothing. Check that npm is '
u'installed.'.format(u' '.join(command)))
less_bin = os.path.join(directory, u'lessc')
command = (u'npm', u'run', u'build')

public = config.get(u'ckan.base_public_folder')

Expand All @@ -73,23 +62,21 @@ def less():
f = open(custom_less, u'w')
f.write(_custom_css[color])
f.close()
_compile_less(root, less_bin, color)
_compile_less(root, command, color)
f = open(custom_less, u'w')
f.write(u'// This file is needed in order for ./bin/less to '
f.write(u'// This file is needed in order for `gulp build` to '
u'compile in less 1.3.1+\n')
f.close()
_compile_less(root, less_bin, u'main')
_compile_less(root, command, u'main')


def _compile_less(root, less_bin, color):
def _compile_less(root, command, color):
click.echo(u'compile {}.css'.format(color))
main_less = os.path.join(root, u'less', u'main.less')
main_css = os.path.join(root, u'css', u'{}.css'.format(color))
command = (less_bin, main_less, main_css)
command = command + (u'--', u'-' + color)

process = subprocess.Popen(
command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True)
stderr=subprocess.PIPE)
output = process.communicate()
click.echo(output)
2 changes: 1 addition & 1 deletion ckan/lib/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1889,7 +1889,7 @@ def less(self):
f.close()
self.compile_less(root, less_bin, color)
f = open(custom_less, 'w')
f.write('// This file is needed in order for ./bin/less to compile in less 1.3.1+\n')
f.write('// This file is needed in order for `gulp build` to compile in less 1.3.1+\n')
f.close()
self.compile_less(root, less_bin, 'main')

Expand Down
22 changes: 10 additions & 12 deletions doc/contributing/frontend/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Instructions for installing |nodejs| can be found on the |nodejs| `website
On Ubuntu, run the following to install |nodejs| official repository and the node
package::

curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
curl -sL https://deb.nodesource.com/setup_13.x | sudo -E bash -
sudo apt-get install -y nodejs

.. note:: If you use the package on the default Ubuntu repositories (eg ``sudo apt-get install nodejs``),
Expand All @@ -34,22 +34,18 @@ package::

ln -s /usr/bin/nodejs /usr/bin/node

Also npm (the |nodejs| package manager) needs to be installed separately::

sudo apt-get install npm

For more information, refer to the |nodejs| `instructions
<https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions>`_.

Less can then be installed via the node package manager (npm).
We also use ``nodewatch`` to make our Less compiler a watcher
Dependencies can then be installed via the node package manager (npm).
We use ``gulp`` to make our Less compiler a watcher
style script.

``cd`` into the CKAN source folder (eg |virtualenv|/src/ckan ) and run:

::

$ npm install [email protected] nodewatch
$ npm install


You may need to use ``sudo`` depending on your CKAN install type.
Expand Down Expand Up @@ -127,11 +123,13 @@ before beginning development by running:

::

$ ./bin/less
$ npm run watch

This will watch for changes to all of the less files and automatically
rebuild the CSS for you. To quit the script press ``ctrl-c``. There is also
``--production`` flag for compiling the production ``main.css``.
rebuild the CSS for you. To quit the script press ``ctrl-c``. If you
need sourcemaps for debugging, set `DEBUG` environment variable. I.e::

$ DEBUG=1 npm run watch

There are many Less files which attempt to group the styles in useful
groups. The main two are:
Expand All @@ -146,7 +144,7 @@ ckan.less:

.. Note::
Whenever a CSS change effects ``main.less`` it's important than after
the merge into master that a ``$ ./bin/less --production`` should be
the merge into master that a ``$ npm run build`` should be
run and commited.

There is a basic pattern primer available at:
Expand Down
2 changes: 1 addition & 1 deletion doc/contributing/release-process.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Turn this file into a github issue with a checklist using this command::
cherry-picked from master, the less compiling command needs to be run on
the release branch. This will update the ``main.css`` file::

./bin/less --production
npm run build
git commit -am "Rebuild CSS"
git push

Expand Down
2 changes: 1 addition & 1 deletion doc/maintaining/installing/install-from-source.rst
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ AttributeError: 'module' object has no attribute 'css/main.debug.css'
This error is likely to show up when `debug` is set to `True`. To fix this
error, install frontend dependencies. See :doc:`/contributing/frontend/index`.

After installing the dependencies, run ``bin/less`` and then start paster server
After installing the dependencies, run ``npm run build`` and then start paster server
again.

If you do not want to compile CSS, you can also copy the main.css to
Expand Down
33 changes: 33 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const path = require("path");
const { src, watch, dest } = require("gulp");
const less = require("gulp-less");
const if_ = require("gulp-if");
const sourcemaps = require("gulp-sourcemaps");
const rename = require("gulp-rename");

console.log(process.argv);
const with_sourcemaps = () => !!process.env.DEBUG;
const renamer = path => {
if (process.argv[3]) {
path.basename = process.argv[3].slice(1);
}
return path;
};

const build = () =>
src(__dirname + "/ckan/public/base/less/main.less")
.pipe(if_(with_sourcemaps(), sourcemaps.init()))
.pipe(less())
.pipe(if_(with_sourcemaps(), sourcemaps.write()))
.pipe(rename(renamer))
.pipe(dest(__dirname + "/ckan/public/base/css/"));

const watchSource = () =>
watch(
__dirname + "/ckan/public/base/less/**/*.less",
{ ignoreInitial: false },
build
);

exports.build = build;
exports.watch = watchSource;
29 changes: 29 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "ckan",
"version": "1.0.0",
"description": "CKAN: The Open Source Data Portal Software ==========================================",
"dependencies": {
"gulp": "^4.0.2",
"gulp-if": "^3.0.0",
"gulp-less": "^4.0.1",
"gulp-rename": "^2.0.0",
"gulp-sourcemaps": "^2.6.5"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"watch": "gulp watch",
"build": "gulp build"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ckan/ckan.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/ckan/ckan/issues"
},
"homepage": "https://github.com/ckan/ckan#readme"
}

0 comments on commit 013859b

Please sign in to comment.