Giter Site home page Giter Site logo

grunt-dojo2's Introduction

This repository has been deprecated

grunt-dojo2

Build Status codecov.io npm version

A package of Grunt tasks and configuration to use with Dojo 2 Packages.

Installation

This package contains configuration and tasks for Grunt to help orchestrate development of Dojo 2 Packages. It is meant to be a development dependency of a Dojo 2 package.

To install:

$ npm install grunt-dojo2 --save-dev

The package Gruntfile.js should look like this:

module.exports = function (grunt) {
	require('grunt-dojo2').initConfig(grunt);
};

Code Style

This repository uses prettier for code styling rules and formatting. A pre-commit hook is installed automatically and configured to run prettier against all staged files as per the configuration in the projects package.json.

An additional npm script to run prettier (with write set to true) against all src and test project files is available by running:

npm run prettier

Dependencies

There are several peer dependencies which you should have installed in the containing project:

Package SemVer
codecov.io >=0.1.6
dts-generator >=1.7.0
grunt-contrib-clean >=1.0.0
grunt-contrib-copy >=1.0.0
grunt-contrib-watch >=1.0.0
grunt-text-replace >=0.4.0
grunt-typings >=0.1.4
grunt-ts >=5.0.0
grunt-tslint >=3.0.0
remap-istanbul >=0.6.3

Configuration

If you need to customise the Grunt configuration, you can do so by passing a second argument to the initConfig() function. For example to configure Uglify2, you would do something like this:

module.exports = function (grunt) {
	grunt.loadNpmTasks('grunt-contrib-uglify');

	require('grunt-dojo2').initConfig(grunt, {
		uglify: {
			dist: {
				options: {
					sourceMap: true,
					sourceMapName: 'dist/umd/_debug/module.min.js.map',
					sourceMapIncludeSources: true,
					sourceMapIn: 'dist/umd/_debug/module.js.map',
					compress: {
						dead_code: true,
						unsafe: true
					}
				},
				files: {
					'dist/umd/module.min.js': 'dist/umd/module.js'
				}
			}
		}
	});

	grunt.registerTask('dist', grunt.config.get('distTasks').concat('uglify:dist'));
};

Tasks

grunt tslint

The grunt tslint task, runs tslint with the following configuration.

options: {
	configuration: grunt.file.readJSON('tslint.json')
},
src: {
	src: [
		'<%= all %>',
		'!typings/**/*.ts',
		'!tests/typings/**/*.ts',
		'!node_modules/**/*.ts'
	]
}

grunt dojo-ts

The grunt dojo-ts task runs a project through the TypeScript compiler using the project's tsconfig.json. It is preconfigured with two targets, dev and dist.

dev

The dev target transpiles a project for development. src/ and test/ files are built and the output is put in the _build directory.

dist

The dist target prepares a project for distribution and applies the following overrides to the tsconfig:

{
	compilerOptions: {
		outDir: distDirectory,
		declaration: true
	},
	exclude: ['tests/**/*.ts']
}

Where the distDirectory is defaulted to dist/umd.

If you have other root level directories besides src and tests, you might want to exclude them from the dist build. Including them can cause unwanted output in your dist/umd directory. For example, if you wanted to exclude an examples directory, you would add:

ts: {
	dist: {
		exclude: ['tests/**/*.ts', 'examples/**/*.ts'],
	}
}
Custom Targets

It is possible to create custom targets for the ts by adding an entry to the grunt config, such as:

"ts": {
	"custom": {
		"compilerOptions": {
			"target": "es6",
			"module": "commonjs"
		}
	}
}

The custom ts config can be run using grunt grunt-ts:custom.

grunt intern

The intern task provides multiple preconfigured targets

options: {
	runType: 'runner',
	config: '<%= devDirectory %>/tests/intern',
	reporters: [ 'Runner' ]
},
browserstack: {},
	saucelabs: {
		options: {
			config: '<%= devDirectory %>/tests/intern-saucelabs'
		}
	},
remote: {},
local: {
	options: {
		config: '<%= devDirectory %>/tests/intern-local',
	}
},
node: {
	options: {
		runType: 'client'
	}
},
proxy: {
	options: {
		proxyOnly: true
	}
}

grunt doc

The doc task is used to automatically build and publish API documentation to the project's GitHub pages. Please note that if you want to generate documentation locally by manually running this command use the grunt typedoc command instead.

Environment Variables

Running grunt typedoc (part of grunt doc) will only generate APIs using typedoc. In order to automatically commit or publish API documentation the DEPLOY_DOCS environment variable must be set to either publish or commit. Environment variables are used so they may be turned on/off using travis-ci settings and to support forks that may want to use the travis build, but do not want to automatically publish documentation.

Prerequisites

To support continuous delivery of API documents to your project's GitHub pages Travis-ci needs access to your GitHub repository. This is best achieved by supplying an encrypted deployment key that can be used via SSH (there are other methods that are less secure that we will not go into). To use this method you will need to:

  1. Create a ssh key; e.g. ssh-keygen -t rsa -C "[email protected]"
  2. encrypt the private key using travis cli; e.g. travis encrypt-file deploy_key (you will need to be logged in and be the owner of the GitHub repository to do this)
  3. add the public key under your project's GitHub settings
  4. add grunt doc --publish-api as part of your install steps

