Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(cli build): add build targets#765

Closed
jwx wants to merge 1 commit intoaurelia:masterfrom
jwx:build-targets-cli
Closed

feat(cli build): add build targets#765
jwx wants to merge 1 commit intoaurelia:masterfrom
jwx:build-targets-cli

Conversation

@jwx
Copy link
Member

@jwx jwx commented Oct 4, 2017

Configure build target folders in aurelia.json that builds multiple, complete distribution folders.

Changes:

  • complete build is made into target root folder based on env (default: build/dev)
  • source files in src are never touched
  • source file environment.js/ts is never copied into src
  • files index.html and favicon.ico should always be in root directory
  • build command have a new --target flag

aurelia.json:

  • build.targets changed from array to object with target names as keys
  • target object in build.targets has the following properties:
    • platform (string): Specifies platform (currently web or aspdotnet)
    • displayName (string): Friendly target name
    • root (string): Target root, relative to project root, default: 'dist/${TARGET}/${ENV}'
    • index (string): Name of target index file, default: 'index.html'
    • output (string): Target folder for bundles, relative to target root, default: 'scripts' (leave it alone)
    • indexSource (string): Name of source index file for target, default: uses target's "index" property (above)
    • resources (array): Unbundled resources copied from project root to target root, default:
      [
      'favicon.ico',
      'scripts/', // This folder isn't used by the bundles anymore, so these are any additional, non-bundled scripts
      'images/
      ',
      'styles/**'
      ],
    • environments (object): Used to override target settings for environment (dev/stage/prod), default: {}
  • if target object in build.targets is a string instead of an object, it serves as an alias for &-separated targets ("ALL": "target1 & target2")
  • build.defaultTarget added that specifies default target when no --target flag is specified
  • build.defaultEnvironment added that specifies default environment when no --env flag is specified

Replaces PR #644.
Closes #200, #442, #563, #627 and #677.
Partially closes #763 and #724.

