@rvoh/dream 0.30.0 → 0.30.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.
- package/dist/cjs/src/bin/index.js +26 -11
- package/dist/cjs/src/cli/index.js +28 -0
- package/dist/cjs/src/cli/logger/DreamCliLogger.js +57 -0
- package/dist/cjs/src/cli/logger/helpers/createSpinner.js +14 -0
- package/dist/cjs/src/cli/logger/loggable/DreamCliLoggable.js +22 -0
- package/dist/cjs/src/cli/logger/loggable/DreamCliLoggableSpinner.js +31 -0
- package/dist/cjs/src/cli/logger/loggable/DreamCliLoggableText.js +21 -0
- package/dist/cjs/src/cli/logger/loggable/colorize.js +8 -0
- package/dist/cjs/src/cli/logger/loggable/spinners.js +1185 -0
- package/dist/cjs/src/helpers/db/runMigration.js +8 -3
- package/dist/esm/src/bin/index.js +24 -9
- package/dist/esm/src/cli/index.js +28 -0
- package/dist/esm/src/cli/logger/DreamCliLogger.js +54 -0
- package/dist/esm/src/cli/logger/helpers/createSpinner.js +11 -0
- package/dist/esm/src/cli/logger/loggable/DreamCliLoggable.js +19 -0
- package/dist/esm/src/cli/logger/loggable/DreamCliLoggableSpinner.js +28 -0
- package/dist/esm/src/cli/logger/loggable/DreamCliLoggableText.js +18 -0
- package/dist/esm/src/cli/logger/loggable/colorize.js +5 -0
- package/dist/esm/src/cli/logger/loggable/spinners.js +1183 -0
- package/dist/esm/src/helpers/db/runMigration.js +8 -3
- package/dist/types/src/cli/index.d.ts +5 -0
- package/dist/types/src/cli/logger/DreamCliLogger.d.ts +22 -0
- package/dist/types/src/cli/logger/helpers/createSpinner.d.ts +2 -0
- package/dist/types/src/cli/logger/loggable/DreamCliLoggable.d.ts +15 -0
- package/dist/types/src/cli/logger/loggable/DreamCliLoggableSpinner.d.ts +21 -0
- package/dist/types/src/cli/logger/loggable/DreamCliLoggableText.d.ts +16 -0
- package/dist/types/src/cli/logger/loggable/colorize.d.ts +5 -0
- package/dist/types/src/cli/logger/loggable/spinners.d.ts +355 -0
- package/docs/assets/search.js +1 -1
- package/docs/classes/Benchmark.html +2 -2
- package/docs/classes/CalendarDate.html +2 -2
- package/docs/classes/CreateOrFindByFailedToCreateAndFind.html +3 -3
- package/docs/classes/Decorators.html +19 -19
- package/docs/classes/Dream.html +126 -126
- package/docs/classes/DreamApplication.html +4 -4
- package/docs/classes/DreamBin.html +2 -2
- package/docs/classes/DreamCLI.html +6 -4
- package/docs/classes/DreamDbConnection.html +2 -2
- package/docs/classes/DreamImporter.html +2 -2
- package/docs/classes/DreamMigrationHelpers.html +7 -7
- package/docs/classes/DreamSerializer.html +2 -2
- package/docs/classes/DreamTransaction.html +2 -2
- package/docs/classes/Encrypt.html +2 -2
- package/docs/classes/Env.html +2 -2
- package/docs/classes/GlobalNameNotSet.html +3 -3
- package/docs/classes/NonLoadedAssociation.html +3 -3
- package/docs/classes/Query.html +50 -50
- package/docs/classes/Range.html +2 -2
- package/docs/classes/RecordNotFound.html +3 -3
- package/docs/classes/ValidationError.html +3 -3
- package/docs/functions/Attribute.html +1 -1
- package/docs/functions/RendersMany.html +1 -1
- package/docs/functions/RendersOne.html +1 -1
- package/docs/functions/ReplicaSafe.html +1 -1
- package/docs/functions/STI.html +1 -1
- package/docs/functions/SoftDelete.html +1 -1
- package/docs/functions/camelize.html +1 -1
- package/docs/functions/capitalize.html +1 -1
- package/docs/functions/closeAllDbConnections.html +1 -1
- package/docs/functions/compact.html +1 -1
- package/docs/functions/db.html +1 -1
- package/docs/functions/debug.html +1 -1
- package/docs/functions/dreamDbConnections.html +1 -1
- package/docs/functions/dreamPath.html +1 -1
- package/docs/functions/generateDream.html +1 -1
- package/docs/functions/globalClassNameFromFullyQualifiedModelName.html +1 -1
- package/docs/functions/hyphenize.html +1 -1
- package/docs/functions/inferSerializerFromDreamClassOrViewModelClass.html +1 -1
- package/docs/functions/inferSerializerFromDreamOrViewModel.html +1 -1
- package/docs/functions/isEmpty.html +1 -1
- package/docs/functions/loadRepl.html +1 -1
- package/docs/functions/lookupClassByGlobalName.html +1 -1
- package/docs/functions/pascalize.html +1 -1
- package/docs/functions/pgErrorType.html +1 -1
- package/docs/functions/range-1.html +1 -1
- package/docs/functions/relativeDreamPath.html +1 -1
- package/docs/functions/round.html +1 -1
- package/docs/functions/serializerNameFromFullyQualifiedModelName.html +1 -1
- package/docs/functions/sharedPathPrefix.html +1 -1
- package/docs/functions/snakeify.html +1 -1
- package/docs/functions/sortBy.html +1 -1
- package/docs/functions/standardizeFullyQualifiedModelName.html +1 -1
- package/docs/functions/uncapitalize.html +1 -1
- package/docs/functions/uniq.html +1 -1
- package/docs/functions/validateColumn.html +1 -1
- package/docs/functions/validateTable.html +1 -1
- package/docs/interfaces/AttributeStatement.html +2 -2
- package/docs/interfaces/DecoratorContext.html +2 -2
- package/docs/interfaces/DreamApplicationInitOptions.html +2 -2
- package/docs/interfaces/DreamApplicationOpts.html +2 -2
- package/docs/interfaces/DreamSerializerAssociationStatement.html +2 -2
- package/docs/interfaces/EncryptOptions.html +2 -2
- package/docs/interfaces/OpenapiSchemaProperties.html +1 -1
- package/docs/interfaces/OpenapiSchemaPropertiesShorthand.html +1 -1
- package/docs/interfaces/OpenapiTypeFieldObject.html +1 -1
- package/docs/types/Camelized.html +1 -1
- package/docs/types/CommonOpenapiSchemaObjectFields.html +1 -1
- package/docs/types/DreamAssociationMetadata.html +1 -1
- package/docs/types/DreamAttributes.html +1 -1
- package/docs/types/DreamClassColumn.html +1 -1
- package/docs/types/DreamColumn.html +1 -1
- package/docs/types/DreamColumnNames.html +1 -1
- package/docs/types/DreamLogLevel.html +1 -1
- package/docs/types/DreamLogger.html +1 -1
- package/docs/types/DreamOrViewModelSerializerKey.html +1 -1
- package/docs/types/DreamParamSafeAttributes.html +1 -1
- package/docs/types/DreamParamSafeColumnNames.html +1 -1
- package/docs/types/DreamSerializerKey.html +1 -1
- package/docs/types/DreamSerializers.html +1 -1
- package/docs/types/DreamTableSchema.html +1 -1
- package/docs/types/DreamVirtualColumns.html +1 -1
- package/docs/types/EncryptAlgorithm.html +1 -1
- package/docs/types/Hyphenized.html +1 -1
- package/docs/types/IdType.html +1 -1
- package/docs/types/OpenapiAllTypes.html +1 -1
- package/docs/types/OpenapiFormats.html +1 -1
- package/docs/types/OpenapiNumberFormats.html +1 -1
- package/docs/types/OpenapiPrimitiveTypes.html +1 -1
- package/docs/types/OpenapiSchemaArray.html +1 -1
- package/docs/types/OpenapiSchemaArrayShorthand.html +1 -1
- package/docs/types/OpenapiSchemaBase.html +1 -1
- package/docs/types/OpenapiSchemaBody.html +1 -1
- package/docs/types/OpenapiSchemaBodyShorthand.html +1 -1
- package/docs/types/OpenapiSchemaCommonFields.html +1 -1
- package/docs/types/OpenapiSchemaExpressionAllOf.html +1 -1
- package/docs/types/OpenapiSchemaExpressionAnyOf.html +1 -1
- package/docs/types/OpenapiSchemaExpressionOneOf.html +1 -1
- package/docs/types/OpenapiSchemaExpressionRef.html +1 -1
- package/docs/types/OpenapiSchemaExpressionRefSchemaShorthand.html +1 -1
- package/docs/types/OpenapiSchemaInteger.html +1 -1
- package/docs/types/OpenapiSchemaNull.html +1 -1
- package/docs/types/OpenapiSchemaNumber.html +1 -1
- package/docs/types/OpenapiSchemaObject.html +1 -1
- package/docs/types/OpenapiSchemaObjectAllOf.html +1 -1
- package/docs/types/OpenapiSchemaObjectAllOfShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectAnyOf.html +1 -1
- package/docs/types/OpenapiSchemaObjectAnyOfShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectBase.html +1 -1
- package/docs/types/OpenapiSchemaObjectBaseShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectOneOf.html +1 -1
- package/docs/types/OpenapiSchemaObjectOneOfShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectShorthand.html +1 -1
- package/docs/types/OpenapiSchemaPartialSegment.html +1 -1
- package/docs/types/OpenapiSchemaPrimitiveGeneric.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionAllOf.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionAnyOf.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionOneOf.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionSerializableRef.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionSerializerRef.html +1 -1
- package/docs/types/OpenapiSchemaShorthandPrimitiveGeneric.html +1 -1
- package/docs/types/OpenapiSchemaString.html +1 -1
- package/docs/types/OpenapiShorthandAllTypes.html +1 -1
- package/docs/types/OpenapiShorthandPrimitiveTypes.html +1 -1
- package/docs/types/OpenapiTypeField.html +1 -1
- package/docs/types/Pascalized.html +1 -1
- package/docs/types/PrimaryKeyType.html +1 -1
- package/docs/types/RoundingPrecision.html +1 -1
- package/docs/types/SerializableClassOrSerializerCallback.html +1 -1
- package/docs/types/SerializableDreamClassOrViewModelClass.html +1 -1
- package/docs/types/SerializableDreamOrViewModel.html +1 -1
- package/docs/types/SerializableTypes.html +1 -1
- package/docs/types/Snakeified.html +1 -1
- package/docs/types/Timestamp.html +1 -1
- package/docs/types/UpdateableAssociationProperties.html +1 -1
- package/docs/types/UpdateableProperties.html +1 -1
- package/docs/types/ValidationType.html +1 -1
- package/docs/types/ViewModelSerializerKey.html +1 -1
- package/docs/types/WhereStatementForDream.html +1 -1
- package/docs/types/WhereStatementForDreamClass.html +1 -1
- package/docs/variables/DreamConst.html +1 -1
- package/docs/variables/TRIGRAM_OPERATORS.html +1 -1
- package/docs/variables/openapiPrimitiveTypes-1.html +1 -1
- package/docs/variables/openapiShorthandPrimitiveTypes-1.html +1 -1
- package/docs/variables/ops.html +1 -1
- package/docs/variables/primaryKeyTypes.html +1 -1
- package/package.json +3 -2
|
@@ -7,6 +7,8 @@ const path = require("path");
|
|
|
7
7
|
const DreamDbConnection_js_1 = require("../../db/DreamDbConnection.js");
|
|
8
8
|
const index_js_1 = require("../../db/index.js");
|
|
9
9
|
const index_js_2 = require("../../dream-application/index.js");
|
|
10
|
+
const index_js_3 = require("../../cli/index.js");
|
|
11
|
+
const colorize_js_1 = require("../../cli/logger/loggable/colorize.js");
|
|
10
12
|
async function runMigration({ mode = 'migrate' } = {}) {
|
|
11
13
|
const dreamApp = index_js_2.default.getOrFail();
|
|
12
14
|
const migrationFolder = path.join(dreamApp.projectRoot, dreamApp.paths.db, 'migrations');
|
|
@@ -87,11 +89,14 @@ function migratedActionPastTense(mode) {
|
|
|
87
89
|
function logResults(results, mode) {
|
|
88
90
|
results?.forEach(it => {
|
|
89
91
|
if (it.status === 'Success') {
|
|
90
|
-
|
|
92
|
+
index_js_3.default.logger.log((0, colorize_js_1.default)(`[db]`, { color: 'cyan' }) +
|
|
93
|
+
` migration "${it.migrationName}" was ${migratedActionPastTense(mode)} successfully`, { permanent: true, logPrefix: '├', logPrefixColor: 'cyan' });
|
|
91
94
|
}
|
|
92
95
|
else if (it.status === 'Error') {
|
|
93
|
-
|
|
94
|
-
|
|
96
|
+
index_js_3.default.logger.log(JSON.stringify(it, null, 2), { permanent: true });
|
|
97
|
+
index_js_3.default.logger.log((0, colorize_js_1.default)(`failed to ${migratedActionCurrentTense(mode)} migration "${it.migrationName}"`, {
|
|
98
|
+
color: 'redBright',
|
|
99
|
+
}), { permanent: true });
|
|
95
100
|
}
|
|
96
101
|
});
|
|
97
102
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import DreamCLI from '../cli/index.js';
|
|
1
2
|
import ConnectionConfRetriever from '../db/ConnectionConfRetriever.js';
|
|
2
3
|
import DreamApplication from '../dream-application/index.js';
|
|
3
4
|
import SchemaBuilder from '../helpers/cli/SchemaBuilder.js';
|
|
@@ -17,14 +18,14 @@ export default class DreamBin {
|
|
|
17
18
|
await onSync();
|
|
18
19
|
}
|
|
19
20
|
static async buildDreamSchema() {
|
|
20
|
-
|
|
21
|
+
const spinner = DreamCLI.logger.log('writing dream schema...', { spinner: true });
|
|
21
22
|
await new SchemaBuilder().build();
|
|
22
|
-
|
|
23
|
+
spinner.stop();
|
|
23
24
|
}
|
|
24
25
|
static async dbCreate() {
|
|
25
26
|
const connectionRetriever = new ConnectionConfRetriever();
|
|
26
27
|
const primaryDbConf = connectionRetriever.getConnectionConf('primary');
|
|
27
|
-
|
|
28
|
+
const spinner = DreamCLI.logger.log(`creating ${primaryDbConf.name}...`, { spinner: true });
|
|
28
29
|
await createDb('primary');
|
|
29
30
|
// TODO: add support for creating replicas. Began doing it below, but it is very tricky,
|
|
30
31
|
// and we don't need it at the moment, so kicking off for future development when we have more time
|
|
@@ -34,12 +35,12 @@ export default class DreamBin {
|
|
|
34
35
|
// console.log(`creating ${process.env[replicaDbConf.name]}`)
|
|
35
36
|
// await createDb('replica')
|
|
36
37
|
// }
|
|
37
|
-
|
|
38
|
+
spinner.stop();
|
|
38
39
|
}
|
|
39
40
|
static async dbDrop() {
|
|
40
41
|
const connectionRetriever = new ConnectionConfRetriever();
|
|
41
42
|
const primaryDbConf = connectionRetriever.getConnectionConf('primary');
|
|
42
|
-
|
|
43
|
+
const spinner = DreamCLI.logger.log(`dropping ${primaryDbConf.name}...`, { spinner: true });
|
|
43
44
|
await _dropDb('primary');
|
|
44
45
|
// TODO: add support for dropping replicas. Began doing it below, but it is very tricky,
|
|
45
46
|
// and we don't need it at the moment, so kicking off for future development when we have more time
|
|
@@ -49,19 +50,27 @@ export default class DreamBin {
|
|
|
49
50
|
// console.log(`dropping ${process.env[replicaDbConf.name]}`)
|
|
50
51
|
// await _dropDb('replica')
|
|
51
52
|
// }
|
|
52
|
-
|
|
53
|
+
spinner.stop();
|
|
53
54
|
}
|
|
54
55
|
static async dbMigrate() {
|
|
56
|
+
const connectionRetriever = new ConnectionConfRetriever();
|
|
57
|
+
const primaryDbConf = connectionRetriever.getConnectionConf('primary');
|
|
58
|
+
const spinner = DreamCLI.logger.log(`migrating ${primaryDbConf.name}...`, { spinner: true });
|
|
55
59
|
await runMigration({ mode: 'migrate' });
|
|
56
60
|
await this.duplicateDatabase();
|
|
61
|
+
spinner.stop();
|
|
57
62
|
}
|
|
58
63
|
static async dbRollback(opts) {
|
|
64
|
+
const connectionRetriever = new ConnectionConfRetriever();
|
|
65
|
+
const primaryDbConf = connectionRetriever.getConnectionConf('primary');
|
|
66
|
+
const spinner = DreamCLI.logger.log(`rolling back ${primaryDbConf.name}...`, { spinner: true });
|
|
59
67
|
let step = opts.steps;
|
|
60
68
|
while (step > 0) {
|
|
61
69
|
await runMigration({ mode: 'rollback' });
|
|
62
70
|
step -= 1;
|
|
63
71
|
}
|
|
64
72
|
await this.duplicateDatabase();
|
|
73
|
+
spinner.stop();
|
|
65
74
|
}
|
|
66
75
|
static async generateDream(fullyQualifiedModelName, columnsWithTypes, options) {
|
|
67
76
|
await generateDream({ fullyQualifiedModelName, columnsWithTypes, options });
|
|
@@ -76,9 +85,8 @@ export default class DreamBin {
|
|
|
76
85
|
// It is only made private so that people don't mistakenly try
|
|
77
86
|
// to use it to generate docs for their apps.
|
|
78
87
|
static async buildDocs() {
|
|
79
|
-
|
|
88
|
+
DreamCLI.logger.log('generating docs...');
|
|
80
89
|
await sspawn('yarn typedoc src/index.ts --tsconfig ./tsconfig.esm.build.json --out docs');
|
|
81
|
-
console.log('done!');
|
|
82
90
|
}
|
|
83
91
|
static async duplicateDatabase() {
|
|
84
92
|
const parallelTests = DreamApplication.getOrFail().parallelTests;
|
|
@@ -89,15 +97,22 @@ export default class DreamBin {
|
|
|
89
97
|
const client = await loadPgClient({ useSystemDb: true });
|
|
90
98
|
if (process.env.DREAM_CORE_DEVELOPMENT === '1') {
|
|
91
99
|
const replicaTestWorkerDatabaseName = `replica_test_${dbConf.name}`;
|
|
92
|
-
|
|
100
|
+
const spinner = DreamCLI.logger.log(`creating fake replica test database ${replicaTestWorkerDatabaseName}...`, {
|
|
101
|
+
spinner: true,
|
|
102
|
+
});
|
|
93
103
|
await client.query(`DROP DATABASE IF EXISTS ${replicaTestWorkerDatabaseName};`);
|
|
94
104
|
await client.query(`CREATE DATABASE ${replicaTestWorkerDatabaseName} TEMPLATE ${dbConf.name};`);
|
|
105
|
+
spinner.stop();
|
|
95
106
|
}
|
|
96
107
|
for (let i = 2; i <= parallelTests; i++) {
|
|
97
108
|
const workerDatabaseName = `${dbConf.name}_${i}`;
|
|
98
109
|
console.log(`creating duplicate test database ${workerDatabaseName} for concurrent tests`);
|
|
110
|
+
const spinner = DreamCLI.logger.log(`creating duplicate test database ${workerDatabaseName} for concurrent tests...`, {
|
|
111
|
+
spinner: true,
|
|
112
|
+
});
|
|
99
113
|
await client.query(`DROP DATABASE IF EXISTS ${workerDatabaseName};`);
|
|
100
114
|
await client.query(`CREATE DATABASE ${workerDatabaseName} TEMPLATE ${dbConf.name};`);
|
|
115
|
+
spinner.stop();
|
|
101
116
|
}
|
|
102
117
|
await client.end();
|
|
103
118
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { spawn } from 'child_process';
|
|
1
2
|
import { InvalidArgumentError } from 'commander';
|
|
2
3
|
import DreamBin from '../bin/index.js';
|
|
3
4
|
import EnvInternal from '../helpers/EnvInternal.js';
|
|
5
|
+
import DreamCliLogger from './logger/DreamCliLogger.js';
|
|
4
6
|
export default class DreamCLI {
|
|
5
7
|
/**
|
|
6
8
|
* use this method for initializing a standalone dream application. If using Psychic and Dream together,
|
|
@@ -142,6 +144,32 @@ export default class DreamCLI {
|
|
|
142
144
|
process.exit();
|
|
143
145
|
});
|
|
144
146
|
}
|
|
147
|
+
/*
|
|
148
|
+
* the default spawn provided by node:child_process is incompatible
|
|
149
|
+
* with promises. this will automatically wrap the spawn method,
|
|
150
|
+
* and will by default connect STDOUT to the current STDOUT,
|
|
151
|
+
* so that whatever the command is outputting is output to the
|
|
152
|
+
* primary STDOUT context.
|
|
153
|
+
*/
|
|
154
|
+
static async spawn(command, opts) {
|
|
155
|
+
return new Promise((accept, reject) => {
|
|
156
|
+
const spawnInstance = spawn(command, {
|
|
157
|
+
stdio: 'inherit',
|
|
158
|
+
shell: true,
|
|
159
|
+
...(opts || {}),
|
|
160
|
+
});
|
|
161
|
+
spawnInstance.on('close', code => {
|
|
162
|
+
if (code !== 0)
|
|
163
|
+
reject(new Error(code?.toString()));
|
|
164
|
+
accept({});
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
static get logger() {
|
|
169
|
+
this._logger ||= new DreamCliLogger();
|
|
170
|
+
return this._logger;
|
|
171
|
+
}
|
|
172
|
+
static _logger = undefined;
|
|
145
173
|
}
|
|
146
174
|
function myParseInt(value) {
|
|
147
175
|
const parsedValue = parseInt(value, 10);
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import DreamCliLoggableSpinner from './loggable/DreamCliLoggableSpinner.js';
|
|
2
|
+
import DreamCliLoggableText from './loggable/DreamCliLoggableText.js';
|
|
3
|
+
export default class DreamCliLogger {
|
|
4
|
+
logs = [];
|
|
5
|
+
log(text, { permanent = false, spinner = false, logPrefix, logPrefixColor, logPrefixBgColor, spinnerPrefixColor = 'greenBright', spinnerPrefixBgColor, } = {}) {
|
|
6
|
+
const loggable = spinner
|
|
7
|
+
? new DreamCliLoggableSpinner({
|
|
8
|
+
text,
|
|
9
|
+
permanent: false,
|
|
10
|
+
spinner: 'noise',
|
|
11
|
+
color: spinnerPrefixColor,
|
|
12
|
+
bgColor: spinnerPrefixBgColor,
|
|
13
|
+
})
|
|
14
|
+
: new DreamCliLoggableText(text, {
|
|
15
|
+
permanent,
|
|
16
|
+
logPrefix,
|
|
17
|
+
logPrefixColor: logPrefixColor || (permanent ? 'green' : 'yellow'),
|
|
18
|
+
logPrefixBgColor,
|
|
19
|
+
});
|
|
20
|
+
this.logs.push(loggable);
|
|
21
|
+
// re-render everything
|
|
22
|
+
this.render();
|
|
23
|
+
return loggable;
|
|
24
|
+
}
|
|
25
|
+
render() {
|
|
26
|
+
this.clear();
|
|
27
|
+
let skipNext = false;
|
|
28
|
+
this.logs.forEach(loggable => {
|
|
29
|
+
if (skipNext) {
|
|
30
|
+
skipNext = false;
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
loggable.render();
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
get spinners() {
|
|
37
|
+
return this.logs.filter(log => log instanceof DreamCliLoggableSpinner);
|
|
38
|
+
}
|
|
39
|
+
/*
|
|
40
|
+
* remove all logs that are not marked permanent,
|
|
41
|
+
* then clear STDOUT and re-render with only
|
|
42
|
+
* the permanent logs remaining.
|
|
43
|
+
*/
|
|
44
|
+
purge() {
|
|
45
|
+
this.logs = this.logs.filter(log => log.permanent);
|
|
46
|
+
this.render();
|
|
47
|
+
}
|
|
48
|
+
clear() {
|
|
49
|
+
console.clear();
|
|
50
|
+
// @ts-expect-error this works fine with no args provided
|
|
51
|
+
process.stdout.clearLine?.();
|
|
52
|
+
process.stdout.cursorTo?.(0);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import yoctoSpinner from 'yocto-spinner';
|
|
2
|
+
import spinners from '../loggable/spinners.js';
|
|
3
|
+
export default function createSpinner(text, spinnerKey = 'noise') {
|
|
4
|
+
return yoctoSpinner({
|
|
5
|
+
text,
|
|
6
|
+
spinner: {
|
|
7
|
+
interval: spinners[spinnerKey].interval,
|
|
8
|
+
frames: [...spinners[spinnerKey].frames],
|
|
9
|
+
},
|
|
10
|
+
}).start();
|
|
11
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import colorize from './colorize.js';
|
|
2
|
+
export default class DreamCliLoggable {
|
|
3
|
+
permanent;
|
|
4
|
+
logPrefix;
|
|
5
|
+
logPrefixColor;
|
|
6
|
+
logPrefixBgColor;
|
|
7
|
+
constructor({ permanent, logPrefix = '✺', logPrefixColor, logPrefixBgColor, }) {
|
|
8
|
+
this.permanent = permanent;
|
|
9
|
+
this.logPrefix = logPrefix;
|
|
10
|
+
this.logPrefixColor = logPrefixColor;
|
|
11
|
+
this.logPrefixBgColor = logPrefixBgColor;
|
|
12
|
+
}
|
|
13
|
+
render() {
|
|
14
|
+
throw new Error('define in base class');
|
|
15
|
+
}
|
|
16
|
+
get colorizedLogPrefix() {
|
|
17
|
+
return colorize(this.logPrefix, { color: this.logPrefixColor, bgColor: this.logPrefixBgColor });
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import createSpinner from '../helpers/createSpinner.js';
|
|
2
|
+
import DreamCliLoggable from './DreamCliLoggable.js';
|
|
3
|
+
import DreamCLI from '../../index.js';
|
|
4
|
+
export default class DreamCliLoggableSpinner extends DreamCliLoggable {
|
|
5
|
+
text;
|
|
6
|
+
spinner;
|
|
7
|
+
currentIndex = 0;
|
|
8
|
+
color;
|
|
9
|
+
bgColor;
|
|
10
|
+
lastRender;
|
|
11
|
+
_spinner;
|
|
12
|
+
constructor({ text, permanent, spinner, color, bgColor, }) {
|
|
13
|
+
super({ permanent });
|
|
14
|
+
this.text = text;
|
|
15
|
+
this.spinner = spinner;
|
|
16
|
+
this.color = color;
|
|
17
|
+
this.bgColor = bgColor;
|
|
18
|
+
}
|
|
19
|
+
render() {
|
|
20
|
+
this._spinner?.stop();
|
|
21
|
+
this._spinner = createSpinner(this.text, this.spinner);
|
|
22
|
+
}
|
|
23
|
+
stop(message = this.text + ' done!') {
|
|
24
|
+
this._spinner.stop();
|
|
25
|
+
DreamCLI.logger.purge();
|
|
26
|
+
DreamCLI.logger.log(message, { permanent: true });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import colorize from './colorize.js';
|
|
2
|
+
import DreamCliLoggable from './DreamCliLoggable.js';
|
|
3
|
+
export default class DreamCliLoggableText extends DreamCliLoggable {
|
|
4
|
+
text;
|
|
5
|
+
color;
|
|
6
|
+
bgColor;
|
|
7
|
+
constructor(text, { permanent, logPrefix, color, bgColor, logPrefixColor, logPrefixBgColor, }) {
|
|
8
|
+
super({ permanent, logPrefix });
|
|
9
|
+
this.text = text;
|
|
10
|
+
this.color = color;
|
|
11
|
+
this.bgColor = bgColor;
|
|
12
|
+
this.logPrefixColor = logPrefixColor;
|
|
13
|
+
this.logPrefixBgColor = logPrefixBgColor;
|
|
14
|
+
}
|
|
15
|
+
render() {
|
|
16
|
+
console.log(`${this.colorizedLogPrefix} ${colorize(this.text, { color: this.color, bgColor: this.bgColor })}`);
|
|
17
|
+
}
|
|
18
|
+
}
|