2024-10-11 17:14:21 +02:00
|
|
|
#include <QDir>
|
2023-09-28 10:11:47 +02:00
|
|
|
#include <QGuiApplication>
|
2025-04-01 16:20:44 +02:00
|
|
|
#include <QLibraryInfo>
|
2023-09-28 10:11:47 +02:00
|
|
|
#include <QQmlApplicationEngine>
|
|
|
|
|
|
2024-10-11 17:14:21 +02:00
|
|
|
#include <StatusQ/typesregistration.h>
|
2023-09-28 10:11:47 +02:00
|
|
|
|
2025-08-05 10:44:01 +02:00
|
|
|
using namespace Qt::Literals::StringLiterals;
|
|
|
|
|
|
2023-09-28 10:11:47 +02:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
|
{
|
2025-07-24 17:19:53 +02:00
|
|
|
Q_INIT_RESOURCE(storybook);
|
|
|
|
|
|
2023-09-28 10:11:47 +02:00
|
|
|
QGuiApplication app(argc, argv);
|
2026-03-17 15:27:19 +04:00
|
|
|
|
2025-08-05 10:44:01 +02:00
|
|
|
QGuiApplication::setOrganizationName(u"Status"_s);
|
|
|
|
|
QGuiApplication::setOrganizationDomain(u"status.im"_s);
|
2023-09-28 10:11:47 +02:00
|
|
|
|
2025-08-05 10:44:01 +02:00
|
|
|
const QString pagesPath = QML_IMPORT_ROOT u"/pages"_s;
|
2023-09-28 10:11:47 +02:00
|
|
|
QDir pagesDir(pagesPath);
|
2025-08-05 10:44:01 +02:00
|
|
|
const QFileInfoList files = pagesDir.entryInfoList({u"*Page.qml"_s},
|
2024-03-08 17:20:20 +01:00
|
|
|
QDir::Files,
|
|
|
|
|
QDir::Name);
|
2023-09-28 10:11:47 +02:00
|
|
|
|
2024-03-08 17:20:20 +01:00
|
|
|
const QStringList additionalImportPaths{STATUSQ_MODULE_IMPORT_PATH,
|
2025-08-05 10:44:01 +02:00
|
|
|
u"qrc:/"_s,
|
|
|
|
|
QML_IMPORT_ROOT u"/../ui/app"_s,
|
|
|
|
|
QML_IMPORT_ROOT u"/../ui/imports"_s,
|
|
|
|
|
QML_IMPORT_ROOT u"/src"_s,
|
|
|
|
|
QML_IMPORT_ROOT u"/stubs"_s};
|
2023-09-28 10:11:47 +02:00
|
|
|
|
2024-03-08 17:20:20 +01:00
|
|
|
int errorCount = 0;
|
2024-05-20 12:23:56 +03:00
|
|
|
QStringList warnings;
|
|
|
|
|
QStringList failedPages;
|
2025-04-01 16:20:44 +02:00
|
|
|
|
2025-08-05 10:44:01 +02:00
|
|
|
qInfo() << ">>> StoryBook page verification started; Qt runtime version:"
|
|
|
|
|
<< qVersion() << "; built against version:"
|
|
|
|
|
<< QLibraryInfo::version().toString();
|
2025-04-01 16:20:44 +02:00
|
|
|
|
|
|
|
|
registerStatusQTypes();
|
2024-05-20 12:23:56 +03:00
|
|
|
|
2024-03-08 17:20:20 +01:00
|
|
|
for (const auto &fileInfo : files) {
|
2024-05-20 12:23:56 +03:00
|
|
|
warnings.clear();
|
2024-03-08 17:20:20 +01:00
|
|
|
QQmlApplicationEngine engine;
|
|
|
|
|
engine.setOutputWarningsToStandardError(false);
|
|
|
|
|
engine.setBaseUrl(QUrl::fromLocalFile(pagesPath + QDir::separator()));
|
2023-09-28 10:11:47 +02:00
|
|
|
|
2024-03-08 17:20:20 +01:00
|
|
|
for (const auto &path : additionalImportPaths)
|
|
|
|
|
engine.addImportPath(path);
|
2023-09-28 10:11:47 +02:00
|
|
|
|
2025-08-05 10:44:01 +02:00
|
|
|
QObject::connect(&engine, &QQmlApplicationEngine::warnings, &app,
|
|
|
|
|
[&warnings](const QList<QQmlError> &qmlWarnings) {
|
2024-05-20 12:23:56 +03:00
|
|
|
for (const auto &qmlWarning: qmlWarnings)
|
|
|
|
|
warnings.append(qmlWarning.toString());
|
|
|
|
|
});
|
|
|
|
|
|
2024-03-08 17:20:20 +01:00
|
|
|
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
|
2025-04-01 16:20:44 +02:00
|
|
|
&app, [&errorCount, &warnings, &failedPages](QObject *obj, const QUrl &objUrl) {
|
2024-03-08 17:20:20 +01:00
|
|
|
if (!obj) {
|
|
|
|
|
errorCount++;
|
2024-05-20 12:23:56 +03:00
|
|
|
failedPages << objUrl.toLocalFile();
|
|
|
|
|
|
2025-03-25 10:28:29 +01:00
|
|
|
for (const auto &warning: std::as_const(warnings))
|
2024-05-20 12:23:56 +03:00
|
|
|
qWarning() << " " << warning;
|
2024-03-08 17:20:20 +01:00
|
|
|
}
|
|
|
|
|
});
|
2023-09-28 10:11:47 +02:00
|
|
|
|
2024-03-08 17:20:20 +01:00
|
|
|
auto fileName = fileInfo.filePath();
|
|
|
|
|
qInfo() << ">>> Checking StoryBook page:" << fileName;
|
2023-09-28 10:11:47 +02:00
|
|
|
|
2024-03-08 17:20:20 +01:00
|
|
|
engine.load(fileName);
|
2023-09-28 10:11:47 +02:00
|
|
|
}
|
|
|
|
|
|
2024-03-08 17:20:20 +01:00
|
|
|
if (errorCount) {
|
|
|
|
|
qWarning() << ">>> StoryBook page verification failed with" << errorCount << "errors.";
|
2024-05-20 12:23:56 +03:00
|
|
|
qWarning() << ">>> StoryBook pages with errors:" << failedPages;
|
|
|
|
|
|
2023-09-28 10:11:47 +02:00
|
|
|
return EXIT_FAILURE;
|
2024-03-08 17:20:20 +01:00
|
|
|
}
|
2023-09-28 10:11:47 +02:00
|
|
|
|
2024-03-08 17:20:20 +01:00
|
|
|
qInfo() << ">>> StoryBook page verification completed successfully.";
|
2023-09-28 10:11:47 +02:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
|
}
|