UNPKG

5.52 kBMarkdownView Raw
1# Asset-Mate
2Asset-Mate auto-generates a gulpfile based on a manifest, which enables you to easily compile, rewrite, copy, or deploy Javascript, ES6, SCSS, CSS and images
3
4###How it works
51) You fill in a manifest of your source-tree assets, and desired destinations
6
72) It auto-generates a gulp file
8
93) Call 'watch', or 'build' with gulp to have it make your output assets
10
114) Call 'deploy' with gulp to have it deployed to an AWS S3 bucket
12
13###What it can do
14- Compile ES6 files
15- Compile SASS files
16- Minify ES6 or Javascript files
17- Autoprefix CSS files (automatic cross-browser support)
18- Do find and replace (rewrites) on all text files
19- Create multiple output sizes of images
20- Simple copying of files
21- Deploy to an S3 bucket
22- Keeps an internal list of files (so that you don't copy everything every time)
23
24###Requirements
25- Node and NPM
26- Ffmpeg (If you want to resize images)
27
28###Installation
291) npm install -g asset-mate
30
312) cd to the root of your project directory
32
333) asset-mate new
34
35###Commands
36- asset-mate new
37- asset-mate autogenerate
38- asset-mate clearcache
39- gulp (build | deploy | watch)
40- gulp (build | deploy | watch) [--src 0] [ --dest 0]
41- gulp (build | deploy | watch) [--src src_name] [ --dest dest_name]
42
43###Usage
44When you call 'asset-mate new' it installs gulp and the dependencies you need to run the gulp file, and adds a 'gulp-manifest.json' file to the root of your project.
45
46'gulp-manifest.json' will start with an example structure that you can fill in with the details of your own project. You can have multiple sources and multiple destinations, and it understands arrayed and glob format descriptions of your files.
47Once you've finished describing your manifest, call 'asset-mate autogenerate'. This will build your gulp file for you. Then use the commands 'gulp build' or 'gulp watch' to have it produce your assets.
48
49If you specify 's3Bucket' and 'awsCredentialsProfile' in a destination in your manifest, calling 'gulp deploy' will use that information to automatically upload your files to the given S3 bucket. You can also specify an 's3Prefix' if you would like the files in that destination prefixed in the bucket.
50
51###Example
52A common example case is when you have a source directory that you would like compiled into three formats:
53
54- A local 'dev' folder in which sources are not minified
55- A local 'dist' folder in which sources are minified
56- A 'deploy' folder in which sources are both minified and any urls in those files point to S3 or CDN addresses
57
58Your gulp-manifest.json file for this use case might look as follows:
59
60```
61[
62 {
63 "name" : "my-app",
64 "src" : {
65 "directory" : "src",
66 "es6" : "js/*.js",
67 "js" : "other_file/js/*.js",
68 "scss" : "scss/*.scss",
69 "css" : "css/*",
70 "images" : [
71 {
72 "glob" : "images/**",
73 "sizes" : {
74 "big" : "100%",
75 "med" : 0.5
76 }
77 }
78 ],
79 "copy" : "**",
80 "copyExclude" : ["folder_to_exclude1/*", "folder_to_exclude2/*"]
81 },
82 "dest" : [
83 {
84 "name" : "dev",
85 "directory" : "dist_dev",
86 "minify" : false,
87 "autoprefix" : true,
88 "rewrites" : { "ASSET_URL" : "dist_dev" },
89 },
90 {
91 "name" : "dist",
92 "directory" : "dist",
93 "minify" : true,
94 "autoprefix" : true,
95 "rewrites" : { "ASSET_URL" : "" },
96 },
97 {
98 "name" : "deploy",
99 "directory" : "deploy",
100 "minify" : true,
101 "autoprefix" : true,
102 "rewrites" : { "ASSET_URL" : "aws-cdn.com" },
103 "s3Bucket" : "my-bucket",
104 "s3Prefix" : "app-asset",
105 "awsCredentialsProfile" : "default"
106 }
107 ]
108 }
109]
110```
111
112You can omit any of the keys that are not relevant to your project and it should still build ok.
113
114(Note: I've also used this example to demonstrate that the images list will understand you specifying your sizes as both percentages and fractions)
115
116Since I've specified the copy glob as "**", when gulp runs it will copy and rewrite all files in the 'src' directory that don't match with those specified in the other globs, it will parse everything in the es6 glob using Babel and Browserify, it will resize my images and appended them with their size name (e.g. image_med.png), and it will compile and autoprefix any css.
117
118The results will vary as per the rules specified in each of the destinations
119
120When I call 'gulp deploy' it will ignore the first two destinations (as they don't list any s3 information) any only deploy the files in the third.
121
122If I only want to watch or build to a single destination, the second for example, I can call 'gulp build --src my-app --dest dist' or 'gulp build --src 0 --dest 1'
123
124Also, any subsequent times I run the build command it 'should' check the source files against their destinations and an internal record and only copy those with changes (this might be a bit flakey though)
125
126Oh and! Subsequent deploys should also upload only the files that have changed
127