@mobilabs/es6lib 2.1.0 → 2.1.1

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,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 --