let target;
if (Array.isArray(targets)) {
target = targets[0];
target.legacy = true;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps I'm missing something, but is this always going to return the first target if the project.build.targets is in fact an array?

Do you perhaps have an example of what the structure should look like?
My aurelia.json currently looks like this:

"build": {
    "targets": [
      {
        "id": "web",
        "displayName": "Web",
        "index": "index.html",
        "baseDir": ".",
        "output": "scripts"
      },
      {
        "id": "kiosk",
        "displayName": "Kiosk",
        "index": "kiosk.html",
        "baseDir": ".",
        "output": "kiosk_scripts"
      }
    ]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johan-v-r You're not missing something; that is the current behaviour (which is kept so that it's a non-breaking change).

Here's a (somewhat long) example:

    "targets": {
      "web": {
        "id": "web",
        "displayName": "Web",
        "index": "index.html",
        "output": "scripts",
        "root": "dist/${TARGET}/${ENV}",
        "resources": [
          "favicon.ico",
          "images/**",
          "styles/**"
        ],
        "environments": {
          "dev": {
            "root": "build/dev"
          }
        }
      },
      "aspnetcore": {
        "id": "aspnetcore",
        "displayName": "ASP.NET Core",
        "index": "index.html",
        "output": "scripts",
        "root": "wwwroot",
        "resources": [
          "favicon.ico",
          "images/**",
          "styles/**"
        ],
        "environments": {
          "prod": {
            "root": "../dotnetcore/wwwroot"
          }
        }
      },
      "cordova": {
        "id": "cordova",
        "displayName": "Cordova",
        "index": "index.html",
        "indexSource": "index.cordova.html",
        "output": "scripts",
        "root": "../cordova/www",
        "resources": [
          "favicon.ico",
          "images/**",
          "styles/**"
        ]
      },
      "EXTERNAL": "aspnetcore & cordova",
      "ALL": "web & EXTERNAL"
    }

In this example the Aurelia project also contains a dotnet core web server/project (not really a good idea, but it's just an example) that will be targeted for dev and stage builds. In addition, the Aurelia project has two "sibling projects", one Cordova and one that's, again, dotnet core (which is targeted for the prod build). The Cordova project has additional requirements for index.html, so it's a separate file in the Aurelia project (that will be renamed to index.html for the target).

Running
au build --target ALL --watch
will rebuild and update all three targets as soon as a file is changed.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay yeah thanks this is awesome, will 100% work for me. This also replaces my PR #731

Just a final note from my side, looks like root property is more like an output directory..? Can/should this name perhaps be changed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johan-v-r Well, it is the target root and the base for the other target settings. (And, depending on them, nothing might actually end up there.) Plus, I didn't want it mixed up with the current output (which is where the script bundles are put). But yeah, perhaps it should be changed (but then output also needs to be changed). Naming things is often the hardest part of this stuff...

Configure build target folders in aurelia.json that builds multiple, complete distribution folders.

Changes:
- complete build is made into target root folder based on env (default: build/dev)
- source files in src are never touched
- source file environment.js/ts is never copied into src
- files index.html and favicon.ico should always be in root directory
- build command have a new --target flag

aurelia.json:
- build.targets changed from array to object with target names as keys
- target object in build.targets has the following properties:
    + platform (string): Specifies platform (currently web or aspdotnet)
    + displayName (string): Friendly target name
    + root (string): Target root, relative to project root, default: 'dist/${TARGET}/${ENV}'
    + index (string): Name of target index file, default: 'index.html'
    + output (string): Target folder for bundles, relative to target root, default: 'scripts' (leave it alone)
    + indexSource (string): Name of source index file for target, default: uses target's "index" property (above)
    + resources (array): Unbundled resources copied from project root to target root, default:
      [
        'favicon.ico',
        'scripts/**', // This folder isn't used by the bundles anymore, so these are any additional, non-bundled scripts
        'images/**',
        'styles/**'
      ],
    + environments (object): Used to override target settings for environment (dev/stage/prod), default: {}
- build.defaultTarget added that specifies default target when no --target flag is specified
- build.defaultEnvironment added that specifies default environment when no --env flag is specified

Replaces PR aurelia#644.
Closes aurelia#200, aurelia#442, aurelia#563, aurelia#627 and aurelia#677.
Partially closes aurelia#763 and aurelia#724.
@EisenbergEffect
Copy link
Contributor

Ping @JeroenVinke to review.

@The1nternet
Copy link

I'm highly interested in this feature and I want it released! :)

Copy link
Collaborator

@JeroenVinke JeroenVinke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, nice work man! I have added a few comments here and there.

I created a typescript project on Windows and it seems to run nicely.

I think we should add documentation for this. Specifically the options in aurelia.json, some sample configurations etc. I'd like to hear your thoughts on that

}
})
.catch(e => {
logger.error(`Unable to write the bundle to ${path.posix.join(platform.output, bundleFileName)}`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a specific reason for avoiding the logger abstraction here? My idea was to log everything through the logger abstraction so that we can at some point display error messages in red easily

"aurelia-tools": "^0.2.4",
"babel-eslint": "^7.1.1",
"gulp": "^3.9.1",
"gulp": "git+https://[email protected]/gulpjs/gulp.git#4.0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need these new dependencies (gulp, typescript, babel-polyfill and babel-register)? I think they may have been added when you linked the aurelia-cli using NPM

throw e;
});
.catch(e => {
console.log(`Unable to analyze ${(dependency.name || dependency)}`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you check if the linter is OK with this (gulp lint from the project directory)?


vfs.src(pattern).pipe(mapStream(copy))
.on('error', e => {
console.log(`Error while copying all matching resources of pattern "${pattern}": ${e.message}`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

}
else {
if (!targets[targetId]) {
console.log(`No target "${targetId}" found in configuration!`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we continue at this point, or should we throw?

}

let config = {
platform: target.id, // Not really necessary for building yet, but is good form (and will be useful)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should document these options in the docs

let dts = gulp.src(project.transpiler.dtsSource);

let src = gulp.src(project.transpiler.source)
let src = gulp.src(`aurelia_project/environments/${env}.ts`)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While the typescript/babel compiler might be OK with this, isn't the editor going to complain that the environment.js/ts file doesn't exist?

});
};

exports.mkdirSync = function (path) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this create a folder structure if necessary? Nice

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, have you tested this on linux as well? If not I can do that

let arr = path.split(/[\\\/]/);
let folder = arr.shift();
if (folder.indexOf(':') !== -1) {
folder += '/';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add some comments here?

@Jenselme
Copy link
Contributor

Any progress on this? I'd like to see this feature.

@avrahamcool
Copy link
Contributor

@JeroenVinke
any news on this?
if the whole PR is still not ready to merge, can you take the part that use the environment file without copying it to the src folder?
it feels like there a new version of the cli in the horizon, it can help a lot to have it there.

@JeroenVinke
Copy link
Collaborator

@Jenselme @avrahamcool the comments (and merge conflicts) have to be addressed until it can be merged. Since this is quite a big change, we need to thoroughly test it as well.

@avrahamcool if someone can create a separate PR for that I can get it into the next release. I'm going to try and do releases more often from now on

@jwx
Copy link
Member Author

jwx commented Jul 27, 2018

I'll try and take a look at comments and merge conflicts this weekend.

@3cp
Copy link
Member

3cp commented Apr 12, 2021

Closed the stale PR. Please reopen when it's needed.

@3cp 3cp closed this Apr 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bundle does not use platform baseDir wrong bundle path when setting relative tagret in config

8 participants

Comments