@puya/ts 1.1.1 → 1.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.
- package/Timestamper.js +19 -19
- package/index.js +1 -0
- package/package.json +2 -2
package/Timestamper.js
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
const path = require("path");
|
2
2
|
const fs = require("fs");
|
3
3
|
const moment = require("jalali-moment");
|
4
|
-
const
|
4
|
+
const _package = require('./package.json');
|
5
5
|
|
6
|
-
const version =
|
6
|
+
const version = _package.version;
|
7
7
|
|
8
8
|
let default_options = {
|
9
9
|
locale: "en",
|
@@ -31,30 +31,30 @@ function start(args) {
|
|
31
31
|
|
32
32
|
try {
|
33
33
|
const options = Array.isArray(args) ? parseArguments(args) : args;
|
34
|
-
|
34
|
+
|
35
35
|
if (args.length !== 0) {
|
36
36
|
result.state = validateOptions(Object.assign(default_options, options));
|
37
37
|
} else {
|
38
38
|
result.state = "successful";
|
39
39
|
}
|
40
|
-
|
40
|
+
|
41
41
|
if (result.state === "successful") {
|
42
42
|
result.options = Object.assign(default_options, options);
|
43
|
-
|
43
|
+
|
44
44
|
if (default_options.version === true) {
|
45
45
|
console.log(version);
|
46
46
|
} else {
|
47
|
-
|
47
|
+
|
48
48
|
const ts = generateTimestamp(options.locale, options.format);
|
49
49
|
const data = generateData(ts, result.options);
|
50
|
-
|
50
|
+
|
51
51
|
if (!options.skipOutput) {
|
52
52
|
writeOutput(data, result.options.outPutFilePath);
|
53
53
|
}
|
54
54
|
|
55
55
|
result.data = data;
|
56
56
|
}
|
57
|
-
|
57
|
+
|
58
58
|
result.success = true;
|
59
59
|
}
|
60
60
|
} catch (ex) {
|
@@ -114,9 +114,9 @@ function parseArguments(args) {
|
|
114
114
|
default_options.hasInlineTemplate = true;
|
115
115
|
i += 2;
|
116
116
|
break;
|
117
|
-
|
118
|
-
|
119
|
-
|
117
|
+
case '-v':
|
118
|
+
default_options.version = true;
|
119
|
+
i++;
|
120
120
|
break;
|
121
121
|
default:
|
122
122
|
throw new Error(`Invalid argument provided: ${args[i]}`);
|
@@ -133,33 +133,33 @@ function validateOptions(options) {
|
|
133
133
|
if (options.skipOutput && !options.outPutFilePath) {
|
134
134
|
throw new TimestampError("output_confusion", `Please make up your mind buddy. Do you want me to generate the output for you or not?`);
|
135
135
|
}
|
136
|
-
|
136
|
+
|
137
137
|
Object.entries(options).forEach(([key, value]) => {
|
138
138
|
if (value === undefined) {
|
139
139
|
throw new TimestampError(`${key}_required`, `${key} is required after -${key.slice(0, 1)}`);
|
140
140
|
}
|
141
141
|
});
|
142
|
-
|
142
|
+
|
143
143
|
// if (!fileRegex.test(path.basename(options.outPutFilePath))) {
|
144
144
|
// throw new TimestampError("invalid_filename", `Please enter a valid file name.`);
|
145
145
|
// }
|
146
|
-
|
146
|
+
|
147
147
|
if (options.templatePath && !fs.existsSync(options.templatePath)) {
|
148
148
|
throw new TimestampError("template_not_exists", `Template file does not exist.`);
|
149
149
|
}
|
150
|
-
|
150
|
+
|
151
151
|
if (!isValidDateFormat(options.format)) {
|
152
152
|
throw new TimestampError("invalid_format", `Please enter a valid format.`);
|
153
153
|
}
|
154
|
-
|
154
|
+
|
155
155
|
if (options.inlineTemplate !== "") {
|
156
156
|
options.hasInlineTemplate = true;
|
157
157
|
}
|
158
|
-
|
158
|
+
|
159
159
|
if (options.hasInlineTemplate && options.inlineTemplate === "") {
|
160
160
|
throw new TimestampError("invalid_inline_template", `Please provide a valid inline template.`);
|
161
161
|
}
|
162
|
-
|
162
|
+
|
163
163
|
if (options.templatePath && options.inlineTemplate != "") {
|
164
164
|
throw new TimestampError("extra_template", `You can use only one template.`);
|
165
165
|
}
|
@@ -172,7 +172,7 @@ function generateTimestamp(locale, format) {
|
|
172
172
|
return moment().locale(locale).format(format);
|
173
173
|
}
|
174
174
|
|
175
|
-
function generateData(ts, {template, templatePath, inlineTemplate, hasInlineTemplate}) {
|
175
|
+
function generateData(ts, { template, templatePath, inlineTemplate, hasInlineTemplate }) {
|
176
176
|
let data;
|
177
177
|
|
178
178
|
if (hasInlineTemplate) {
|
package/index.js
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@puya/ts",
|
3
|
-
"version": "1.1.
|
3
|
+
"version": "1.1.2",
|
4
4
|
"description": "This library provides timestamp and supports custom templates for its output file.",
|
5
5
|
"main": "index.js",
|
6
6
|
"bin": {
|
@@ -35,4 +35,4 @@
|
|
35
35
|
"TimestamperCLI.js",
|
36
36
|
"bin/ts"
|
37
37
|
]
|
38
|
-
}
|
38
|
+
}
|