eolang 0.2.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CITATION.cff ADDED
@@ -0,0 +1,11 @@
1
+ cff-version: 1.2.0
2
+ message: "If you use this software, please cite it as below."
3
+ authors:
4
+ - family-names: "Bugayenko"
5
+ given-names: "Yegor"
6
+ orcid: "https://orcid.org/0000-0001-6370-0678"
7
+ title: "EOLANG and 𝜑-calculus"
8
+ version: 0.23.0
9
+ doi: 10.48550/arXiv.2111.13384
10
+ date-released: 2022-05-09
11
+ url: "https://github.com/objectionary/eoc"
package/README.md CHANGED
@@ -16,14 +16,14 @@ in the current directory:
16
16
 
17
17
  ```
18
18
  [args...] > hello
19
- Q.org.eolang.io.stdout > @
19
+ QQ.io.stdout > @
20
20
  "Hello, world!\n"
21
21
  ```
22
22
 
23
23
  Then, you run it:
24
24
 
25
25
  ```
26
- $ eoc run hello
26
+ $ eoc dataize hello
27
27
  ```
28
28
 
29
29
  That's it.
@@ -37,15 +37,16 @@ You can also do many other things with `eoc` commands
37
37
  * `compile` converts target language to binaries
38
38
  * `link` puts all binaries together into a single executable binary
39
39
  * `dataize` executes the binary and dataize a single object
40
+ * `test` executes all visible unit tests
40
41
 
41
- There are also commands that help manipulate with XMIR and EO sources:
42
+ There are also commands that help manipulate with XMIR and EO sources (some of them are not implemented as of yet):
42
43
 
43
44
  * `audit` inspects all packages and report their status
44
- * `translate` converts Java/C++/Python/etc. program to EO program
45
- * `demu` removes `cage` and `memory` objects
46
- * `dejump` removes `goto` objects
47
- * `infer` suggests object names where it's possible to infer them
48
- * `flatten` moves inner objects to upper level
45
+ * <del>`translate` converts Java/C++/Python/etc. program to EO program</del>
46
+ * <del>`demu` removes `cage` and `memory` objects</del>
47
+ * <del>`dejump` removes `goto` objects</del>
48
+ * <del>`infer` suggests object names where it's possible to infer them</del>
49
+ * <del>`flatten` moves inner objects to upper level</del>
49
50
 
50
51
  This command line toolkit simply integrates other tools available in
