Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Makefile #2

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ qpm
setupfile
coverage
src/node_path/node_modules
tmp
*.swp
tmp
133 changes: 133 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#export PATH=$PATH:/path/to/Qt/5.7/clang_64/bin
#check for qpm

.PHONY: test, build, run, clean, example/%

##
# use bash as shell
#
SHELL:=/bin/bash

##
# root directory (Makefile location)
#
WORKING_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))

##
# path to qt bins
#
QT:=$(HOME)/Qt/5.7/clang_64/bin

BUILD_DIR:=$(WORKING_DIR)/build
JS_DIR:=$(WORKING_DIR)/src/node_path

##
# find all relevant sources (sources that end with .js)
# and get their path relative to working dir
#
SOURCES_RELATIVE:= \
$(shell cd $(JS_DIR) && find src -type f -iname '*.js')

##
# save the relative sources to a new variable that holds al SOURCES
# with absolute paths
#
SOURCES:= \
$(foreach x, $(SOURCES_RELATIVE), $(JS_DIR)/$(x))

##
# these are our "object"-files - the files that are transpiled from
# es6 to es5
#
OBJECTS:= \
$(foreach x, $(SOURCES_RELATIVE), $(BUILD_DIR)/$(x))

##
# these are our "object"-files - the files that are transpiled from
# es6 to es5
#
INSTALLED_OBJECTS:= \
$(foreach x, $(shell cd $(JS_DIR)/src && find . -type f -iname '*.js'), $(JS_DIR)/lib/$(x)) \

export PATH:=$(QT):$(PATH)

all: build

build: $(BUILD_DIR)/quark.app
@echo "Build finished"

run: APP=$(WORKING_DIR)/example/default
run: build
@echo "Running app"
$(WORKING_DIR)/build/quark.app/Contents/MacOS/quark $(APP)/package.json

force:

example/%: force
make run APP=$@

clean:
rm -rf $(WORKING_DIR)/setupfile
rm -rf $(WORKING_DIR)/src/node_path/node_modules
cd $(BUILD_DIR) && make clean
rm -rf $(BUILD_DIR)
rm -rf $(JS_DIR)/lib
rm -rf $(JS_DIR)/node_modules

test: $(OBJECTS) $(BUILD_DIR)/node_modules
$(WORKING_DIR)/src/node_path/node_modules/.bin/istanbul cover --root $(BUILD_DIR)/src -x "**/__tests__/**" $(WORKING_DIR)/src/node_path/node_modules/.bin/_mocha $(shell find $(BUILD_DIR)/src -name "*Test.js" -not -path "*node_modules*") -- -R spec --require source-map-support/register


setup: $(WORKING_DIR)/setupfile

##
# builds the qt renderer app
#
$(BUILD_DIR)/quark.app: $(INSTALLED_OBJECTS) test
cd $(BUILD_DIR) && qmake ..
cd $(BUILD_DIR) && make

##
# adds the node modules to build dir
# for testing purposes
#
# TODO: hier müssen die files einzeln kopiert werden,
# damit der änderungen checkt
#
$(BUILD_DIR)/node_modules: $(WORKING_DIR)/setupfile
cp -r $(JS_DIR)/node_modules $@

##
# file to save setup status
#
$(WORKING_DIR)/setupfile:
mkdir -p $(BUILD_DIR)
cd $(WORKING_DIR)/src/node_path && npm install
qpm install
cd $(WORKING_DIR)/tools && make bootstrap
@echo "setup done" > $@

##
# this targets are necessary to not always trigger a rebuild of
# transpiled files, even if they exist. if the no-op is removed
# this will trigger a rebuild too
#
$(JS_DIR)/src/%.js:
@echo "" > /dev/null

##
# every transpiled file requires a matching source file
# to be created.
#
$(BUILD_DIR)/src/%.js: $(JS_DIR)/src/%.js $(WORKING_DIR)/setupfile
mkdir -p $(dir $@)
$(JS_DIR)/node_modules/.bin/eslint $<
$(JS_DIR)/node_modules/.bin/babel $< --out-file $@ --source-maps --presets es2017,es2016,node6 --plugins transform-runtime,transform-class-properties

