composer自定义安装目录 - root

时间:2017-06-02 14:31:51

标签: wordpress composer-php

我们正在尝试使用composer来处理wordpress站点的依赖关系。我想在这些依赖项中包含wordpress本身。我正在尝试将wordpress安装到项目的根目录。所有其他插件等都是基于installer-paths ..

正确安装的

我尝试过使用fancyguy / webroot-installer,但是擦除了安装包的目录 还尝试了mnsami / composer-custom-directory-installer,但这也擦除了目录。

我在root中有一些我不想删除的文件 - 比如composer.json,一个.tfignore等等。

是我必须让它安装到/ vendor然后运行安装后脚本以将其移动到我想要的地方的唯一选项吗?还是有其他我缺少的选择

这是我为webroot-installer

尝试的那个
{
  "name": "the/name",
  "description": "description",
  "repositories": [
    {
      "type": "composer",
      "url": "https://wpackagist.org"
    },
    {
      "type": "package",
      "package": {
        "name": "wordpress",
        "type": "webroot",
        "version": "4.7.5",
        "dist": {
          "type": "zip",
          "url": "https://github.com/WordPress/WordPress/archive/4.7.5.zip"
        },
        "require": {
          "fancyguy/webroot-installer": "1.0.0"
        }
      }
    }
  ],
  "require-dev": {
    "wpackagist-plugin/query-monitor": "2.13.4",
    "wordpress": "4.7.5",
    "fancyguy/webroot-installer": "1.0.0"
  },
  "require": {
    "wpackagist-plugin/advanced-custom-fields": "4.4.11",
    ...etc
  },
  "extra": {
    "webroot-dir": ".",
    "webroot-package": "wordpress",
    "installer-paths": {
      "library/plugins/{$name}": [ "type:wordpress-plugin" ]
    }
  },
  "scripts": { ...}
}

这是使用composer-custom-directory-installer的composer.json。

{
  "name": "the/name",
  "description": "description",
  "repositories": [
    {
      "type": "composer",
      "url": "https://wpackagist.org"
    },
    {
      "type": "package",
      "package": {
        "name": "wordpress",
        "type": "library",
        "version": "4.7.5",
        "dist": {
          "type": "zip",
          "url": "https://github.com/WordPress/WordPress/archive/4.7.5.zip"
        }
      }
    }
  ],
  "require-dev": {
    "mnsami/composer-custom-directory-installer": "1.1.*",
    "wordpress": "4.7.5"
  },
  "require": {
    "wpackagist-plugin/advanced-custom-fields": "4.4.11",
    ...etc
  },
  "extra": {
    "installer-paths": {
      "library/plugins/{$name}": [ "type:wordpress-plugin" ],
      "./": [ "wordpress" ]
    }

  },
  "scripts": { ... }
}

2 个答案:

答案 0 :(得分:1)

我认为这就是作曲家安装程序的工作方式。从我已经完成的阅读中删除旧文件,以确保版本没有任何交叉污染。它不像git checkout / merge那样可以处理差异,而是在需要时进行干净安装(缓存类型的东西)。

我建议不要将您正在创作的任何文件保存在正在安装内容的同一文件夹中,而是采取将所有内容安装并编译到分发文件夹中的方法。

利用web pack或gulp等工具,加上NPM和composer来处理所有编译,并将您的分发文件夹保存为可以被吹走和复制的东西。它增加了一些开销,但允许所有工具进行交互而不会导致文件丢失。

例如我的典型回购看起来如下。有了所有不同的工具,dist完全被gitignored,但是编写器和构建工具会编译进去。从那里,如果我想要FTP或使用CI / CD我可以,但我有一个永远不会存储的干净文件夹,并且在我运行工具后包含整个项目。

/dist
/src (where any files I'm authoring reside)
composer.json
package.json
gulpfile.js
etc...

快速更新至。我正在做更多的游戏。似乎扩展版本的composer安装程序不会安装其他目录。我最终做了以下似乎每次都工作的东西(尽管仍然需要测试部署)

"extra": {
    "installer-types": ["cms-core"],
    "installer-paths": {
        "public/wp": ["type:cms-core"],
        "public/wp-content/plugins/{$name}/": ["type:wordpress-plugin"],
        "public/wp-content/themes/{$name}/": ["type:wordpress-theme"]
    }
},
"repositories":[
    {
        "type": "composer",
        "url": "https://wpackagist.org"
    },
    {
        "type": "package",
        "package": {
            "name": "wordpress",
            "type": "cms-core",
            "version": "4.7.5",
            "dist": {
                "type": "zip",
                "url": "https://github.com/WordPress/WordPress/archive/4.7.5.zip"
            }
        }
    }
],
"require": {
    "composer/installers": "^1.3",
    "oomphinc/composer-installers-extender": "^1.1",
    "wpackagist-plugin/wordpress-seo": "^4.8",
    "wordpress": "^4.7"
},
"scripts": {
    "post-update-cmd": [
        "cp -R public/wp/ public && rm -rf public/wp"
    ]
}`

答案 1 :(得分:0)

对于任何尝试将Wordpress与Composer结合使用的新访客,请签出https://github.com/johnpbloch/wordpress以获取使用自定义Composer安装程序的实现。完整的详细信息和示例可在https://composer.rarst.net/中找到,但是要点是:

composer.json:

{
    "name"        : "my/wordpress-project",
    "description" : "Test project for WordPress stack via Composer",
    "type"        : "project",
    "repositories": [
        {
            "type": "composer",
            "url" : "https://wpackagist.org"
        }
    ],
    "config"      : {
        "vendor-dir": "wp-content/vendor"
    },
    "require"     : {
        "johnpbloch/wordpress" : ">=5",
        "wpackagist-plugin/a-fresher-cache" : "*",
        "wpackagist-plugin/core-control" : "*",
        "wpackagist-plugin/monster-widget" : "*",
        "wpackagist-plugin/theme-check" : "*",
        "wpackagist-plugin/user-switching" : "*",
        "wpackagist-plugin/wcm-user-language-switcher" : "*"
    },
    "extra"       : {
        "installer-paths" : {
            "wp-content/plugins/{$name}/": ["type:wordpress-plugin"]
            "wp-content/themes/{$name}/": ["type:wordpress-theme"]
        }

        "wordpress-install-dir": "wp"
    }
}

这会将Wordpress安装到/ wp文件夹中。您将需要修改.htaccess使其适合,详情如下:https://wordpress.org/support/article/giving-wordpress-its-own-directory/

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^(www.)?example.com$
    RewriteCond %{REQUEST_URI} !^/wp/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /wp/$1
    RewriteCond %{HTTP_HOST} ^(www.)?example.com$
    RewriteRule ^(/)?$ wp/index.php [L]
</IfModule>