diff --git a/README.md b/README.md index d4b00e0..c02830f 100644 --- a/README.md +++ b/README.md @@ -1,94 +1,96 @@ Upsection. Generate static sites. ================================= Several Nasqueron static sites use the ZURB Template for Foundation for Sites. This command allows to maintain in sites repository an unified configuration stored in config.yml, and generate Node package, browserslists or Gulp files. The main expected benefit is to maintain the Node dependencies in a central repository and so avoid to upgrade package.json everywhere. Installation ------------ To install the `upsection` command and needed resources, use `make install`. How to use on an existing site ------------------------------ Go to the site repository directory and run `make`. That will take care to call upsection to generate files and then to call npm to install Node dependencies and run the gulp script. If successful, you've a full build of the site in the dist/ directory. To use in development mode, use `make dev`. How to convert a site? ---------------------- 1. Update the keys of config.yml to adhere to Upsection conventions 2. Move package.json metadata unique to your project in config.yml 3. Run `upsection package.json` and compare with legacy package.json 4. Remove from your repo package.json, gulpfile.babel.js and .browsers 5. Add to your repo `template/Makefile` How to start a new project? --------------------------- 1. Copy the template directory for your site 2. Generate a configuration file from the .in provided If we would automate the tasks, that would give for https://awesome.nasqueron.org: ``` cp -R template /path/to/your-awesome-site cd /path/to/your-awesome-site git init . sed -i s/%%SUBDOMAIN%%/awesome/g config.yml.in > config.yml rm config.yml.in # Edit config.yml make ``` The config.yml.in file offers %%SUBDOMAIN%% for any automation need. How to regenerate the files on an existing site? ------------------------------------------------ Use `make clean all` if you want a fresh node_modules folder. To keep node_modules folder, simply run `upsection` again. If you updated dependencies, `npm install` works (or yarn). To regenerate only one file, you can use `upsection .browserslistrc`. What this script doesn't do? ---------------------------- Upsection takes care of the installation and maintenance of the build mechanism but not of the maintenance of the content and assets. As such, upsection doesn't propagate changes in template folder, so for e.g. it won't upgrade the SCSS for a Foundation 6.3 site into a 6.7 version. How to upgrade dependencies in upsection repository? ---------------------------------------------------- For the Node dependencies, edit `components/package-template.json`. +Then run `make publish` to update the repository reference package. +That last step allows to expose dependencies to security trackers. When a new Foundation version is released, changes to templates/assets/ are expected. The following files can be normally copied as is from the Foundation for sites repository: - scss/settings/_settings.scss -> assets/scss/_settings.scss - js/entries/foundation.js -> assets/js/lib/foundation-explicit-pieces.js Check also `assets/scss/app.css` if a component is added or removed (e.g. foundation-slider). diff --git a/package.json b/package.json new file mode 100644 index 0000000..85ba6cc --- /dev/null +++ b/package.json @@ -0,0 +1,55 @@ +{ + "main": "gulpfile.babel.js", + "scripts": { + "start": "gulp", + "build": "gulp build --production" + }, + "dependencies": { + "foundation-sites": "~6.4.1", + "jquery": ">=3.0.0", + "motion-ui": "^2.0.3", + "what-input": "^4.1.3" + }, + "devDependencies": { + "@babel/core": "^7.1.2", + "@babel/preset-env": "^7.1.0", + "@babel/register": "^7.0.0", + "autoprefixer": "^9.1.5", + "babel-loader": "^8.0.4", + "browser-sync": "^2.10.0", + "gulp": "^4.0.0", + "gulp-babel": "^8.0.0", + "gulp-clean-css": "^3.3.1", + "gulp-cli": "^2.0.1", + "gulp-concat": "^2.5.2", + "gulp-extname": "^0.2.0", + "gulp-if": "^2.0.0", + "gulp-imagemin": "^7.1.0", + "gulp-load-plugins": "^1.1.0", + "gulp-postcss": "^8.0.0", + "gulp-sass": "^5.0.0", + "gulp-sourcemaps": "^2.6.4", + "gulp-uglify": "^3.0.1", + "js-yaml": "^3.4.6", + "panini": "^1.3.0", + "rimraf": "^2.4.3", + "sass": "^1.41.1", + "style-sherpa": "^1.0.0", + "uncss": "^0.16.2", + "vinyl-named": "^1.1.0", + "webpack": "^5.53.0", + "webpack-stream": "^7.0.0", + "yargs": "^17.1.1" + }, + "bugs": { + "url": "https://devcentral.nasqueron.org/" + }, + "private": true, + "name": "nasqueron-upsection-test", + "version": "0.1.0", + "description": "Allow to test if we can build a static site", + "repository": { + "type": "git", + "url": "https://devcentral.nasqueron.org/source/upsection.git" + } +} diff --git a/src/upsection.py b/src/upsection.py index 146a25a..17e9a7c 100755 --- a/src/upsection.py +++ b/src/upsection.py @@ -1,119 +1,119 @@ #!/usr/bin/env python3 import json import sys import yaml # ------------------------------------------------------------- # Available builders configuration # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - PACKAGE_TEMPLATE = "/usr/local/share/upsection/package-template.json" def get_builders(): return { ".browserslistrc": build_browserslistrc, "package.json": build_package, } # ------------------------------------------------------------- # Build package.json # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - def build_package(): with open(PACKAGE_TEMPLATE) as fd: package_template = json.load(fd) package = { **package_template, **get_package_config() } - return json.dumps(package) + return json.dumps(package, sort_keys=False, indent=4) + "\n" def get_package_config(): package_metadata = app['config']['package'] repository = get_repository(package_metadata['repository_name']) del package_metadata['repository_name'] return { **package_metadata, "repository": repository, } # ------------------------------------------------------------- # Build .browserslistrc # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - def build_browserslistrc(): return "# Browsers that we support\n" + get_browsers_list() + "\n" def get_browsers_list(): return "\n".join(app['config']['tasks']['autoprefixer']['browsers']) def get_repository(name): return { "type": "git", "url": "https://devcentral.nasqueron.org/source/" + name + ".git" } # ------------------------------------------------------------- # Application entry point # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - def initialize_app(): with open('config.yml') as fd: config = yaml.safe_load(fd) return { 'config': config, 'builders': get_builders(), } def run(args): if len(args) == 1: build_all() return build_some(args[1:]) def build_all(): for file_to_build, builder in app['builders'].items(): with open(file_to_build, 'w') as fd: fd.write(builder()) def build_some(files_to_build): for file_to_build in files_to_build: build(file_to_build) def build(file_to_build): try: content = app['builders'][file_to_build]() except KeyError: print("Don't know how to generate", file_to_build, file=sys.stderr) return with open(file_to_build, 'w') as fd: fd.write(content) if __name__ == "__main__": app = initialize_app() run(sys.argv)