Giter Site home page Giter Site logo

ngx-builders / netlify-builder Goto Github PK

View Code? Open in Web Editor NEW
71.0 4.0 23.0 5.82 MB

Deploy your Angular app to netlify from CLI

Home Page: https://www.npmjs.com/package/@netlify-builder/deploy

License: MIT License

TypeScript 100.00%
typescript angular8 builders angular-builders netlify netlify-deployment ngx-builder angular builder cli

netlify-builder's Introduction

npm downloads npm (scoped) Build Status All Contributors

Deploy your Angular app to Netlify directly from the Angular CLI! ๐Ÿš€

Pre-requisites

  • Angular project created via Angular CLI v8.3.0 or greater.

Steps:

  1. run ng add @netlify-builder/deploy OR ng add @netlify-builder/deploy --project={projectName} to add necessary dependencies. Once, it get installed,you will be prompted to enter (a) Site Id and (b) Netlify Token Screenshot

  2. run ng deploy assuming that you have Angular CLI installed globally

    OR

    add below script to package.json

    "deploy":"ng deploy"
    

    Screenshot

Netlify Builder demo

This repository contains an example of the Angular CLI Architect API.

Builder

You can find the Architect builder in the src directory.

Sample application

The sample application which uses the Architect builder is available under the builder-test directory.

License

MIT

Setup

  1. Move to src and run the below command
npm i
  1. Run the below command to build the package
npm run build
  1. run the below command to link the package
npm link

Contributors โœจ

Thanks goes to these wonderful people (emoji key):


Nitish Kumar Singh

๐Ÿ’ป

Shaikh-Ubaid

๐Ÿ“–

Suraj Chandgude

๐Ÿ’ป

Santosh Yadav

๐Ÿ’ป

Alan Agius

๐Ÿ’ป

Imran Momin

๐Ÿ’ป

Michael Hladky

๐Ÿ’ป

Nilesh Patel

๐Ÿ“–

Josh Morony

๐Ÿ’ป

This project follows the all-contributors specification. Contributions of any kind welcome!

netlify-builder's People

Contributors

alan-agius4 avatar allcontributors[bot] avatar biophoton avatar corysmc avatar dependabot[bot] avatar ducan-ne avatar iamsurajdc avatar jordan-hall avatar joshuamorony avatar nileshpatel17 avatar nitishk72 avatar patelvimal avatar renovate-bot avatar santoshyadavdev avatar shaikh-ubaid avatar varit05 avatar wiput1999 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

netlify-builder's Issues

Could not find module "collection.json" while executing ng add

Describe the bug
I have tried to add @netlify-builder/deploy using ng add @netlify-builder/deploy, but it gives following error

An unhandled exception occurred: Could not find module "collection.json"

This are the error logs

[error] Error: Could not find module "collection.json" from "[project_path]\\node_modules\\@netlify-builder\\deploy". at Object.resolve ([project_path]\node_modules\@angular-devkit\core\node\resolve.js:151:11) at NodeModulesEngineHost._resolvePath ([project_path]\node_modules\@angular-devkit\schematics\tools\node-module-engine-host.js:52:25) at NodeModulesEngineHost._resolveCollectionPath ([project_path]\node_modules\@angular-devkit\schematics\tools\node-module-engine-host.js:78:35) at NodeModulesEngineHost.createCollectionDescription ([project_path]\node_modules\@angular-devkit\schematics\tools\file-system-engine-host-base.js:115:27) at SchematicEngine._createCollectionDescription ([project_path]\node_modules\@angular-devkit\schematics\src\engine\engine.js:147:40) at SchematicEngine.createCollection ([project_path]\node_modules\@angular-devkit\schematics\src\engine\engine.js:140:43) at AddCommand.getCollection ([project_path]\node_modules\@angular\cli\models\schematic-command.js:128:35) at AddCommand.runSchematic ([project_path]\node_modules\@angular\cli\models\schematic-command.js:291:50) at AddCommand.executeSchematic ([project_path]\node_modules\@angular\cli\commands\add-impl.js:148:31) at AddCommand.run ([project_path]\node_modules\@angular\cli\commands\add-impl.js:45:25) at AddCommand.validateAndRun ([project_path]\node_modules\@angular\cli\models\command.js:134:39) at process._tickCallback (internal/process/next_tick.js:68:7) at Function.Module.runMain (internal/modules/cjs/loader.js:745:11) at startup (internal/bootstrap/node.js:283:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)

I have looked into the @netlify-builder/deploy code, as per code collection.json is part of main @netlify-builder folder while it is searching collection.json in deploy folder.

