I have published a package on npm. Sometime last night I tried to install it and run it locally.
I am getting this error: missing script: new-post even though I have the script object in my package.json file.
Here is my package file:
{
"name": "new-post-gatsby-starter-blog",
"version": "1.1.5",
"description": "create a new post in gatsby starter blog format with a simple command",
"main": "/bin/index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/twhite96/gatsby-starter-blog-new-post.git"
},
"bin": {
"new-post": "bin/new-post.js"
},
"keywords": [
"gatsby-starter-blog",
"blog",
"post",
"gatsby",
"npm"
],
"author": "Tiffany White",
"license": "MIT",
"bugs": {
"url": "https://github.com/twhite96/gatsby-starter-blog-new-post/issues"
},
"homepage": "https://github.com/twhite96/gatsby-starter-blog-new-post#readme",
"devDependencies": {
"date-fns": "^1.30.1",
"slug": "^0.9.3",
"slugify": "^1.3.4"
},
"dependencies": {
"shelljs": "^0.8.3"
},
"scripts": {
"new-post": "new-post"
}
}
My directory structure is a bin folder at the root of the package and inside that bin folder is the executable, new-post.js.
My executable file is basic JS:
#!/usr/bin/env node
const fs = require('fs');
const slugify = require('slug');
const dateFns = require('date-fns');
const title = process.argv[2];
const shell = require(shelljs);
if (!title) {
throw 'a title is required!';
}
const slug = slugify(title.toLowerCase());
const date = dateFns.format(new Date(), 'YYYY-MM-DD');
const dir = `./src/pages/${slug}`;
if (!dir) {
throw 'this directory does not exist!';
}
fs.writeFileSync(
`${dir}.md`,
`---
date: ${date}
title: "${title}"
author:
spoiler:
---`,
function(err) {
if (err) {
return console.log(err);
}
console.log(`${title} was created!`);
}
);
shell.exec('node bin/new-post.js')
Not sure what I am doing wrong here.
I am on macOS 10.14.3
Using node 11.8 and the latest npm