Skip to content

Commit

Permalink
✨ ENVIRONMENT refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
cookiengineer committed May 15, 2020
1 parent bb3b848 commit 0d4e391
Show file tree
Hide file tree
Showing 63 changed files with 1,203 additions and 815 deletions.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,2 +1,3 @@
/build
/node_modules
/package-lock.json

19 changes: 17 additions & 2 deletions base/.eslintrc.json
Expand Up @@ -10,8 +10,23 @@
"sourceType": "module"
},
"overrides": [{
"files": [ "extern/base.mjs" ],
"rules": { "no-global-assign": "off", "no-undef": "off" }
"files": [ "*.mjs" ],
"rules": {}
}, {
"files": [ "build/browser.mjs" ],
"rules": {
"no-undef": "off"
}
}, {
"files": [ "build/node.mjs" ],
"globals": {
"global": true,
"window": true
},
"rules": {
"no-control-regex": "off",
"no-undef": "off"
}
}, {
"files": [ "source/node/console.mjs" ],
"rules": { "no-control-regex": "off" }
Expand Down
124 changes: 124 additions & 0 deletions base/bin/base.mjs
@@ -0,0 +1,124 @@

import fs from 'fs';
import url from 'url';
import path from 'path';
import process from 'process';

import { console } from '../../base/index.mjs';



const FILE = url.fileURLToPath(import.meta.url);
const ROOT = path.dirname(path.resolve(FILE, '../'));

const read = (path) => {

let buffer = null;

try {
buffer = fs.readFileSync(path);
} catch (err) {
buffer = null;
}

return {
path: path,
buffer: buffer
};

};

const generate = (path, files) => {

let errors = 0;
let buffers = [];

files.forEach((file) => {

if (file.buffer !== null) {
buffers.push(file.buffer);
} else {
console.warn('> "' + file.path + '" is empty.');
errors++;
}

});

try {
fs.writeFileSync(path, Buffer.concat(buffers));
} catch (err) {
errors++;
}

if (errors === 0) {

console.info('base: generate("base/' + path.substr(ROOT.length + 1) + '")');

return true;

} else {

console.error('base: generate("base/' + path.substr(ROOT.length + 1) + '")');

return false;

}

};



const BASE_FILES = [
ROOT + '/source/Array.mjs',
ROOT + '/source/Boolean.mjs',
ROOT + '/source/Date.mjs',
ROOT + '/source/Function.mjs',
ROOT + '/source/Number.mjs',
ROOT + '/source/Object.mjs',
ROOT + '/source/RegExp.mjs',
ROOT + '/source/String.mjs',
ROOT + '/source/Emitter.mjs'
].map((path) => read(path));

const BROWSER_FILES = [
ROOT + '/source/browser/Buffer.mjs',
ROOT + '/source/browser/console.mjs',
ROOT + '/source/MODULE.mjs'
].map((path) => read(path));

const NODE_FILES = [
ROOT + '/source/node/Buffer.mjs',
ROOT + '/source/node/console.mjs',
ROOT + '/source/MODULE.mjs'
].map((path) => read(path));



export const build = () => {

let results = [
generate(ROOT + '/build/browser.mjs', [].concat(BASE_FILES).concat(BROWSER_FILES)),
generate(ROOT + '/build/node.mjs', [].concat(BASE_FILES).concat(NODE_FILES))
];

if (results.includes(false) === false) {
return true;
}


return false;

};


if (process.argv.includes(FILE) === true) {

let result = build();
if (result === true) {
process.exit(0);
} else {
process.exit(1);
}

}

42 changes: 0 additions & 42 deletions base/bin/base.sh

This file was deleted.

24 changes: 0 additions & 24 deletions bin/eslint.sh

This file was deleted.

135 changes: 0 additions & 135 deletions bin/generate-service.mjs

This file was deleted.

14 changes: 0 additions & 14 deletions bin/generate-service.sh

This file was deleted.

0 comments on commit 0d4e391

Please sign in to comment.