@mobilabs/es6lib 2.1.0 → 2.1.2

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.
@@ -0,0 +1,198 @@
1
+ #!/usr/bin/env node
2
+ /* *****************************************************************************
3
+ *
4
+ * Creates the production folder.
5
+ *
6
+ * build:skeleton:prod.js script creates the productiion folder and copies the
7
+ * files defined in config.js.
8
+ *
9
+ * Private Functions:
10
+ * . _help displays the help message,
11
+ * . _clean removes the previous production folder,
12
+ * . _doskeleton creates the production folder and copies files,
13
+ *
14
+ *
15
+ * Public Static Methods:
16
+ * . run executes the script,
17
+ *
18
+ *
19
+ * @namespace -
20
+ * @dependencies none
21
+ * @exports -
22
+ * @author -
23
+ * @since 0.0.0
24
+ * @version -
25
+ * ************************************************************************** */
26
+ /* eslint one-var: 0, semi-style: 0, no-underscore-dangle: 0,
27
+ import/no-extraneous-dependencies: 0 */
28
+
29
+ 'use strict';
30
+
31
+ // -- Vendor Modules
32
+ const fs = require('fs')
33
+ , path = require('path')
34
+ , nopt = require('nopt')
35
+ ;
36
+
37
+
38
+ // -- Local Modules
39
+ const config = require('./config')
40
+ ;
41
+
42
+
43
+ // -- Local Constants
44
+ const VERSION = '0.0.0-alpha.0'
45
+ , opts = {
46
+ help: [Boolean, false],
47
+ version: [String, null],
48
+ }
49
+ , shortOpts = {
50
+ h: ['--help'],
51
+ v: ['--version', VERSION],
52
+ }
53
+ , parsed = nopt(opts, shortOpts, process.argv, 2)
54
+ , { dist } = config
55
+ , { webfiles } = config
56
+ ;
57
+
58
+
59
+ // -- Local Variables
60
+
61
+
62
+ // -- Private Functions --------------------------------------------------------
63
+
64
+ /**
65
+ * Dispays the help message.
66
+ *
67
+ * @function ()
68
+ * @private
69
+ * @param {} -,
70
+ * @returns {} -,
71
+ * @since 0.0.0
72
+ */
73
+ function _help() {
74
+ const message = ['',
75
+ 'Usage: command [options]',
76
+ '',
77
+ ' creates the production folder and copies the files defined in config.js',
78
+ '',
79
+ 'Options:',
80
+ '',
81
+ '-h, --help output usage information',
82
+ '-v, --version output the version number',
83
+ '',
84
+ ].join('\n');
85
+
86
+ process.stdout.write(`${message}\n`);
87
+ }
88
+
89
+ /**
90
+ * Removes the previous production folder,
91
+ *
92
+ * @function ()
93
+ * @private
94
+ * @param {} -,
95
+ * @returns {Object} returns a promise,
96
+ * @since 0.0.0
97
+ */
98
+ function _clean() {
99
+ const d1 = new Date();
100
+ process.stdout.write('Starting \'\x1b[36mclean\x1b[89m\x1b[0m\'...\n');
101
+
102
+ return new Promise((resolve) => {
103
+ fs.rm(dist, { force: true, recursive: true }, (err) => {
104
+ if (err) throw new Error(err);
105
+
106
+ const d2 = new Date() - d1;
107
+ process.stdout.write(`Finished '\x1b[36mclean\x1b[89m\x1b[0m' after \x1b[35m${d2} ms\x1b[89m\x1b[0m\n`);
108
+ resolve();
109
+ });
110
+ });
111
+ }
112
+
113
+ /**
114
+ * Creates the production folder and copies files.
115
+ *
116
+ * @function (arg1)
117
+ * @private
118
+ * @param {Function} the function to call at the completion,
119
+ * @returns {} -,
120
+ * @since 0.0.0
121
+ */
122
+ function _doskeleton(done) {
123
+ const d1 = new Date();
124
+ process.stdout.write('Starting \'\x1b[36mdoskeleton\x1b[89m\x1b[0m\'...\n');
125
+
126
+ /**
127
+ * Wait all processes completed;
128
+ */
129
+ let pending = webfiles.length;
130
+ function _next() {
131
+ pending -= 1;
132
+ if (!pending) {
133
+ const d2 = new Date() - d1;
134
+ process.stdout.write(`Finished '\x1b[36mdoskeleton\x1b[89m\x1b[0m' after \x1b[35m${d2} ms\x1b[89m\x1b[0m\n`);
135
+ done();
136
+ }
137
+ }
138
+
139
+ let filename;
140
+ for (let i = 0; i < webfiles.length; i++) {
141
+ filename = path.basename(webfiles[i]);
142
+ fs.cp(webfiles[i], `${dist}/${filename}`, (err) => {
143
+ if (err) throw new Error(err);
144
+ _next();
145
+ });
146
+ }
147
+ }
148
+
149
+
150
+ // -- Main ---------------------------------------------------------------------
151
+
152
+ /**
153
+ * Executes the script.
154
+ *
155
+ * @function ()
156
+ * @public
157
+ * @param {} -,
158
+ * @returns {} -,
159
+ * @since 0.0.0
160
+ */
161
+ async function run() {
162
+ const PENDING = 1;
163
+
164
+ if (parsed.help) {
165
+ _help();
166
+ return;
167
+ }
168
+
169
+ if (parsed.version) {
170
+ process.stdout.write(`version: ${parsed.version}\n`);
171
+ return;
172
+ }
173
+
174
+ const d1 = new Date();
175
+ process.stdout.write('Starting \'\x1b[36mbuild:skeleton:prod\x1b[89m\x1b[0m\'...\n');
176
+
177
+ let pending = PENDING;
178
+ /**
179
+ * Executes done until completion.
180
+ */
181
+ function done() {
182
+ pending -= 1;
183
+ if (!pending) {
184
+ const d2 = new Date() - d1;
185
+ process.stdout.write(`Finished '\x1b[36mbuild:skeleton:prod\x1b[89m\x1b[0m' after \x1b[35m${d2} ms\x1b[89m\x1b[0m\n`);
186
+ }
187
+ }
188
+
189
+ await _clean();
190
+ _doskeleton(done);
191
+ }
192
+
193
+
194
+ // Start script.
195
+ run();
196
+
197
+
198
+ // -- oOo --
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env bash
2
+
3
+ NAME=$1
4
+ name=$(echo $1 | tr '[:upper:]' '[:lower:]')
5
+ VERSION=$2
6
+ NAMESPACE=$3
7
+ NPM='private_repo'
8
+ TMP='tmp'
9
+ DIST='_dist'
10
+
11
+ # Check if it is a package with a namespace. For instance @mobilabs/libname
12
+ if [[ ! -z ${NAMESPACE} ]]
13
+ then
14
+ # Remove the namespace:
15
+ NAMESPACE=${NAMESPACE}/
16
+ name=${name/${NAMESPACE}}
17
+ echo ${name}
18
+ fi
19
+
20
+ if [[ -z ${name} ]]
21
+ then
22
+ echo 'You have to provide a name for the NPM package! Aborting ...'
23
+ exit 1
24
+ fi
25
+
26
+ if [[ -z ${VERSION} ]]
27
+ then
28
+ echo 'You have to provide a version for the NPM package! Aborting ...'
29
+ exit 1
30
+ fi
31
+
32
+ mkdir -p ${NPM}/${name}/${VERSION}/${name}
33
+ cp ${NPM}/${TMP}/index.js ${NPM}/${name}/${VERSION}/${name}/.
34
+ cp ${NPM}/${TMP}/package.json ${NPM}/${name}/${VERSION}/${name}/.
35
+ rm -rf ${NPM}/${TMP}
36
+
37
+ cp -r ${DIST} ${NPM}/${name}/${VERSION}/${name}/_dist
38
+ cd ${NPM}/${name}/${VERSION}
39
+ tar zcvf ${name}.tgz ${name}/
40
+ rm -rf ${name}
41
+ echo 'Done!'
@@ -0,0 +1,80 @@
1
+ /* eslint one-var: 0, semi-style: 0 */
2
+
3
+ 'use strict';
4
+
5
+ // -- Vendor Modules
6
+
7
+
8
+ // -- Local Modules
9
+ const pack = require('../package.json');
10
+
11
+
12
+ // -- Local Constants
13
+ const libname = 'ES6lib'
14
+ , name = libname.replace(/\s+/g, '').toLowerCase()
15
+ ;
16
+
17
+
18
+ // -- Local Variables
19
+
20
+
21
+ // -- Main
22
+
23
+ module.exports = {
24
+ ES6GLOB: '$__ES6GLOB',
25
+ dist: './_dist',
26
+ libdir: './lib',
27
+ libname,
28
+ name,
29
+ index: './index.js',
30
+ distlink: `./_dist/lib/${name}.js`,
31
+
32
+ // These are the Javascript files required to build the library. Choose one
33
+ // pattern among these ones. The library can include only the header file,
34
+ // a core file and the footer file. The files 'basic.js', 'functional.js',
35
+ // 'functional-shared.js', 'prototypal.js', 'pseudoclassical.js' and
36
+ // 'pseudoclassical-auto.js' are mutually exclusives.
37
+ /* eslint-disable no-multi-spaces */
38
+ src: [
39
+ // These three files (_header, _head.js and extend.js) must be declared
40
+ // in this order as they create the umd module, define the global
41
+ // constants/variables, the object tree and the function to fill
42
+ // the tree!
43
+ './src/_header',
44
+ './src/_head.js',
45
+ './src/lib/extend.js',
46
+
47
+ './src/util/util.js',
48
+ // './src/basic.js',
49
+ // './src/basicplus.js',
50
+ // './src/functional.js',
51
+ // './src/functional-shared.js',
52
+ './src/prototypal.js',
53
+ // './src/pseudoclassical.js',
54
+ // './src/pseudoclassical-auto.js',
55
+
56
+ // This file must always be the last one as it closes the umd module.
57
+ './src/_footer',
58
+ ],
59
+ /* eslint-enable no-multi-spaces */
60
+
61
+ webfiles: [
62
+ // These are the files to copy to the root path of the web app,
63
+ './README.md',
64
+ './LICENSE.md',
65
+ ],
66
+
67
+ get license() {
68
+ return ['/*! ****************************************************************************',
69
+ ` * ${libname} v${pack.version}`,
70
+ ' *',
71
+ ` * ${pack.description}.`,
72
+ ' * (you can download it from npm or github repositories)',
73
+ ` * Copyright (c) ${(new Date()).getFullYear()} ${pack.author.name} <${pack.author.email}> (${pack.author.url}).`,
74
+ ' * Released under the MIT license. You may obtain a copy of the License',
75
+ ' * at: http://www.opensource.org/licenses/mit-license.php).',
76
+ ' * Built from {{boiler:name}} v{{boiler:name:version}}.',
77
+ ' * ************************************************************************** */',
78
+ ''].join('\n');
79
+ },
80
+ };
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env bash
2
+
3
+ NAME=$1
4
+ name=$(echo $1 | tr '[:upper:]' '[:lower:]')
5
+ VERSION=$2
6
+ NAMESPACE=$3
7
+ NPM='npm_private_repo'
8
+
9
+ # Check if it is a package with a namespace. For instance @mobilabs/libname
10
+ if [[ ! -z ${NAMESPACE} ]]
11
+ then
12
+ PREFIX=${NAMESPACE/@}
13
+ # remove the namespace:
14
+ NAMESPACE=${NAMESPACE}/
15
+ name=${name/${NAMESPACE}}
16
+ echo ${name}
17
+ fi
18
+
19
+ if [[ -z ${name} ]]
20
+ then
21
+ echo 'You have to provide a name for the NPM package! Aborting ...'
22
+ exit 1
23
+ fi
24
+
25
+ if [[ -z ${VERSION} ]]
26
+ then
27
+ echo 'You have to provide a version for the NPM package! Aborting ...'
28
+ exit 1
29
+ fi
30
+
31
+ mkdir -p ${NPM}/${name}
32
+ if [[ ! -z ${NAMESPACE} ]]
33
+ then
34
+ mv ${PREFIX}-${name}-${VERSION}.tgz ./${NPM}/${name}/.
35
+ else
36
+ mv ${name}-${VERSION}.tgz ./${NPM}/${name}/.
37
+ fi
38
+
39
+ echo 'done!'
40
+
41
+
42
+ # -- oOo --
@@ -0,0 +1,232 @@
1
+ #!/usr/bin/env node
2
+ /* *****************************************************************************
3
+ *
4
+ * Creates a private npm package.
5
+ *
6
+ * dep:private script creates a npm package not to be published but used
7
+ * locally.
8
+ *
9
+ * Private Functions:
10
+ * . _help displays the help message,
11
+ * . _clean removes the previous build,
12
+ * . _copyindex copies the modified index,
13
+ * . _copypackagejson copies the modified package.json,
14
+ *
15
+ *
16
+ * Public Static Methods:
17
+ * . run executes the script,
18
+ *
19
+ *
20
+ * @namespace -
21
+ * @dependencies none
22
+ * @exports -
23
+ * @author -
24
+ * @since 0.0.0
25
+ * @version -
26
+ * ************************************************************************** */
27
+ /* eslint one-var: 0, semi-style: 0, no-underscore-dangle: 0,
28
+ import/no-extraneous-dependencies: 0 */
29
+
30
+ 'use strict';
31
+
32
+ // -- Vendor Modules
33
+ const fs = require('fs')
34
+ , path = require('path')
35
+ , nopt = require('nopt')
36
+ ;
37
+
38
+
39
+ // -- Local Modules
40
+ const config = require('./config')
41
+ ;
42
+
43
+
44
+ // -- Local Constants
45
+ const VERSION = '0.0.0-alpha.0'
46
+ , opts = {
47
+ help: [Boolean, false],
48
+ version: [String, null],
49
+ }
50
+ , shortOpts = {
51
+ h: ['--help'],
52
+ v: ['--version', VERSION],
53
+ }
54
+ , parsed = nopt(opts, shortOpts, process.argv, 2)
55
+ , tmppriv = './private_repo/tmp'
56
+ , { name } = config
57
+ , { index } = config
58
+ , { distlink } = config
59
+ ;
60
+
61
+
62
+ // -- Local Variables
63
+
64
+
65
+ // -- Private Functions --------------------------------------------------------
66
+
67
+ /**
68
+ * Dispays the help message.
69
+ *
70
+ * @function ()
71
+ * @private
72
+ * @param {} -,
73
+ * @returns {} -,
74
+ * @since 0.0.0
75
+ */
76
+ function _help() {
77
+ const message = ['',
78
+ 'Usage: command [options]',
79
+ '',
80
+ ' creates a private npm package to be used locally',
81
+ '',
82
+ 'Options:',
83
+ '',
84
+ '-h, --help output usage information',
85
+ '-v, --version output the version number',
86
+ '',
87
+ ].join('\n');
88
+
89
+ process.stdout.write(`${message}\n`);
90
+ }
91
+
92
+ /**
93
+ * Removes the previous build.
94
+ *
95
+ * @function ()
96
+ * @private
97
+ * @param {} -,
98
+ * @returns {Object} returns a promise,
99
+ * @since 0.0.0
100
+ */
101
+ function _clean() {
102
+ const d1 = new Date();
103
+ process.stdout.write('Starting \'\x1b[36mclean\x1b[89m\x1b[0m\'...\n');
104
+
105
+ return new Promise((resolve) => {
106
+ fs.rm(tmppriv, { force: true, recursive: true }, (err1) => {
107
+ if (err1) throw new Error(err1);
108
+
109
+ fs.mkdir(tmppriv, { recursive: true }, (err2) => {
110
+ if (err2) throw new Error(err2);
111
+
112
+ const d2 = new Date() - d1;
113
+ process.stdout.write(`Finished '\x1b[36mclean\x1b[89m\x1b[0m' after \x1b[35m${d2} ms\x1b[89m\x1b[0m\n`);
114
+ resolve();
115
+ });
116
+ });
117
+ });
118
+ }
119
+
120
+ /**
121
+ * Copies the modified index.
122
+ *
123
+ * @function (arg1)
124
+ * @private
125
+ * @param {Function} the function to call at the completion,
126
+ * @returns {} -,
127
+ * @since 0.0.0
128
+ */
129
+ function _copyindex(done) {
130
+ const d1 = new Date();
131
+ process.stdout.write('Starting \'\x1b[36mcopyindex\x1b[89m\x1b[0m\'...\n');
132
+
133
+ fs.readFile(index, 'utf8', (err1, data) => {
134
+ if (err1) throw new Error(err1);
135
+
136
+ const content = data.replace(`./lib/${name}`, distlink);
137
+ fs.writeFile(`${tmppriv}/${path.basename(index)}`, content, { encoding: 'utf8' }, (err2) => {
138
+ if (err2) throw new Error(err2);
139
+
140
+ const d2 = new Date() - d1;
141
+ process.stdout.write(`Finished '\x1b[36mcopyindex\x1b[89m\x1b[0m' after \x1b[35m${d2} ms\x1b[89m\x1b[0m\n`);
142
+ done();
143
+ });
144
+ });
145
+ }
146
+
147
+ /**
148
+ * Copies the modified package.json.
149
+ *
150
+ * @function (arg1)
151
+ * @private
152
+ * @param {Function} the function to call at the completion,
153
+ * @returns {} -,
154
+ * @since 0.0.0
155
+ */
156
+ function _copypackagejson(done) {
157
+ const d1 = new Date();
158
+ process.stdout.write('Starting \'\x1b[36mcopypackagejson\x1b[89m\x1b[0m\'...\n');
159
+
160
+ fs.readFile('./package.json', 'utf8', (err1, data) => {
161
+ if (err1) throw new Error(err1);
162
+
163
+ const obj = JSON.parse(data);
164
+ obj.main = distlink;
165
+ obj.bin = {};
166
+ obj.scripts = {};
167
+ obj.dependencies = {};
168
+ obj.devDependencies = {};
169
+ obj.private = true;
170
+ obj.husky = {};
171
+
172
+ fs.writeFile(`${tmppriv}/package.json`, JSON.stringify(obj, null, 2), { encooding: 'utf8' }, (err2) => {
173
+ if (err2) throw new Error(err2);
174
+
175
+ const d2 = new Date() - d1;
176
+ process.stdout.write(`Finished '\x1b[36mcopypackagejson\x1b[89m\x1b[0m' after \x1b[35m${d2} ms\x1b[89m\x1b[0m\n`);
177
+ done();
178
+ });
179
+ });
180
+ }
181
+
182
+
183
+ // -- Main ---------------------------------------------------------------------
184
+
185
+ /**
186
+ * Executes the script.
187
+ *
188
+ * @function ()
189
+ * @public
190
+ * @param {} -,
191
+ * @returns {} -,
192
+ * @since 0.0.0
193
+ */
194
+ async function run() {
195
+ const PENDING = 2;
196
+
197
+ if (parsed.help) {
198
+ _help();
199
+ return;
200
+ }
201
+
202
+ if (parsed.version) {
203
+ process.stdout.write(`version: ${parsed.version}\n`);
204
+ return;
205
+ }
206
+
207
+ const d1 = new Date();
208
+ process.stdout.write('Starting \'\x1b[36mdep:private\x1b[89m\x1b[0m\'...\n');
209
+
210
+ let pending = PENDING;
211
+ /**
212
+ * Executes done until completion.
213
+ */
214
+ function done() {
215
+ pending -= 1;
216
+ if (!pending) {
217
+ const d2 = new Date() - d1;
218
+ process.stdout.write(`Finished '\x1b[36mdep:private\x1b[89m\x1b[0m' after \x1b[35m${d2} ms\x1b[89m\x1b[0m\n`);
219
+ }
220
+ }
221
+
222
+ await _clean();
223
+ _copyindex(done);
224
+ _copypackagejson(done);
225
+ }
226
+
227
+
228
+ // Start script.
229
+ run();
230
+
231
+
232
+ // -- oOo --
package/test/index.html CHANGED
@@ -50,7 +50,7 @@
50
50
  console.log(lib.getArray());
51
51
 
52
52
  const el = document.getElementById('app');
53
- el.append(`Es6lib $v${ES6lib.VERSION}`);
53
+ el.append(`Es6lib v${ES6lib.VERSION}`);
54
54
  el.append(` ... ${lib.getString()}`);
55
55
  el.append(` ... ${lib.getArray()}`);
56
56