grunt link

The link task is designed to ease the local development and testing of changes that span multiple packages. Traditionally npm link can be used but this assumes that the project structure is the same as the distribution, which for dojo2 projects is not the case.

This command emulates the behaviour of npm link but with some additional steps to ensure that the linked structure matches that of the distributed package.

Once grunt link has been run within a dojo2 package, npm link can be used as normal to created the linked package dependency.

Example

npm link dojo-widgets

grunt release

The release task automates all the steps involved in building, tagging and publishing a dojo2 package.

grunt release --pre-release-tag=alpha

note:

  1. Task runs the dist pipelines as a prerequisite.
  2. Requires being logged into NPM unless using the dry-run options

#####Options

The pre-release-tag is required, the other options are all optional.

  • pre-release-tag- determines the pre-release tag used for the published version (usually alpha, beta or rc)
  • dry-run - performs the release in dry run mode, no commits, tags or publishing occur. The generated package is built into the dist directory.
  • initial - indicates that it is an initial release of an asset and therefore assumes the version rather than using npm veiw.
  • skip-checks - skips checks against the registered maintainers, only available with dry-run
  • push-back - automatically pushes back to github (tags and commits)
  • tag - the npm tag to publish as (defaults to next)

Pipelines

dev

The running grunt dev will execute the dev pipeline which as follows:

  • clean:typings
  • typings
  • tslint
  • clean:dev
  • ts:dev
  • copy:staticTestFiles

dist

The running grunt dist will execute the dist pipeline which as follows:

  • clean:typings
  • typings
  • tslint
  • clean:dist
  • ts:dist

doc

Running grunt doc will execute the doc pipeline, which comes from the docTasks configuration:

  • clean:typings
  • typings:dev
  • typedoc
  • clean:typedoc
  • clean:ghpages

test

The running grunt test will execute the test pipeline which as follows:

  • clean:coverage
  • dev
  • intern:node
  • remapIstanbul:coverage
  • clean:coverage

Default (grunt)

Running grunt will execute the default pipeline which as follows:

  • clean
  • dev

grunt-dojo2's People

Contributors

agubler avatar bitpshr avatar bryanforbes avatar devpaul avatar dylans avatar edhager avatar jason0x43 avatar kitsonk avatar lzhoucs avatar maier49 avatar matt-gadd avatar msssk avatar novemberborn avatar rishson avatar rorticus avatar smhigley avatar tomdye avatar umaar avatar vansimke avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

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

grunt-dojo2's Issues

Release Task: Add flag to skip the recommended package.json changes

Dojo Loader does not require all the changes (specifically setting main to main.js and typings to undefined) to the package.json that the release task performs automatically.

Perhaps can optionally add a flag to the task that indicates these updates require skipping or potentially add an attribute to the package.json itself that indicates that the changes are not required.

Third option would be to just remove these updates from the release entirely.

Add support to publish an uber package

An uber package is essentially the same as the structure of the git repo, with the added dist folder with the generated outputs for umd and esm.

We'd like to publish the uber packages under the @dojo scope. For example:
dojo-has (umd) ---> @dojo/has (uber).

The work to add this to the release task is trivial, but one thing we must deal with is switching the dojo dependencies in the package.json (which are the umd ones) to use the uber equivalents, so that in effect, when you pull an uber package down from npm you will get any of the dependencies of it in uber form also.

Copy d.ts files from src/ on `dist` task

