Skip to content

Commit

Permalink
♻️ Replace old sputnik dependency with a new stages system
Browse files Browse the repository at this point in the history
  • Loading branch information
skerit committed Jan 14, 2024
1 parent ecbd730 commit b1f922b
Show file tree
Hide file tree
Showing 24 changed files with 1,912 additions and 1,044 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 1.4.0 (WIP)

* Implement new settings system
* Replace old `sputnik` dependency with a new stages system

## 1.3.22 (2023-12-21)

Expand Down
8 changes: 4 additions & 4 deletions lib/app/helper_model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ Model.setStatic(function getClass(model_name, allow_create, parent) {
*
* @author Jelle De Loecker <[email protected]>
* @since 1.0.0
* @version 1.1.2
* @version 1.4.0
*/
Model.setStatic(function setDocumentMethod(name, fnc, on_server) {

Expand All @@ -321,7 +321,7 @@ Model.setStatic(function setDocumentMethod(name, fnc, on_server) {
}

if (Blast.isNode) {
alchemy.sputnik.after('plugins', whenLoaded);
STAGES.afterStages('load_app.plugins', whenLoaded);
} else {
Blast.loaded(whenLoaded);
}
Expand All @@ -336,15 +336,15 @@ Model.setStatic(function setDocumentMethod(name, fnc, on_server) {
*
* @author Jelle De Loecker <[email protected]>
* @since 1.0.0
* @version 1.1.2
* @version 1.4.0
*/
Model.setStatic(function setDocumentProperty(key, getter, setter, on_server) {

var that = this,
args = arguments;

if (Blast.isNode) {
alchemy.sputnik.after('plugins', whenLoaded);
STAGES.afterStages('load_app.plugins', whenLoaded);
} else {
Blast.loaded(whenLoaded);
}
Expand Down
249 changes: 12 additions & 237 deletions lib/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,15 @@
'use strict';

const libpath = require('path');
let starting;

/**
* Load Protoblast in the prototype-modifying mode.
* This is the backbone of Alchemy.
*/
require('protoblast')(true);

/**
* Resolve a core path
*
* @author Jelle De Loecker <[email protected]>
* @since 1.4.0
* @version 1.4.0
*/
function resolveCorePath(...args) {
return libpath.resolve(PATH_CORE, ...args);
}

/**
* Require a core path
*
* @author Jelle De Loecker <[email protected]>
* @since 1.4.0
* @version 1.4.0
*/
function requireCorePath(...args) {
return require(resolveCorePath(...args));
}

/**
* Define DEFINE and constants
* Define global constants and require methods
*/
require('./init/constants');
require('./init_scripts/constants');

/**
* Alchemy's Base class (from which all other classes inherit)
Expand All @@ -47,224 +22,24 @@ requireCorePath('core', 'base');
requireCorePath('core', 'client_base');

/**
* Load the setting class
*/
requireCorePath('core', 'setting.js');

/**
* Load the actual settings
*/
requireCorePath('init', 'settings.js');

/**
* Define alchemy class and instance
*/
requireCorePath('core', 'alchemy');

/**
* Get all the languages by their locale
*/
requireCorePath('init', 'languages');

/**
* Require basic functions
*/
requireCorePath('init', 'functions');

/**
* Require load functions
*/
requireCorePath('init', 'load_functions');

/**
* Pre-load basic requirements
*/
requireCorePath('init', 'preload_modules');

/**
* Set up file change watchers for development
*/
requireCorePath('init', 'devwatch');

/**
* The migration class
*/
requireCorePath('class', 'migration');

const CLIENT_HAWKEJS_OPTIONS = {

// Do not load on the server
server : false,

// Turn it into a commonjs load
make_commonjs: true,

// The arguments to add to the wrapper function
arguments : 'hawkejs'
};

const SERVER_HAWKEJS_OPTIONS = {

// Also load on the server
server : true,

// Turn it into a commonjs load
make_commonjs: true,

// The arguments to add to the wrapper function
arguments : 'hawkejs'
};

/**
* Require the base class on the client side too
*
* @author Jelle De Loecker <[email protected]>
* @since 0.3.0
* @version 1.1.0
*/
alchemy.hawkejs.load(resolveCorePath('core', 'base.js'), CLIENT_HAWKEJS_OPTIONS);

/**
* Require the client_base class on the client side too
*
* @author Jelle De Loecker <[email protected]>
* @since 1.0.0
* @version 1.1.0
*/
alchemy.hawkejs.load(resolveCorePath('core', 'client_base.js'), CLIENT_HAWKEJS_OPTIONS);

/**
* Require the error class
*
* @author Jelle De Loecker <[email protected]>
* @since 1.1.0
* @version 1.1.0
*/
alchemy.hawkejs.load(resolveCorePath('class', 'error.js'), SERVER_HAWKEJS_OPTIONS);

/**
* Require the client_alchemy class on the client side
*
* @author Jelle De Loecker <[email protected]>
* @since 1.0.5
* @version 1.1.0
*/
alchemy.hawkejs.load(resolveCorePath('core', 'client_alchemy.js'), SERVER_HAWKEJS_OPTIONS);

/**
* Require the path_evaluator class
*
* @author Jelle De Loecker <[email protected]>
* @since 1.1.0
* @version 1.1.0
*/
alchemy.hawkejs.load(resolveCorePath('class', 'path_evaluator.js'), SERVER_HAWKEJS_OPTIONS);

/**
* Require the field_value class
*
* @author Jelle De Loecker <[email protected]>
* @since 1.1.0
* @version 1.1.0
*/
alchemy.hawkejs.load(resolveCorePath('class', 'field_value.js'), SERVER_HAWKEJS_OPTIONS);

/**
* Require the path_definition class on the client side too
*
* @author Jelle De Loecker <[email protected]>
* @since 1.0.0
* @version 1.1.0
* Load the stages classes
*/
alchemy.hawkejs.load(resolveCorePath('class', 'path_definition.js'), CLIENT_HAWKEJS_OPTIONS);
alchemy.hawkejs.load(resolveCorePath('class', 'path_param_definition.js'), CLIENT_HAWKEJS_OPTIONS);
requireCorePath('core', 'stages.js');

/**
* Require the element class on the client side too
* Define the Stages instance
*
* @author Jelle De Loecker <[email protected]>
* @since 1.0.0
* @version 1.1.0
*/
alchemy.hawkejs.load(resolveCorePath('class', 'element.js'), CLIENT_HAWKEJS_OPTIONS);

/**
* Require the helper class on the client side too
*
* @author Jelle De Loecker <[email protected]>
* @since 1.0.0
* @version 1.1.0
*/
alchemy.hawkejs.load(resolveCorePath('class', 'helper.js'), CLIENT_HAWKEJS_OPTIONS);

/**
* Require the datasource class on the client side too
*
* @author Jelle De Loecker <[email protected]>
* @since 1.1.0
* @version 1.1.0
*/
alchemy.hawkejs.load(resolveCorePath('class', 'datasource.js'), CLIENT_HAWKEJS_OPTIONS);

/**
* Require the field class on the client side too
*
* @author Jelle De Loecker <[email protected]>
* @since 1.1.0
* @version 1.1.0
*/
alchemy.hawkejs.load(resolveCorePath('class', 'field.js'), CLIENT_HAWKEJS_OPTIONS);

/**
* Require the schema_client class on the client side too
* @since 1.4.0
* @version 1.4.0
*
* @author Jelle De Loecker <[email protected]>
* @since 1.1.0
* @version 1.1.0
*/
alchemy.hawkejs.load(resolveCorePath('class', 'schema_client.js'), CLIENT_HAWKEJS_OPTIONS);

/**
* Set up routing functions
*/
alchemy.useOnce(resolveCorePath('core', 'routing.js'));

/**
* Set up middleware functions
*/
alchemy.useOnce(resolveCorePath('core', 'middleware.js'));

/**
* Load socket.io code
*/
alchemy.useOnce(resolveCorePath('core', 'socket.js'));

/**
* Load discovery code
*/
alchemy.useOnce(resolveCorePath('core', 'discovery.js'));

/**
* Load inode classes
* @type {Alchemy.Stages.Stage}
*/
alchemy.useOnce(resolveCorePath('class', 'inode.js'));
alchemy.useOnce(resolveCorePath('class', 'inode_file.js'));
alchemy.useOnce(resolveCorePath('class', 'inode_dir.js'));
alchemy.useOnce(resolveCorePath('class', 'inode_list.js'));
DEFINE('STAGES', new Classes.Alchemy.Stages.Stage('root'));

/**
* Load in all classes
* Start the stages script
*/
alchemy.usePath(libpath.resolve(__dirname, 'class'), {modular: false});
requireCorePath('init_scripts', 'stages.js');

// Load the base bootstrap file
try {
alchemy.useOnce(libpath.resolve(PATH_ROOT, 'app', 'config', 'bootstrap.js'));
} catch (err) {
if (err.message.indexOf('Cannot find') === -1) {
alchemy.printLog(alchemy.WARNING, 'Could not load app bootstrap file');
throw err;
} else {
alchemy.printLog(alchemy.SEVERE, 'Could not load config bootstrap file', {err: err});
}
}
module.exports = STAGES;
4 changes: 2 additions & 2 deletions lib/class/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ Schema.setMethod(function eachAlternateIndex(data, fnc) {
*
* @author Jelle De Loecker <[email protected]>
* @since 1.1.0
* @version 1.2.0
* @version 1.4.0
*
* @return {Pledge}
*/
Expand All @@ -214,7 +214,7 @@ Schema.setMethod(function getDatasource() {
that.afterOnce('has_model_class', next);
}, function waitForDatasources(next) {

alchemy.sputnik.after('datasources', function afterDs() {
STAGES.afterStages('datasource', function afterDs() {

let datasource;

Expand Down
Loading

0 comments on commit b1f922b

Please sign in to comment.