Managing and moving files between projects at build time - jeffsim/typescriptGulpSample GitHub Wiki
Projects are inherently self-contained; they define the files within them as well as metadata about the project. However, there are two instances in which Projects reach outside their path to acquire or place files:
Output code to /bld and /dist
Typically, 'application' Projects place compiled code alongside the source code to help them be more standalone. 'Library' Projects, however, are not normally intended to be standalone; they're intended to be included in applications. As such, library Projects typically place their final distributable files into the /dist folder.
The folder for "/bld" and "/dist" can be changed in gulpBuild/buildSettings.js, 'bldPath and distPath'
Precopying files
ProjectGroups support copying previously built files into Projects. This is useful for something like editor.d.ts, which all plugins need to use. It needs to be copied after it gets built in an earlier part of the build process.
Note that, while we could just include editor.d.ts using the 'commonFiles' field described in a moment, it wouldn't get copied into the plugins' folders, and you therefore wouldn't have ambient typings when editing the plugins.
There are two ways to copy files, both via fields specified in a ProjectGroup:
- filesToPrecopyToAllProjects - Optional list of files that should be precopied to all projects within the ProjectGroup. Example usage, from the plugins ProjectGroup:
filesToPrecopyToAllProjects: [{ src: "dist/typings/editor.d.ts", dest: "typings" }] - filesToPrecopyOnce - Optional list of files that should be precopied once before projects are compiled. Example usage, from the tests ProjectGroup:
filesToPrecopyOnce: [{ src: "dist/typings/" + bundle.typingFilename, dest: "tests/typings" }]
Referencing common files
In addition to copying files into all Projects, you can also inject references to them in the ProjectGroup using the ProjectGroup's optional 'commonFiles' field. What this specifically does is: adds the file to the Project's list of files to compile, but doesn't actually copy the file into the Project's folder. This is useful when all Projects in a ProjectGroup reference the same file, and that file doesn't need to be present in the Projects' folders.
Here's an example from the tests ProjectGroup,
commonFiles: ["tests/typings/*.d.ts"],
Defining dependencies between projects
If a Project is dependent on another project (e.g. an App project that uses a Lib project), then you need to tell the build environment to copy (via filesToPrecopy) or reference (va commonFiles) the lib's .js files, and likely copy the lib's d.ts file into the app's folder in order to get ambient typings working.
Instead of the precopy above, you can just specify the dependency in the Project itself, and the build environment takes care of copying the lib's files over. The 'testApp2' sample in this project demonstrates that:
dependsOn: [buildConfig.projectGroups.plugins.projects.threeJS],