Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F11722332
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/Makefile b/Makefile
index dc3e41a..c87cb67 100644
--- a/Makefile
+++ b/Makefile
@@ -1,31 +1,31 @@
COMPONENTS_DIR=/usr/local/share/upsection
BIN_DIR=/usr/local/bin
MKDIR=mkdir -p
INSTALL_BIN=install -m 755
INSTALL_SHARE=install -m 644
# -------------------------------------------------------------
# Main targets
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
all:
# Nothing to build
install:
${MKDIR} ${COMPONENTS_DIR} ${BIN_DIR}
${INSTALL_BIN} src/upsection.py ${BIN_DIR}/upsection
${INSTALL_SHARE} components/* ${COMPONENTS_DIR}
# -------------------------------------------------------------
# Development and maintenance targets
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
test:
cd tests/site && \
cp ../../config.yml . && \
cp -Rp ../../template/* . && \
- make
+ PACKAGE_TEMPLATE=../../components/package-template.json UPSECTION=../../src/upsection.py make
publish:
upsection package.json
diff --git a/src/upsection.py b/src/upsection.py
index 60b0eb2..d87aa99 100755
--- a/src/upsection.py
+++ b/src/upsection.py
@@ -1,119 +1,127 @@
#!/usr/bin/env python3
import json
+import os
import sys
import yaml
# -------------------------------------------------------------
# Available builders configuration
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-PACKAGE_TEMPLATE = "/usr/local/share/upsection/package-template.json"
+DEFAULT_PACKAGE_TEMPLATE_PATH = "/usr/local/share/upsection/package-template.json"
+
+
+def get_package_template_path():
+ try:
+ return os.environ["PACKAGE_TEMPLATE"]
+ except KeyError:
+ return DEFAULT_PACKAGE_TEMPLATE_PATH
def get_builders():
return {
".browserslistrc": build_browserslistrc,
"package.json": build_package,
}
# -------------------------------------------------------------
# Build package.json
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def build_package():
- with open(PACKAGE_TEMPLATE) as fd:
+ with open(get_package_template_path()) as fd:
package_template = json.load(fd)
package = {
**package_template,
**get_package_config(),
}
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)
diff --git a/template/Makefile b/template/Makefile
index c5c7b77..f8f2afe 100644
--- a/template/Makefile
+++ b/template/Makefile
@@ -1,38 +1,39 @@
CP=cp
RM=rm -rf
SOURCE=/usr/local/share/upsection
+UPSECTION ?= upsection
# -------------------------------------------------------------
# Main targets
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ALL_TARGETS=package.json .babelrc .browserslistrc gulpfile.babel.js node_modules
CLEAN_TARGETS=dist/ ${ALL_TARGETS}
all: ${ALL_TARGETS}
npm run build
dev: ${ALL_TARGETS}
npm start
clean:
${RM} ${CLEAN_TARGETS}
# -------------------------------------------------------------
# Individual targets
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
package.json:
- upsection package.json
+ ${UPSECTION} package.json
.browserslistrc:
- upsection .browserslistrc
+ ${UPSECTION} .browserslistrc
node_modules: package.json
npm install
.babelrc:
${CP} ${SOURCE}/babelrc .babelrc
gulpfile.babel.js:
${CP} ${SOURCE}/gulpfile.js gulpfile.babel.js
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Sep 18, 02:07 (1 d, 19 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2986192
Default Alt Text
(5 KB)
Attached To
Mode
rUPSECTION Upsection
Attached
Detach File
Event Timeline
Log In to Comment