fix import de-duplication
This commit is contained in:
parent
689403ad4e
commit
4199b9c7b7
6 changed files with 72 additions and 23 deletions
|
@ -49,9 +49,6 @@ SettingsNodejs::SettingsNodejs(Settings* settings, QWidget* parent) : SettingsPa
|
|||
connect(m_ui.m_btnNpmExecutable, &QPushButton::clicked, this, [this]() {
|
||||
changeFileFolder(m_ui.m_tbPackageFolder, false, QSL("NPM (npm*)"));
|
||||
});
|
||||
|
||||
// FOR ME: npm install --prefix "složka"
|
||||
// NODE_PATH="složka" node.exe....
|
||||
}
|
||||
|
||||
void SettingsNodejs::changeFileFolder(LineEditWithStatus* tb, bool directory_select, const QString& file_filter) {
|
||||
|
@ -92,6 +89,10 @@ void SettingsNodejs::loadSettings() {
|
|||
void SettingsNodejs::saveSettings() {
|
||||
onBeginSaveSettings();
|
||||
|
||||
qApp->nodejs()->setNodeJsExecutable(m_ui.m_tbNodeExecutable->lineEdit()->text());
|
||||
qApp->nodejs()->setNpmExecutable(m_ui.m_tbNpmExecutable->lineEdit()->text());
|
||||
qApp->nodejs()->setPackageFolder(m_ui.m_tbPackageFolder->lineEdit()->text());
|
||||
|
||||
onEndSaveSettings();
|
||||
}
|
||||
|
||||
|
|
|
@ -96,7 +96,8 @@ bool IOFactory::startProcessDetached(const QString& program, const QStringList&
|
|||
|
||||
QString IOFactory::startProcessGetOutput(const QString& executable,
|
||||
const QStringList& arguments,
|
||||
const QProcessEnvironment& pe) {
|
||||
const QProcessEnvironment& pe,
|
||||
const QString& working_directory) {
|
||||
QProcess proc;
|
||||
|
||||
proc.setProgram(executable);
|
||||
|
@ -106,6 +107,11 @@ QString IOFactory::startProcessGetOutput(const QString& executable,
|
|||
|
||||
system_pe.insert(pe);
|
||||
proc.setProcessEnvironment(system_pe);
|
||||
|
||||
if (!working_directory.isEmpty()) {
|
||||
proc.setWorkingDirectory(working_directory);
|
||||
}
|
||||
|
||||
proc.start();
|
||||
|
||||
if (proc.waitForFinished() &&
|
||||
|
|
|
@ -34,7 +34,8 @@ class IOFactory {
|
|||
const QString& working_directory = {});
|
||||
static QString startProcessGetOutput(const QString& executable,
|
||||
const QStringList& arguments = {},
|
||||
const QProcessEnvironment& pe = {});
|
||||
const QProcessEnvironment& pe = {},
|
||||
const QString& working_directory = {});
|
||||
|
||||
// Returns contents of a file.
|
||||
// Throws exception when no such file exists.
|
||||
|
|
|
@ -27,6 +27,10 @@ void NodeJs::setNpmExecutable(const QString& exe) const {
|
|||
m_settings->setValue(GROUP(Node), Node::NpmExecutable, exe);
|
||||
}
|
||||
|
||||
void NodeJs::setPackageFolder(const QString& path) {
|
||||
m_settings->setValue(GROUP(Node), Node::PackageFolder, path);
|
||||
}
|
||||
|
||||
QString NodeJs::packageFolder() const {
|
||||
QString path = QDir::toNativeSeparators(m_settings->value(GROUP(Node), SETTING(Node::PackageFolder)).toString());
|
||||
|
||||
|
@ -40,11 +44,9 @@ QString NodeJs::processedPackageFolder() const {
|
|||
qCriticalNN << LOGSEC_NODEJS << "Failed to create package folder structure" << QUOTE_W_SPACE_DOT(path);
|
||||
}
|
||||
|
||||
return path;
|
||||
return QDir::toNativeSeparators(path);
|
||||
}
|
||||
|
||||
void NodeJs::setPackageFolder(const QString& path) {}
|
||||
|
||||
QString NodeJs::nodejsVersion(const QString& nodejs_exe) const {
|
||||
if (nodejs_exe.simplified().isEmpty()) {
|
||||
throw ApplicationException(tr("file not found"));
|
||||
|
@ -60,3 +62,16 @@ QString NodeJs::npmVersion(const QString& npm_exe) const {
|
|||
|
||||
return IOFactory::startProcessGetOutput(npm_exe, { QSL("--version") }).simplified();
|
||||
}
|
||||
|
||||
NodeJs::PackageStatus NodeJs::packageStatus(const PackageMetadata& pkg) const {
|
||||
//npm ls --unicode --json --prefix "."
|
||||
|
||||
QString npm_ls = IOFactory::startProcessGetOutput(npmExecutable(),
|
||||
{ QSL("ls"), QSL("--unicode"), QSL("--json"), QSL("--prefix"),
|
||||
processedPackageFolder() });
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
void NodeJs::installPackage(const PackageMetadata& pkg)
|
||||
{}
|
||||
|
|
|
@ -10,6 +10,28 @@ class Settings;
|
|||
class NodeJs : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
struct PackageMetadata {
|
||||
public:
|
||||
|
||||
// Name of package.
|
||||
QString m_name;
|
||||
|
||||
// Version description. This could be fixed version or empty
|
||||
// string (latest version) or perhaps version range.
|
||||
QString m_version;
|
||||
};
|
||||
|
||||
enum class PackageStatus {
|
||||
// Package not installed.
|
||||
NotInstalled,
|
||||
|
||||
// Package installed but out-of-date.
|
||||
OutOfDate,
|
||||
|
||||
// Package installed and up-to-date.
|
||||
UpToDate
|
||||
};
|
||||
|
||||
public:
|
||||
explicit NodeJs(Settings* settings, QObject* parent = nullptr);
|
||||
|
||||
|
@ -26,6 +48,19 @@ class NodeJs : public QObject {
|
|||
QString nodejsVersion(const QString& nodejs_exe) const;
|
||||
QString npmVersion(const QString& npm_exe) const;
|
||||
|
||||
// Checks status of package.
|
||||
//
|
||||
// NOTE: https://docs.npmjs.com/cli/v8/commands/npm-ls
|
||||
PackageStatus packageStatus(const PackageMetadata& pkg) const;
|
||||
|
||||
// Installs package.
|
||||
//
|
||||
// If package is NOT installed, then it is installed.
|
||||
// If package IS installed but out-of-date, it is updated to desired versions.
|
||||
//
|
||||
// NOTE: https://docs.npmjs.com/cli/v8/commands/npm-install
|
||||
void installPackage(const PackageMetadata& pkg);
|
||||
|
||||
private:
|
||||
Settings* m_settings;
|
||||
};
|
||||
|
|
|
@ -358,22 +358,13 @@ bool StandardServiceRoot::mergeImportExportModel(FeedsImportExportModel* model,
|
|||
}
|
||||
else if (source_item->kind() == RootItem::Kind::Feed) {
|
||||
auto* source_feed = qobject_cast<StandardFeed*>(source_item);
|
||||
const auto items = target_root_node->childItems();
|
||||
bool already_exists = false;
|
||||
for (auto i : items) {
|
||||
auto feed = qobject_cast<StandardFeed*>(i);
|
||||
if (feed == nullptr) {
|
||||
continue;
|
||||
}
|
||||
const auto* feed_with_same_url = target_root_node->getItemFromSubTree([source_feed](const RootItem* it) {
|
||||
return it->kind() == RootItem::Kind::Feed &&
|
||||
it->toFeed()->source().toLower() == source_feed->source().toLower();
|
||||
});
|
||||
|
||||
if (feed->source() == source_feed->source()) {
|
||||
already_exists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (already_exists) {
|
||||
continue;
|
||||
if (feed_with_same_url != nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto* new_feed = new StandardFeed(*source_feed);
|
||||
|
|
Loading…
Add table
Reference in a new issue