Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(node): cnpm仓库地址更换 #745

Merged
merged 1 commit into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 the original author or authors.
* Copyright (c) 2023-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -36,7 +36,7 @@ import pub.ihub.plugin.node.IHubNodeExtension
abstract class CnpmSetupTask extends NpmSetupTask {

static final String NAME = 'cnpmSetup'
static final String REGISTRY = 'https://registry.npm.taobao.org'
static final String REGISTRY = 'https://registry.npmmirror.com'

@Input
@Optional
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2023 the original author or authors.
* Copyright (c) 2021-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,7 +24,6 @@ import pub.ihub.plugin.IHubPluginsPlugin
import pub.ihub.plugin.IHubProjectPluginAware



/**
* Gradle版权插件
* @author liheng
Expand Down Expand Up @@ -71,46 +70,44 @@ class IHubCopyrightPlugin extends IHubProjectPluginAware {
}

private static void configCopyrightManager(Project rootProject, String copyrightName) {
File settings = rootProject.file '.idea/copyright/profiles_settings.xml'
File settingsFile = rootProject.file '.idea/copyright/profiles_settings.xml'
List modules = ['Project Files', 'All Changed Files']
Document component
if (settings.exists()) {
component = XmlUtil.readXML settings.path
Node elements = XmlUtil.getNodeByXPath 'module2copyright',
XmlUtil.getNodeByXPath('settings', component.documentElement)
if (elements) {
if (XmlUtil.getNodeByXPath("element[@copyright=\"$copyrightName\"]", elements)) {
return
}
modules.each { module ->
if (!XmlUtil.getNodeByXPath("element[@module=\"$module\"]", elements)) {
appendChild elements, 'element', [module: module, copyright: copyrightName]
}
}
XmlUtil.toFile component, settings.path
Document component = settingsFile.exists() ? XmlUtil.readXML(settingsFile.path) :
XmlUtil.createXml('component').tap {
documentElement.setAttribute 'name', 'CopyrightManager'
}
} else {
component = XmlUtil.createXml 'component'
Node settings = appendChild component.documentElement, 'settings'
Node module2copyright = appendChild settings, 'module2copyright'
if (XmlUtil.getNodeByXPath("element[@copyright=\"$copyrightName\"]", module2copyright)) {
return
}
Node elements = appendChild appendChild(component.documentElement.tap {
setAttribute 'name', 'CopyrightManager'
}, 'settings'), 'module2copyright'
modules.each { module ->
appendChild elements, 'element', [module: module, copyright: copyrightName]
appendChild module2copyright, 'element', module, [module: module, copyright: copyrightName]
}
XmlUtil.toFile component, settings.path
appendOption appendChild(settings, 'LanguageOptions', [name: '__TEMPLATE__']), 'addBlankAfter', 'false'
XmlUtil.toFile component, settingsFile.path
}

private static Node appendChild(Node node, String name, Map<String, String> attributes = [:]) {
private static Node appendChild(Node node, String name) {
XmlUtil.getNodeByXPath(name, node) ?: XmlUtil.appendChild(node, name)
}

private static Node appendChild(Node node, String name, String module, Map<String, String> attributes) {
XmlUtil.getNodeByXPath("$name[@module=\"$module\"]", node) ?: appendChild(node, name, attributes)
}

private static Node appendChild(Node node, String name, Map<String, String> attributes) {
XmlUtil.appendChild(node, name).tap {
attributes.each { k, v ->
setAttribute k, v
}
}
}

private static Node appendOption(Node node, String name, String value) {
appendChild node, 'option', [name: name, value: value]
private static void appendOption(Node node, String name, String value) {
if (!XmlUtil.getNodeByXPath("option[@name=\"$name\"]", node)) {
appendChild node, 'option', [name: name, value: value]
}
}

}
Loading