To Reproduce
Execute ng add @netlify-builder/deploy
Expected behavior
should install the dependencies and add configuration in angular.json

Read Netlify arguments from environment variable

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

I think netlifyToken and siteId should not commit into VCS because someone could see the token.

Describe the solution you'd like
A clear and concise description of what you want to happen.

Using environment variable instead of setting in angular.json.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Other Branches

These updates are pending. To force PRs open, click the checkbox below.

  • chore(deps): update actions/checkout action to v4
  • chore(deps): update actions/setup-node action to v4

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

github-actions
.github/workflows/nodejs.yml
  • actions/checkout v2
  • actions/setup-node v1
.github/workflows/npm-publish.yml
  • actions/checkout v2
  • actions/setup-node v2
  • actions/checkout v2
  • actions/setup-node v2
npm
src/package.json
  • @angular-devkit/architect ^0.1200.0
  • @angular-devkit/core ^12.0.0
  • @angular-devkit/schematics ^12.0.0
  • netlify ^6.1.1
  • @types/jasmine 3.7.6
  • @types/node 14.17.1
  • jasmine 3.7.0
  • jasmine-node 3.0.0
  • ts-node 10.0.0
  • typescript 4.3.2

  • Check this box to trigger a request for Renovate to run again on this repository

Won't build/deploy with dependencies. Error: "dependencies have not been built yet."

Describe the bug
When deploying a project via netlify-builder I can't deploy without first building dependencies. Adding the --with-deps flag doesn't make a difference.

To Reproduce
Steps to reproduce the behavior:

  1. Create a project that is deployed via @netlify-builder/deploy:deploy e.g. deploy target looks like this:
"deploy": {
          "builder": "@netlify-builder/deploy:deploy",
          "options": {
            "outputPath": "dist/apps/my-app/www"
          },
          "configurations": {
            "production": {
              "siteId": "your-side-id"
            }
          }
        }
  1. Create a ui library depency (do not build)
  2. try to deploy via your netlify builder
  3. See error Some of the project project-name dependencies have not been built yet. Please build these libraries before:
  4. Try to add the --with-deps flag before running e.g. nx deploy your-app
  5. Same error is thrown

Console:

$ nx deploy my-app --with-deps

> nx run my-app:deploy 
Executing netlify deploy command ...... 
๐Ÿ“ฆ Building "my-app". Configuration: "production". Build Command: build. 
Some of the project my-app's dependencies have not been built yet. Please build these libraries before:
- core

Try: nx run my-app:build --with-deps
โŒ Application build failed

โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”

>  NX   ERROR  Running target "deploy" failed

  Failed projects:
  
  - my-app

Expected behavior
There needs to be a way to build with dependencies

Current Workaround

  1. First runnpm run nx affected -- --target=build --with-deps // this will build dependencies
  2. Then run npm run nx affected -- --target=deploy

README suggestion: tell me what "ng deploy" does

Is your feature request related to a problem? Please describe.
I'm a first-time Netlify user. (And pretty new to Angular.) I deployed my repo once as a static site, then generated a new angular project inside it.
When googling "netlify angular," I find this repository. But it doesn't help me understand Netlify or Angular or what it is I should expect.

Describe the solution you'd like
When reading the README, I would like it to say what happens on "ng deploy" that doesn't on a "git push."
Does it change the configuration of my site on Netlify? does it perform a local build or one on Netlify? Is this deploy going to be overridden when I push to main?

Describe alternatives you've considered
I got here from this article which has the same problem, I don't understand what the builder does: https://www.netlify.com/blog/2019/09/17/using-the-angular-builder-for-netlify/ (I'd leave an issue there instead, if that were as easy.)

Additional context
Thanks for your work creating and maintaining this.

Custom build target before deploy to netlify

Is your feature request related to a problem? Please describe.
I plan to use netlify-builder with Next.js. The problem is when building Next.js need additional step to deploy as static. It needs to run export command to build a production bundle and generate to static site. When I use nx affected:export as I've customized I found that I can't force buildTarget to export before deploy to Netlify.

Describe the solution you'd like
In src/deploy/index.ts#L29 I think if we can add custom builderOption like buildTarget which is default to build it will give me customization to change it to export which build and export static webpage for Next.js before deploying to Netlify.

If you allow me to PR so I can work on this and PR here. Maybe it doesn't relate to Angular directly so feel free to discuss. Thank you.

deploy fails if following the tutorial - fix is to add relative paths (relative to the build script)

Describe the bug
When trying to deploy using the nx plugin, I get an error that says "deployment failed" after investigating the source, and adding some console.logs - the error said the file wasn't present.