Unfortunately, the current TS compiler does not include copy any existing d.ts files when generating d.ts files for .ts modules. As such, $ grunt dist likewise does not include any existing d.ts files, which has caused problems elsewhere (e.g., dojo/core#209). It would be helpful if existing src/**/*.d.ts were copied into the dist/umd directory when running $ grunt dist so that consuming packages won't run into compiler errors about dependencies referencing modules that do not exist.

Create Unit Tests

We need to create unit tests for the following:

  • tasks/rename
  • tasks/rewriteSourceMaps
  • tasks/updateTsconfig
  • tasks/uploadCoverage

Support TS2.0 paths compiler options

There is a requirement to support the new TS2.0 paths options in order to use "UMD" typings (per module typings) and map the complier discover the types.

This is not available as a command line parameter therefore we need to convert to use temporary tsconfig.json files for each "target" (dev, dist etc) with the default being used for dev.

Add support to publish an ESM package

This would actually be easier than #36, as we'd just ship esm in the same flat structure as our umd ones. This means no folder structure changes.

We'd have to pick another name for the packages in npm (possibly dojo-has-es, or dojo-has-esm), but the main question is - given the state of esm module consumption at the moment i'm not sure how valuable publishing the esm target is.

Source Maps, Debugging and Names

It is great that in our distributions our source maps inline the source, but the one challenge is that the name of the original file makes it a bit confusing when debugging.

For example, here is a partial stack trace:

TypeError: Cannot read property 'get' of undefined
  at factory.on  <src/mixins/createEvented.ts:167:44>
  at initialize  <_build/src/mixins/createRenderMixin.js:291:35>
  at <src/compose.ts:179:42>
  at Array.forEach  <native>
  at Object.factory  <src/compose.ts:179:25>

Where createEvented is in node_modules/dojo-compose/mixins/createEvented.js and compose is in node_modules/dojo-compose/compose.js. When you have multiple packages brought together, all the stack traces make it look like all the original code is all part of one big package in src when actually it can be various packages. I think this will also make future debugging difficult because it will be "oh, what package is that from?" if the names of the module aren't obvious, let alone people using 3rd party packages.

It would be good to inject the package name into the name in the source map on a distribution build, so it at least did something like dojo-compose/src/mixins/createEvented.ts.

Log in to npm when using the release task

The task currently checks whether the user is logged in, and that the user has permissions to publish the package. It might be worth adding the capability to pass credentials to the task and it logging in automatically (as well as logging out after the release is completed).

Missing 'repl' and 'run' task

After moving to TS2.0 the filesGlob attribute needs to be changed to include and the files are no longer required.

Ability to express dev links for CI

One of the challenges we have is using CI when on an upstream dev branch. It would be great if we had some sort of solution to indicate alternative branches of code to substitute in, build and then link into the main package. It would also be great if this was somehow was configurable externally to the code in the repo so it would accidentally leak into master when merging.

I know it is a bit of a pipe dream, but when dreaming, dream big, right?

SemVer support for the release task

The release tool is already semi intelligent when it comes to pre release tags, it will find existing tag versions from npm and bump to the next available one, and then revert back to whatever the SemVer was.

We should think about what releasing and bumping a patch, minor or major might look like and add that to the task.

Current UMD wrapper leaks

UMD wrapper used for AMD loaders uses a global level var which causes last theme file loaded to override all others. Needs replacing.

grunt link should only include production dependencies

At the moment we are symlinking to the packages node_modules, which includes dev dependencies. This can have a habit of causing some type resolution problems due to the dev dependencies.

From now on we should just install the production dependencies in dist/umd rather than symlinking

Update engines for grunt-dojo2

Enhancement

We are not running automated testing against node 4 while engines in package.json supports node >= 4.0.0.

I tried running tests under node 4 but ran into a problem with remap-istanbul, which requires node >= 6. We should consider either moving our engine support from grunt-dojo2 to node 6 or find a way to test node 4 by backporting remap-istanbul to node 4 or skip using remap-istanbul when using node 4. Otherwise, we don't have an automated way notifying us when builds fail on node 4.

Error


/Users/pshannon/src/dojo2/grunt-dojo2/node_modules/remap-istanbul/bin/remap-istanbul.js:19
		let buffer = '';
		^^^

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:140:18)
    at node.js:1043:3
cat: stdout: Broken pipe
npm ERR! Test failed.  See above for more details.

Process finished with exit code 1

Release command fails

The release command has started to fail since #88 was accepted.

It looks like it might have been affected by renaming the internal copy task.

Release Task: Ignore tests directory on publish

Enhancing the release task to ignore the tests directory on publish will allow us to normalise our package build to a single directory with a single uniform set of compile options (configured in each tsconfig.json).

Replace lodash with dojo-core

The usage of lodash in grunt-dojo2 can be easily replaced with dojo-core.

The usage of deepClone can be replaced with dojo-core/lang#duplicate and merge can be replaced with dojo-core/lang#assign or dojo-core/lang#deepAssign.

Integrate Reporter.ts

@iyegoroff commented on Sat Aug 13 2016

Hi, I see that in tests you use similar console reporters across your projects. Is it accessible as a separate npm-module or something like that?


@kitsonk commented on Sun Aug 14 2016

Actually, we should move it to grunt-dojo2, which contains all our tool chain items, right now it is just in the dojo2-package-template.


@iyegoroff commented on Sun Aug 14 2016

Ok, thanks for reply.


@dylans commented on Thu Oct 20 2016

We never actually moved this reporter.

Allow config to be overridden for ts compile grunt tasks

Currently the grunt-ts targets defined (dev, dist and esm) used to compile typescript are preset and consumers are unable to override certain config attributes such as declaration.

Allow consumers to override the presets for certain attributes.

When publishing a new package to npm, the release task fails

Currently, when creating a new package and trying to publish to npm, the release task fails. This is due to the npm user check - because it's never been published there are no maintainers. We should add a flag that skips the user check in this situation.

Change main/fork from bryanforbes to dojo

Currently this repo is a fork of bryanforbes' original work, though we've moved so far past the original that we should switch this around so that dojo/grunt-dojo2 is the primary repo.

Documentation

We should have documentation covering the standard tasks (i.e. dev, test, watch, dist, and release). I'd like to know what they each handle and about their standard task flow. For instance, what standard structure does grunt-dojo2 expect, what release options are available to me, can I do a dry-run of a release (because release and dist look like separate flows), and how can I add to devTasks or distTasks?

`grunt dist` fails

Bug

Running grunt dist throws an exception error TS5011: File specification cannot contain multiple recursive directory wildcards ('**'): 'src/**/example/**/*.ts'.

Due to changes in #101

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.