Publish npm package project directly to github repository - github

Please note, i'm new to npm package manager.
I've created a simple bootstrap 4 sass+gulp starter project using npm package commands and scripts. Now i want to publish this project in a new github repository. I understand i can manually create a github repo, copy my project files and commit.
However, im curious
- to learn the better workflow / approach.
- Is there any npm tool /workflow for any github integration, for publishing?
- Is that the better approach first to create the github repository for any such project? clone then do other stuffs?
This time its only the artifacts. But, latter it might be a project with source where the project dependent artifacts will hold in npm package manager. However, i also noticed that lots of artifacts available in npm packages also has a github repo.

Git Commit
git add -A . && git commit -a -m 'gh-pages update'
Publish to Git
git push origin gh-pages --force && git checkout master
Make sure you're inside the folder of the package you need to publish onto Github for all the commands to work.
Publish to NPM
(Just in case)
Make sure you have name and package entries in your package.json file, then:
npm adduser
Verify that your user is set properly by running npm config ls finally npm publish should do the trick

Related

Add Husky(Git Hooks) into Azure DevOps Project

My repository is on AzureDevops, and I cloned it by the button: "Clone in VS Code". The repository was cloned correctly. I have the files from package.json, .gitignore, etc...
But I don't have a .git folder. And I would like to install some tool to standardize code commits. I try to install husky 7 but it doesn't find the .git folder which doesn't really exist.
Is there any way to use git hooks for the repository within Azure Devops?
Is there any other tool for standardizing commits that works in an Azure Devops repository?
When i try to install husky, i get that error: .git can't be found (see https://git.io/Jc3F9)
husky -v = ^7.0.0,
npm -v = 6.14.12

Run commands in codeship without vm for every commit in a branch

I want to deploy my application in github page. I want the build job to be automated. My build commands basically include running unit tests,building a production version, gh-deploy command to deploy to github page. Can i achieve this using code ship. Do i require a actual vm like ec2 to do this?
The official automation process with codeship involves pushing to GitHub.
If your build process can populate the content you want to publish, then you can simply push it from the codeship job itself.
As an example, see "Auto-deploying to gh-pages with Codeship " (Martyn Chamberlin), which is about publishing a Gulp build:
git clone <the ssh link to your repo> dist
cd dist
git checkout gh-pages || git checkout --orphan gh-pages
cd ..
rm -rf dist/**/* || exit 0
npm install
gulp deploy
cd dist
git config user.email "<the email address you used for your machine user GitHub account>"
git config user.name "<the username you used for your machine user GitHub account>"
git add .
git commit -m "Deploy to GitHub Pages: ${CI_COMMIT_ID} --skip-ci"
git push origin gh-pages
This is a clever little set of commands, really.
It’s creating a git repo inside of another git repo in order to handle the build correctly.
I wish I could say I was the one who came up with this idea but the hat tip belongs to Domenic who gave me the idea with his Travis gist.
A few things to note about this:
This assumes that npm install; gulp deploy is the series of commands you use to combine and minify your assets.
That’s true of my project but yours may be different (particularly the second one). Be sure to replace lines 6 and 7 with your actual ones (as well as the values, of course).
This also assumes your output directory is dist. Hopefully it is, because that’s the convention, but if you’ve got something else, you’ll need to update lines 1, 2, and 8.
I’m completely bypassing Codeship’s recommendation of handling the final git push via their own provided code (“include the commands from continuous-deployments/git-push.sh”).
Not a big deal either way, I just don’t see the need for an extra HTTP request.

host github pages from /dist folder in master branch

I was trying to publish my -username-.github.io repository to github pages but my index.html is inside dist folder.
I cannot use git subtree push --prefix dist origin gh-pages because this is meant for project pages, not user/org pages.
All I want is, github to treat dist as root directory for hosting user/org page. Please help.Thanks
PS: I don't want to do redirection hack.
Configuring a publishing source for GitHub Pages (very limited)
While you can select a folder as the source for gh-pages, you can only do so for the /docs directory at the parent level, and you still have to actually commit the built files in order to do so, which means you'll have to override the .gitignore and commit them twice
Automated Deploy Scripts
If you're using npm, there are a couple packages that handle publishing sub-directories to gh-pages. Install with option --save-dev to add it to your devDependencies:
push-dir
# install
$ npm install push-dir --save-dev
# usage
$ push-dir --dir=dist --branch=gh-pages
gh-pages
# install
$ npm install gh-pages --save-dev
# usage
$ gh-pages -d dist
In either case, if get a command line tool working for you and get it configured with the right options, you can alias it in your package.json like this:
"scripts": {
"deploy": "npm run build && gh-pages -d dist"
}
Further Reading:
Deploying a subfolder to GitHub Pages
Deploy Vue to GitHub pages-the easy way!
You can't do it this way.
GitHub pages can be hosted from either:
the / folder in the master branch
the / folder in the gh-pages branch
the /docs folder in the master branch
But the user pages must be built from the / folder in the master branch.
TIP
Code on another branch than the master. After every push to this branch, build it in any CI/CD tool and push it back to the master branch.
If like me you would prefer to upload to github pages using subtree's in git you can use something like the code below.
git subtree push --prefix dist origin gh-pages

If I create a git repo on github, does it automatically become a npm package?

Question1:
If I create a git repo on github, does it automatically become a npm package?
Question2:
If I publish a public NPM package, does it automatically shows up on github?

How to run npm install on github

I would like to run npm install on GitHub. I tried doing so by cloning the repository through GitHub Desktop, but nothing happens on the online copy of the repo when I commit the changes.
I am trying to do this for parse-server.
If you want to commit npm packges (it's not advised to do so though), remove /node_modules from your .gitignore file.