To Reproduce
Steps to reproduce the behavior:

  1. Create nx project
  2. Follow tutorial here: https://www.netlify.com/blog/2020/04/21/deploying-nx-monorepos-to-netlify/
  3. enter the outputPath": "dist/apps/your-app-output"
  4. run in the terminal: NETLIFY_TOKEN=your_token nx deploy your-app
  5. it wil fail - without explanation

To Fix
3. enter the outputPath": "../../../dist/apps/your-app-output" - this is relative to the build script in node_modules

Expected behavior
I would expect to put the path as explained in the tutorial - relative to my project.
outputPath": "dist/apps/your-app-output"

align app structure to ngx-deploy-starter

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.
The application structure is not aligned to ngx-deploy-starter
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
NA
Additional context
Add any other context or screenshots about the feature request here.
refer https://github.com/angular-schule/ngx-deploy-starter for structure

Align options with RFC 1 of ngx-deploy-starter

I have started a discussion at ngx-deploy-starter RFC #1 about a standardised set of options. It would be great if we could find a common approach so that the expected behaviour and usability of the different builders are consistent.

Currently, there could be a majority for the following options:

  • --configuration (alias -c): A named build target, as specified in the "configurations" section of angular.json
  • --no-build: Skip build process during deployment

Right now for netlify-builder only --configuration is supported, the alias is missing as well as the --no-build option.

Additionally, https://github.com/ngx-builders/netlify-builder/blob/master/command-builder/deploy/schema.json could be fixed.

implement ng add to package

Currently, we need to configure the everything manually.

ng add will automate adding deploy config to angular.json
and install the package locally.

Support to read configuration parameter from environment variable

Is your feature request related to a problem? Please describe.

In my scenario, I have a stage and production environment and stage is for preview purpose and stage have its own build configuration.

Describe the solution you'd like

Let CI decides to build for stage or production by an environment variable.

Implement implementation to verify if site exist if not create one

Netlify API provides the Methods to create site and retrieve list of sites.

const NetlifyAPI = require('netlify')
const client = new NetlifyAPI('1234myAccessToken') -- API to be provide via config or while deployment

// Fetch sites
const sites = await client.listSites()

// Create a site. Notice body here for sending OpenAPI body
const site = await netlify.createSite({
body: {
name: my-awesome-site
// ... https://open-api.netlify.com/#/default/createSite
}
})

Create site if siteId does not exist. use existing if it exist.

Add option for baseHref

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
When building for production we may want to deploy on a context.
Describe the solution you'd like
A clear and concise description of what you want to happen.
Have an option to pass baseHref while build
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Support to read configuration from netlify-config.json (generate in ng add, and mentioned in .gitignore)

Is your feature request related to a problem? Please describe.
I have tested netlify-builder using environment variable configuration, and it is working fine.
This will work for the single application, but how it will work for multiple applications ?,
Though NETLIFY_TOKEN can be common for all sites, but site id will be different for each site. So whenever I want to deploy for particular site, I need to set NETLIFY_API_ID environment variable with Site ID of that application. which is not a proper solution.

Describe the solution you'd like

Solution 1 : I am not sure whether sharing site id is secure or not ? if sharing site id is secure then we can add site id in angular.json directly and NETLIFY_TOKEN in environment variable - For this solution, development is not required. this will work with current builder.

Solution 2: During ng add we can create separate netlify-config.json file, put netlify-builder configuration there, and add it in .gitignore. So it will not get committed in git and we can access parameters from this file (the way it is implemented in angularfire2 deploy)

Additional context
If we are reading configuration from environment variable, it should not ask for site id and netlify token id, in ng add,
For this either we can ask initially whether user want to configure it through environment variable or he want to add it now in angular.json( or in netlify-config.json if this feature is implemented.)

add build task withing deploy

Currently, we need to build and deploy the app in 2 steps.

Add build task into deploy so the user can deploy in a single step.

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

document how to use ng add with the package in Readme

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
ng-add support is added to the package, we need to add the step on how to use it with ng-add.
Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Wrong filename report when ng adding to a single-app Nx workspace

โค๏ธ for this plugin!

Describe the bug
A minor, one could say cosmetic, issue, but can be misleading to beginners.

To Reproduce
On an Nx/angular single-app wporkspace, meaning:

  • there is no angular.json file
  • there is just a single app, living at src/app
  • there is one project.json and nx.json living at the repo root

When you run this command ng add @netlify-builder/deploy
you get this message in cli
image
while the actual file that gets modified is project.json

Expected behavior
project.json is should be the cli output

Otherwise once again: โค๏ธ for this plugin!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.