##
# every destination file needs a transpiled
# source that is tested
#
$(JS_DIR)/lib/%.js: $(BUILD_DIR)/src/%.js
mkdir -p $(dir $@)
cp $< $@
2 changes: 1 addition & 1 deletion example/counter/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "quart-counter",
"name": "quark-counter",
"version": "0.1.0",
"main": "main.js"
}
44 changes: 44 additions & 0 deletions example/login/Menu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const { Statechart } = require("quark");

module.exports = Statechart.of({
type: {
scrollPosition: Number,
opacity: Number
},

OPEN: {
enter() {
return this.set("opacity", 1);
},

onClose() {
return this.changeState("CLOSED")
},

onLoggedOut: "onClose"
},

CLOSED: {
enter() {
return this.set("opacity", 0);
},

onOpen() {
return this.changeState("OPEN");
}
},

enter() {
return this
set("scrollPosition", 0)
.changeState("CLOSED");
},

onScroll(e) {
const state = e.scrollPosition.y > 50 && e.scrollPosition.y - this.get("scrollPosition") ? "OPEN" : "CLOSED";

return this
.set("scrollPosition", e.scrollPosition.y)
.changeState(state);
}
});
21 changes: 21 additions & 0 deletions example/login/Todos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = Statechart.of({
enter() {
return this.set([]);
},

onAdd(todo) {
return this.push(todo);
},

onRemove(todo) {
return this.filter(x => x.id === todo.id);
},

onUpdate(todo) {
return this.update(x => x.id === todo.id ? todo : x);
},

onSort(sort) {
return this.sort((a, b) => sort === DESCENDING ? a.id - b.id : b.id - a.id);
}
});
42 changes: 42 additions & 0 deletions example/login/User.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module.exports = Statechart.of({
enter() {
return this.changeState(„LOGGED_OUT“);
},

LOGGED_IN: {
enter() {
return this.set(„qml“, „loggedIN“);
},

logout() {
return this.changeState(„LOGGED_OUT“);
},

exit() {
return this.set(„user“, null);
}
},

onError(message) {
return this.set(„errorMessage“, message);
},

LOGGED_OUT: {
enter() {
return this.set(„qml“, „loggedOut“);
},

login({ id, password }, state) {
const success = this.state.find(x => x.id === id).password !== password;
const action = success ? „error“ : „loginSuccess“;

return success ? this.changeState(„LOGGED_OUT“, user) : this.trigger(„error“, „Error“);
},

onLogin: „login“,

exit(user) {
this.set(„user“, user);
}
}
});
42 changes: 42 additions & 0 deletions example/login/index.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import QtQuick 2.2
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3
import Quark 1.0

ApplicationWindow {
id: window
visible: true
width: 300

Gluon {
/*
This component holds the application state.
The property value holds the current value.
The slot dispatch can be called to emit an action.
*/
id: store
}

RowLayout {
anchors.fill: parent

Button {
anchors.left: window.left
text: "-"

onClicked: store.trigger("sub")
}
Label {
Layout.fillWidth: true
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
text: JSON.stringify(store.value.count);
}

Button {
text: "+"
onClicked: store.trigger("add")
}
}
}

20 changes: 20 additions & 0 deletions example/login/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const Quark = require("quark");
const path = require("path");
const Menu = require("./Menu");
const User = require("./User");
const Todos = require("./Todos");

/* const app = Quark.of({
qml: path.join(__dirname, "index.qml"),
initialState: { count: 0 },
intents: {
onSub: state => state.update("count", count => count - 1),
onAdd: state => state.update("count", count => count + 1)
}
});*/

const app = Quark.of({
menu: Menu,
user: User,
todos: Todos
});
6 changes: 6 additions & 0 deletions example/login/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "quark-login",
"version": "0.1.0",
"main": "main.js",
"initialQml": "index.qml"
}
Binary file removed example/todo/.main.js.swp
Binary file not shown.
Loading