posthtml / posthtml-cli

CLI for PostHTML
MIT License
29 stars 18 forks source link

posthtml-cli not working properly #326

Closed nauvalazhar closed 4 years ago

nauvalazhar commented 4 years ago

Hi,

I use posthtml-cli, when I build like this:

posthtml -c posthtml.json

The command doesn't output any output and doesn't compile anything.

Here is the configuration:

{
  "root": "./src",
  "input": "./src/*.html",
  "output": "dist",
  "plugins": {
    "posthtml-include": {
      "root": "./src/partials"
    },
    "posthtml-extend": {
      "root": "./src/layouts"
    }
  }
}

And here is my package.json file:

{
  "name": "test",
  "version": "1.0.0",
  "main": "index.js",
  "devDependencies": {
    "@babel/cli": "^7.11.6",
    "@babel/core": "^7.11.6",
    "@babel/polyfill": "^7.11.5",
    "@babel/preset-env": "^7.11.5",
    "cpx": "^1.5.0",
    "imagemin-cli": "^6.0.0",
    "lite-server": "^2.5.4",
    "nodemon": "^2.0.4",
    "npm-run-all": "^4.1.5",
    "posthtml-cli": "^0.7.6",
    "posthtml-extend": "^0.5.0",
    "posthtml-include": "^1.4.3",
    "cross-env": "^7.0.2"
  },
  "dependencies": {
    "tailwindcss": "^1.8.7",
    "@tailwindcss/custom-forms": "^0.2.1"
  },
  "scripts": {
    "html": "posthtml -c posthtml.json",
    "watch:html": "nodemon -w src/**/*.html -e html -x \"posthtml -c posthtml.json\"",
    "tailwind": "tailwindcss build src/css/style.css -o dist/css/style.css",
    "watch:tailwind": "nodemon -w src/css -w tailwind.config.js -e css,js -x \"tailwindcss build src/css/style.css -o dist/css/style.css\"",
    "js": "babel src/js -d dist/js",
    "watch:js": "babel src/js -d dist/js -w",
    "img": "imagemin src/images/* -o dist/images",
    "watch:img": "cpx \"src/images/**/*.*\" dist/images --watch",
    "server": "lite-server -c server.json",
    "watch": "npm-run-all --parallel watch:* server",
    "dev": "npm-run-all tailwind html js img",
    "prod": "cross-env NODE_ENV=production npm-run-all html tailwind js img"
  }
}

And here's my folder structure:

- src/index.html
- src/layouts/layout.html
- posthtml.json
- package.json

Thank you for making this awesome tool!

Scrum commented 4 years ago

@nauvalazhar Hi, I created an example in which everything works, clarify what exactly does not work for you

nauvalazhar commented 4 years ago

But, mine still not working. Can I have a full example of yours? image

Scrum commented 4 years ago

@nauvalazhar You can freely clone this example https://github.com/posthtml-issues/posthtml-cli-issue-326, make changes to it that reproduce your error. Feel free

turusuke commented 4 years ago

@Scrum When the root option is enabled, it does not appear to be running. 😒 I think it's because of this change. https://github.com/posthtml/posthtml-cli/blob/2447d87d05d557ff7c079452196985850a0b8d0f/src/cfg-resolve.js#L73

I have verified the following.

Input folder tree

inputDir
└── parent
    β”œβ”€β”€ about
    β”‚Β Β  └── index.html
    β”œβ”€β”€ fuga
    β”‚Β Β  β”œβ”€β”€ index.html
    β”‚Β Β  └── wao
    β”‚Β Β      └── index.html
    β”œβ”€β”€ index.html
    └── other.html

Execute the following command in the current state.

node lib/cli.js inputDir/**/*.html -o outputDir --root inputDir -a

As a result, nothing is output. So I tried to make the following change.

--${ignoreSymbol}${normalizePath(path.join(path.resolve(root), file))}
++${ignoreSymbol}${normalizePath(file)}

Do the same with posthtml-cli

node lib/cli.js inputDir/**/*.html -o outputDir --root inputDir -a

I got the correct output.

Output folder tree

outputDir
└── parent
    β”œβ”€β”€ about
    β”‚Β Β  └── index.html
    β”œβ”€β”€ fuga
    β”‚Β Β  β”œβ”€β”€ index.html
    β”‚Β Β  └── wao
    β”‚Β Β      └── index.html
    β”œβ”€β”€ index.html
    └── other.html

I tried to make a pull request, but the test failed, so I couldn't push it. πŸ˜… So I'll share with you what I think is the cause of the problem ahead of time.

Scrum commented 4 years ago

@nauvalazhar @turusuke Thank you, I still managed to find the problem thanks to you.

Scrum commented 4 years ago

Also, pay attention to the correctness of the input files, they should not contain the folder specified in root

node lib/cli.js **/*.html -o outputDir --root inputDir -a