51
52
  [@objectionary](https://github.com/objectionary) GitHub organization.
@@ -60,4 +61,4 @@ If you want to run a single test:
60
61
  $ npm test -- test/test_mvnw.js
61
62
  ```
62
63
 
63
- Then, make a pull request.
64
+ Then, make a pull request.
@@ -0,0 +1,16 @@
1
+ [![grunt](https://github.com/objectionary/eoc/actions/workflows/itest.yml/badge.svg)](https://github.com/objectionary/eoc/actions/workflows/itest.yml)
2
+
3
+ There is a simple integration test here. Just run this to make sure
4
+ it works:
5
+
6
+ ```
7
+ $ ../src/eoc.js dataize program
8
+ ```
9
+
10
+ Then, you can execute the unit tests too:
11
+
12
+ ```
13
+ $ ../src/eoc.js test
14
+ ```
15
+
16
+ If doesn't work, submit an issue.
@@ -0,0 +1,27 @@
1
+ # The MIT License (MIT)
2
+ #
3
+ # Copyright (c) 2022 Yegor Bugayenko
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included
13
+ # in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ +alias story
24
+
25
+ [args...] > program
26
+ QQ.io.stdout > @
27
+ story
@@ -0,0 +1,31 @@
1
+ # The MIT License (MIT)
2
+ #
3
+ # Copyright (c) 2022 Yegor Bugayenko
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included
13
+ # in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ +junit
24
+ +alias org.eolang.hamcrest.assert-that
25
+ +alias story
26
+
27
+ [] > story-is-long-enough
28
+ assert-that > @
29
+ story.length
30
+ $.is
31
+ $.greater-than 1
package/itest/story.eo ADDED
@@ -0,0 +1,29 @@
1
+ # The MIT License (MIT)
2
+ #
3
+ # Copyright (c) 2022 Yegor Bugayenko
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included
13
+ # in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ [] > story
24
+ QQ.txt.sprintf > @
25
+ "Hello, Mr. #%d!\n"
26
+ as-int.
27
+ times.
28
+ random
29
+ 100.0
package/mvnw/pom.xml CHANGED
@@ -27,11 +27,24 @@ SOFTWARE.
27
27
  <groupId>org.eolang</groupId>
28
28
  <artifactId>eoc</artifactId>
29
29
  <version>1.0-SNAPSHOT</version>
30
+ <dependencies>
31
+ <dependency>
32
+ <groupId>org.junit.jupiter</groupId>
33
+ <artifactId>junit-jupiter-api</artifactId>
34
+ <version>5.6.2</version>
35
+ </dependency>
36
+ <dependency>
37
+ <groupId>org.junit.jupiter</groupId>
38
+ <artifactId>junit-jupiter-engine</artifactId>
39
+ <version>5.6.2</version>
40
+ </dependency>
41
+ </dependencies>
30
42
  <build>
31
43
  <finalName>eoc</finalName>
32
44
  <sourceDirectory>${eo.generatedDir}</sourceDirectory>
33
45
  <directory>${eo.targetDir}</directory>
34
46
  <outputDirectory>${eo.targetDir}/classes</outputDirectory>
47
+ <testOutputDirectory>${eo.targetDir}/classes</testOutputDirectory>
35
48
  <plugins>
36
49
  <plugin>
37
50
  <groupId>org.eolang</groupId>
@@ -60,6 +73,13 @@ SOFTWARE.
60
73
  </archive>
61
74
  </configuration>
62
75
  </plugin>
76
+ <plugin>
77
+ <artifactId>maven-surefire-plugin</artifactId>
78
+ <version>3.0.0-M7</version>
79
+ <configuration>
80
+ <failIfNoTests>true</failIfNoTests>
81
+ </configuration>
82
+ </plugin>
63
83
  </plugins>
64
84
  </build>
65
85
  </project>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eolang",
3
- "version": "0.2.2",
3
+ "version": "0.4.0",
4
4
  "author": "Yegor Bugayenko <yegor256@gmail.com> (https://www.yegor256.com/)",
5
5
  "license": "MIT",
6
6
  "repository": "objectionary/eoc",
@@ -21,6 +21,7 @@
21
21
  "eoc": "./src/eoc.js"
22
22
  },
23
23
  "dependencies": {
24
+ "colors": "1.4.0",
24
25
  "commander": "9.2.0",
25
26
  "fast-xml-parser": "4.0.0",
26
27
  "xmlhttprequest": "1.8.0"
@@ -33,6 +33,7 @@ const mvnwSync = require('../mvnw');
33
33
  module.exports = function assemble(opts) {
34
34
  mvnwSync([
35
35
  'eo:assemble',
36
+ opts.verbose ? '' : '--quiet',
36
37
  `-Deo.targetDir=${path.resolve(opts.target)}`,
37
38
  `-Deo.outputDir=${path.resolve(opts.target, 'classes')}`,
38
39
  `-Deo.foreign=${path.resolve(opts.target, 'eo-foreign.csv')}`,
@@ -40,4 +41,5 @@ module.exports = function assemble(opts) {
40
41
  `-Deo.placed=${path.resolve(opts.target, 'eo-placed.csv')}`,
41
42
  `-Deo.placedFormat=csv`,
42
43
  ]);
44
+ console.info('EO program assembled in %s', path.resolve(opts.target));
43
45
  };
@@ -33,4 +33,5 @@ const path = require('path');
33
33
  module.exports = function clean(opts) {
34
34
  const home = path.resolve(opts.target);
35
35
  fs.rmSync(home, {recursive: true, force: true});
36
+ console.debug('The directory %s deleted', home);
36
37
  };
@@ -31,11 +31,14 @@ const path = require('path');
31
31
  * @param {Hash} opts - All options
32
32
  */
33
33
  module.exports = function compile(opts) {
34
+ const target = path.resolve(opts.target);
34
35
  mvnwSync([
35
36
  'compiler:compile',
37
+ opts.verbose ? '' : '--quiet',
36
38
  `-Dmaven.compiler.source=1.8`,
37
39
  `-Dmaven.compiler.target=1.8`,
38
- `-Deo.targetDir=${path.resolve(opts.target)}`,
40
+ `-Deo.targetDir=${target}`,
39
41
  `-Deo.generatedDir=${path.resolve(opts.target, 'generated-sources')}`,
40
42
  ]);
43
+ console.info('Java .class files compiled into %s', target);
41
44
  };
@@ -33,6 +33,8 @@ const path = require('path');
33
33
  module.exports = function link(opts) {
34
34
  mvnwSync([
35
35
  'jar:jar',
36
+ opts.verbose ? '' : '--quiet',
36
37
  `-Deo.targetDir=${path.resolve(opts.target)}`,
37
38
  ]);
39
+ console.info('Executable JAR created at %s', path.resolve(opts.target, 'eoc.jar'));
38
40
  };
@@ -31,11 +31,14 @@ const path = require('path');
31
31
  * @param {Hash} opts - All options
32
32
  */
33
33
  module.exports = function register(opts) {
34
+ const foreign = path.resolve(opts.target, 'eo-foreign.csv');
34
35
  mvnwSync([
35
36
  'eo:register',
37
+ opts.verbose ? '' : '--quiet',
36
38
  `-Deo.targetDir=${path.resolve(opts.target)}`,
37
39
  `-Deo.sourcesDir=${path.resolve(opts.sources)}`,
38
- `-Deo.foreign=${path.resolve(opts.target, 'eo-foreign.csv')}`,
40
+ `-Deo.foreign=${foreign}`,
39
41
  `-Deo.foreignFormat=csv`,
40
42
  ]);
43
+ console.info('EO objects registered in %s', foreign);
41
44
  };
@@ -0,0 +1,38 @@
1
+ #! /usr/bin/env node
2
+ /*
3
+ * The MIT License (MIT)
4
+ *
5
+ * Copyright (c) 2022 Yegor Bugayenko
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included
15
+ * in all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ const mvnwSync = require('../mvnw');
27
+ const path = require('path');
28
+
29
+ /**
30
+ * Command to run all available unit tests.
31
+ * @param {Hash} opts - All options
32
+ */
33
+ module.exports = function test(opts) {
34
+ mvnwSync([
35
+ 'surefire:test',
36
+ `-Deo.targetDir=${path.resolve(opts.target)}`,
37
+ ]);
38
+ };
@@ -31,11 +31,14 @@ const path = require('path');
31
31
  * @param {Hash} opts - All options
32
32
  */
33
33
  module.exports = function transpile(opts) {
34
+ const sources = path.resolve(opts.target, 'generated-sources');
34
35
  mvnwSync([
35
36
  'eo:transpile',
37
+ opts.verbose ? '' : '--quiet',
36
38
  `-Deo.targetDir=${path.resolve(opts.target)}`,
37
- `-Deo.generatedDir=${path.resolve(opts.target, 'generated-sources')}`,
39
+ `-Deo.generatedDir=${sources}`,
38
40
  `-Deo.foreign=${path.resolve(opts.target, 'eo-foreign.csv')}`,
39
41
  `-Deo.foreignFormat=csv`,
40
42
  ]);
43
+ console.info('Java sources generated in %s', sources);
41
44
  };
package/src/eoc.js CHANGED
@@ -23,8 +23,23 @@
23
23
  * SOFTWARE.
24
24
  */
25
25
 
26
- const {Command} = require('commander');
27
- const program = new Command();
26
+ const {program} = require('commander');
27
+ const tinted = require('./tinted-console');
28
+ const audit = require('./commands/audit');
29
+ const clean = require('./commands/clean');
30
+ const assemble = require('./commands/assemble');
31
+ const register = require('./commands/register');
32
+ const transpile = require('./commands/transpile');
33
+ const compile = require('./commands/compile');
34
+ const link = require('./commands/link');
35
+ const dataize = require('./commands/dataize');
36
+ const test = require('./commands/test');
37
+
38
+ if (process.argv.includes('--verbose')) {
39
+ tinted.enable('debug');
40
+ console.debug('Debug output is turned ON');
41
+ console.info('INFO');
42
+ }
28
43
 
29
44
  program
30
45
  .name('eoc')
@@ -33,79 +48,100 @@ program
33
48
 
34
49
  program
35
50
  .option('-s, --sources <path>', 'directory with .EO sources', '.')
36
- .option('-t, --target <path>', 'directory with all generated files', '.eoc');
51
+ .option('-t, --target <path>', 'directory with all generated files', '.eoc')
52
+ .option('--alone', 'just run a single command without dependencies')
53
+ .option('--verbose', 'print debug messages and full output of child processes');
37
54
 
38
55
  program.command('audit')
39
56
  .description('inspects all packages and reports their status')
40
- .action((str, options) => {
41
- const audit = require('./commands/audit');
57
+ .action((str, opts) => {
42
58
  audit(program.opts());
43
59
  });
44
60
 
45
61
  program.command('clean')
46
62
  .description('delete all temporary files')
47
- .action((str, options) => {
48
- const clean = require('./commands/clean');
63
+ .action((str, opts) => {
49
64
  clean(program.opts());
50
65
  });
51
66
 
52
67
  program.command('register')
53
68
  .description('register all visible EO source files')
54
- .action((str, options) => {
55
- const register = require('./commands/register');
69
+ .action((str, opts) => {
56
70
  register(program.opts());
57
71
  });
58
72
 
59
73
  program.command('assemble')
60
74
  .description('parse EO files into XMIR and join them with required dependencies')
61
- .action((str, options) => {
62
- const assemble = require('./commands/assemble');
75
+ .action((str, opts) => {
76
+ if (program.opts().alone == undefined) {
77
+ register(program.opts());
78
+ }
63
79
  assemble(program.opts());
64
80
  });
65
81
 
66
82
  program.command('transpile')
67
83
  .description('converts EO files into target language')
68
- .action((str, options) => {
69
- const transpile = require('./commands/transpile');
84
+ .action((str, opts) => {
85
+ if (program.opts().alone == undefined) {
86
+ register(program.opts());
87
+ assemble(program.opts());
88
+ }
70
89
  transpile(program.opts());
71
90
  });
72
91
 
73
92
  program.command('compile')
74
93
  .description('compiles target language sources into binaries')
75
- .action((str, options) => {
76
- const compile = require('./commands/compile');
94
+ .action((str, opts) => {
95
+ if (program.opts().alone == undefined) {
96
+ register(program.opts());
97
+ assemble(program.opts());
98
+ transpile(program.opts());
99
+ }
77
100
  compile(program.opts());
78
101
  });
79
102
 
80
103
  program.command('link')
81
104
  .description('link together all binaries into a single executable binary')
82
- .action((str, options) => {
83
- const link = require('./commands/link');
105
+ .action((str, opts) => {
106
+ if (program.opts().alone == undefined) {
107
+ register(program.opts());
108
+ assemble(program.opts());
109
+ transpile(program.opts());
110
+ compile(program.opts());
111
+ }
84
112
  link(program.opts());
85
113
  });
86
114
 
87
115
  program.command('dataize')
88
116
  .description('run the single executable binary and dataize an object')
89
- .action((str, options) => {
90
- const dataize = require('./commands/dataize');
117
+ .action((str, opts) => {
118
+ if (program.opts().alone == undefined) {
119
+ register(program.opts());
120
+ assemble(program.opts());
121
+ transpile(program.opts());
122
+ compile(program.opts());
123
+ link(program.opts());
124
+ }
91
125
  dataize(program.args[1], program.opts());
92
126
  });
93
127
 
94
- program.command('run')
95
- .description('register, assemble, transpile, compile, link, and dataize an object')
96
- .action((str, options) => {
97
- const register = require('./commands/register');
98
- register(program.opts());
99
- const assemble = require('./commands/assemble');
100
- assemble(program.opts());
101
- const transpile = require('./commands/transpile');
102
- transpile(program.opts());
103
- const compile = require('./commands/compile');
104
- compile(program.opts());
105
- const link = require('./commands/link');
106
- link(program.opts());
107
- const dataize = require('./commands/dataize');
108
- dataize(program.args[1], program.opts());
128
+ program.command('test')
129
+ .description('run all visible unit tests')
130
+ .action((str, opts) => {
131
+ if (program.opts().alone == undefined) {
132
+ register(program.opts());
133
+ assemble(program.opts());
134
+ transpile(program.opts());
135
+ compile(program.opts());
136
+ link(program.opts());
137
+ }
138
+ test(program.opts());
109
139
  });
110
140
 
111
- program.parse();
141
+ try {
142
+ program.parse(process.argv);
143
+ } catch (e) {
144
+ console.error(e.message);
145
+ console.debug(e.stack);
146
+ process.exit(1);
147
+ }
package/src/mvnw.js CHANGED
@@ -46,9 +46,9 @@ function latest() {
46
46
  }
47
47
  const xml = new XMLParser().parse(xhr.responseText);
48
48
  version = xml.metadata.versioning.release;
49
- console.log('The latest version of ' + repo + ' at ' + url + ' is ' + version);
49
+ console.debug('The latest version of %s at %s is %s', repo, url, version);
50
50
  }
51
- console.log('Current version of ' + repo + ' is ' + version);
51
+ console.debug('Current version of %s is %s', repo, version);
52
52
  return version;
53
53
  }
54
54
 
@@ -59,7 +59,9 @@ function latest() {
59
59
  module.exports = function mvnwSync(args) {
60
60
  const home = path.resolve(__dirname, '../mvnw');
61
61
  const bin = path.resolve(home, 'mvnw');
62
- const params = args.concat([
62
+ const params = args.filter(function(t) {
63
+ return t != '';
64
+ }).concat([
63
65
  '-Deo.version=' + latest(),
64
66
  '--errors',
65
67
  '--batch-mode',
@@ -67,9 +69,9 @@ module.exports = function mvnwSync(args) {
67
69
  '--fail-fast',
68
70
  ]);
69
71
  const cmd = bin + ' ' + params.join(' ');
70
- console.log('+ ' + cmd);
72
+ console.debug('+ %s', cmd);
71
73
  const result = spawnSync(bin, params, {cwd: home, stdio: 'inherit'});
72
74
  if (result.status != 0) {
73
- throw new Error('Exit code: ' + result.status);
75
+ throw new Error('The command "' + cmd + '" exited with #' + result.status + ' code');
74
76
  }
75
77
  };
@@ -0,0 +1,74 @@
1
+ #! /usr/bin/env node
2
+ /*
3
+ * The MIT License (MIT)
4
+ *
5
+ * Copyright (c) 2022 Yegor Bugayenko
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included
15
+ * in all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ const safe = require('colors/safe');
27
+ const util = require('node:util');
28
+
29
+ const levels = {
30
+ 'trace': false,
31
+ 'debug': false,
32
+ 'info': true,
33
+ 'warn': true,
34
+ 'error': true,
35
+ };
36
+
37
+ const colors = {
38
+ 'trace': 'gray',
39
+ 'debug': 'gray',
40
+ 'info': 'white',
41
+ 'warn': 'orange',
42
+ 'error': 'red',
43
+ };
44
+
45
+ for (const level in levels) {
46
+ if (levels.hasOwnProperty(level)) {
47
+ const lvl = level;
48
+ const before = console[lvl];
49
+ console[level] = function(...args) {
50
+ if (!levels[lvl]) {
51
+ return;
52
+ }
53
+ before.call(
54
+ before,
55
+ safe[colors[lvl]](util.format(...args))
56
+ );
57
+ };
58
+ }
59
+ }
60
+
61
+ /**
62
+ * Enable this particular logging level.
63
+ * @param {String} level - The level to enable
64
+ */
65
+ module.exports.enable = function enable(level) {
66
+ for (const key in levels) {
67
+ if (levels.hasOwnProperty(level)) {
68
+ levels[key] = true;
69
+ if (key === level) {
70
+ break;
71
+ }
72
+ }
73
+ }
74
+ };
package/src/version.js CHANGED
@@ -23,4 +23,4 @@
23
23
  * SOFTWARE.
24
24
  */
25
25
 
26
- module.exports = '0.2.2';
26
+ module.exports = '0.4.0';