From d5bf709a1e8e4214078cd46c10487ca13c2176fb Mon Sep 17 00:00:00 2001 From: keelii Date: Wed, 17 Feb 2016 23:25:49 +0800 Subject: [PATCH] add deploy. --- .www/components/main/main.js | 2 +- .www/components/module/module.html | 2 +- .www/views/index.html | 10 +- .www/views/layout/layout.html | 4 +- .www/views/maco/default.html | 1 + .www/views/test.html | 4 +- .../main/handlebarsStr.css.handlebars | 111 ------------------ app/components/main/i/test.html | 1 - app/components/main/main.js | 2 +- app/components/module/module.html | 2 +- app/views/index.html | 2 +- app/views/layout/layout.html | 4 +- app/views/maco/default.html | 1 + bin/index.js | 10 +- cli/build.js | 50 +++++--- cli/deploy.js | 22 +++- cli/start.js | 23 ++++ default.js | 12 ++ package.json | 3 +- 19 files changed, 109 insertions(+), 157 deletions(-) delete mode 100644 app/components/main/handlebarsStr.css.handlebars delete mode 100644 app/components/main/i/test.html diff --git a/.www/components/main/main.js b/.www/components/main/main.js index 5ecf659..2947711 100644 --- a/.www/components/main/main.js +++ b/.www/components/main/main.js @@ -2,7 +2,7 @@ var body = document.getElementsByTagName('body')[0]; body.className = 'wow'; - + body.setAttribute('data-type', 'wow'); // eslint will report error // console.log("Hello World..."); })(); diff --git a/.www/components/module/module.html b/.www/components/module/module.html index 76cdc41..df1bb5e 100644 --- a/.www/components/module/module.html +++ b/.www/components/module/module.html @@ -1,4 +1,4 @@ -
+

diff --git a/.www/views/index.html b/.www/views/index.html index 95e2c85..d69d631 100644 --- a/.www/views/index.html +++ b/.www/views/index.html @@ -2,19 +2,18 @@ - Wow is awsome. + wOw is awsome... -

Wow...

- + @

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab accusamus amet atque cum excepturi fuga inventore ipsa iste laborum nam, officiis possimus quam quas rem tempore, vitae voluptatem. Illo, repellat.

@@ -25,7 +24,7 @@

CSS Sprite will auto generate:

-
+

mod1

@@ -52,7 +51,7 @@

img lists:

-
+

mod-default

@@ -87,7 +86,6 @@

img lists:

- diff --git a/.www/views/layout/layout.html b/.www/views/layout/layout.html index 9a582ea..9456df9 100644 --- a/.www/views/layout/layout.html +++ b/.www/views/layout/layout.html @@ -2,15 +2,13 @@ - Wow is awsome. + wOw is awsome... - - diff --git a/.www/views/maco/default.html b/.www/views/maco/default.html index 9e5f5f8..12a6f48 100644 --- a/.www/views/maco/default.html +++ b/.www/views/maco/default.html @@ -5,3 +5,4 @@ + diff --git a/.www/views/test.html b/.www/views/test.html index f1a600b..ca6410b 100644 --- a/.www/views/test.html +++ b/.www/views/test.html @@ -2,17 +2,15 @@ - Wow is awsome. + wOw is awsome... - - diff --git a/app/components/main/handlebarsStr.css.handlebars b/app/components/main/handlebarsStr.css.handlebars deleted file mode 100644 index 6cb0b17..0000000 --- a/app/components/main/handlebarsStr.css.handlebars +++ /dev/null @@ -1,111 +0,0 @@ -{ - // Default options - 'functions': true, - 'variableNameTransforms': ['dasherize'] -} - -{{#block "sprites-comment"}} -/* -SCSS variables are information about icon's compiled state, stored under its original file name - -.icon-home { - width: $icon-home-width; -} - -The large array-like variables contain all information about a single icon -$icon-home: x y offset_x offset_y width height total_width total_height image_path; - -At the bottom of this section, we provide information about the spritesheet itself -$spritesheet: width height image $spritesheet-sprites; -*/ -{{/block}} -{{#block "sprites"}} -{{#each sprites}} -${{strings.name_name}}: '{{name}}'; -${{strings.name_x}}: {{px.x}}; -${{strings.name_y}}: {{px.y}}; -${{strings.name_offset_x}}: {{px.offset_x}}; -${{strings.name_offset_y}}: {{px.offset_y}}; -${{strings.name_width}}: {{px.width}}; -${{strings.name_height}}: {{px.height}}; -${{strings.name_total_width}}: {{px.total_width}}; -${{strings.name_total_height}}: {{px.total_height}}; -${{strings.name_image}}: '{{{escaped_image}}}'; -${{strings.name}}: ({{px.x}}, {{px.y}}, {{px.offset_x}}, {{px.offset_y}}, {{px.width}}, {{px.height}}, {{px.total_width}}, {{px.total_height}}, '{{{escaped_image}}}', '{{name}}', ); -{{/each}} -{{/block}} -{{#block "spritesheet"}} -${{spritesheet_info.strings.name_width}}: {{spritesheet.px.width}}; -${{spritesheet_info.strings.name_height}}: {{spritesheet.px.height}}; -${{spritesheet_info.strings.name_image}}: '{{{spritesheet.escaped_image}}}'; -${{spritesheet_info.strings.name_sprites}}: ({{#each sprites}}${{strings.name}}, {{/each}}); -${{spritesheet_info.strings.name}}: ({{spritesheet.px.width}}, {{spritesheet.px.height}}, '{{{spritesheet.escaped_image}}}', ${{spritesheet_info.strings.name_sprites}}, ); -{{/block}} - -{{#block "sprite-functions-comment"}} -{{#if options.functions}} -/* -The provided mixins are intended to be used with the array-like variables - -.icon-home { - @include sprite-width($icon-home); -} - -.icon-email { - @include sprite($icon-email); -} -*/ -{{/if}} -{{/block}} -{{#block "sprite-functions"}} -{{#if options.functions}} -@mixin sprite-width($sprite) { - width: nth($sprite, 5); -} - -@mixin sprite-height($sprite) { - height: nth($sprite, 6); -} - -@mixin sprite-position($sprite) { - $sprite-offset-x: nth($sprite, 3); - $sprite-offset-y: nth($sprite, 4); - background-position: $sprite-offset-x $sprite-offset-y; -} - -@mixin sprite-image($sprite) { - $sprite-image: nth($sprite, 9); - background-image: url(#{$sprite-image}); -} - -@mixin sprite($sprite) { - @include sprite-image($sprite); - @include sprite-position($sprite); - @include sprite-width($sprite); - @include sprite-height($sprite); -} -{{/if}} -{{/block}} - -{{#block "spritesheet-functions-comment"}} -{{#if options.functions}} -/* -The `sprites` mixin generates identical output to the CSS template - but can be overridden inside of SCSS - -@include sprites($spritesheet-sprites); -*/ -{{/if}} -{{/block}} -{{#block "spritesheet-functions"}} -{{#if options.functions}} -@mixin sprites($sprites) { - @each $sprite in $sprites { - $sprite-name: nth($sprite, 10); - .#{$sprite-name} { - @include sprite($sprite); - } - } -} -{{/if}} -{{/block}} diff --git a/app/components/main/i/test.html b/app/components/main/i/test.html deleted file mode 100644 index 300f902..0000000 --- a/app/components/main/i/test.html +++ /dev/null @@ -1 +0,0 @@ - diff --git a/app/components/main/main.js b/app/components/main/main.js index 5ecf659..2947711 100644 --- a/app/components/main/main.js +++ b/app/components/main/main.js @@ -2,7 +2,7 @@ var body = document.getElementsByTagName('body')[0]; body.className = 'wow'; - + body.setAttribute('data-type', 'wow'); // eslint will report error // console.log("Hello World..."); })(); diff --git a/app/components/module/module.html b/app/components/module/module.html index 945ad8b..76c8676 100644 --- a/app/components/module/module.html +++ b/app/components/module/module.html @@ -1,5 +1,5 @@ {% import 'views/maco/default.html' as wow %} -
+

{{ id }}

diff --git a/app/views/index.html b/app/views/index.html index d47ac1c..fe029dd 100644 --- a/app/views/index.html +++ b/app/views/index.html @@ -12,7 +12,7 @@ {% block body %}

Wow...

- + {{ name }} @ {{ version }}

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab accusamus amet atque cum excepturi fuga inventore ipsa iste laborum nam, officiis possimus quam quas rem tempore, vitae voluptatem. Illo, repellat.

diff --git a/app/views/layout/layout.html b/app/views/layout/layout.html index ebe26df..67d782c 100644 --- a/app/views/layout/layout.html +++ b/app/views/layout/layout.html @@ -3,18 +3,16 @@ - Wow is awsome. + wOw is awsome... {% block style %} {{ Tag('link', '/components/main/main.css') }} {% endblock %} - {% block body %} {% endblock %} - {% block script %} {{ Tag('script', '/components/main/main.js') }} {% endblock %} diff --git a/app/views/maco/default.html b/app/views/maco/default.html index 85518bc..af1fb44 100644 --- a/app/views/maco/default.html +++ b/app/views/maco/default.html @@ -8,6 +8,7 @@ {%- endmacro %} + {# ----- 代码片段 ----- #} {% macro imgList(id='plist', class='plist', source="data-lazy-img", length=5, width=100, height=100, text_size=30, text='Wow') -%} diff --git a/bin/index.js b/bin/index.js index f64f395..2f6cf9a 100644 --- a/bin/index.js +++ b/bin/index.js @@ -13,12 +13,12 @@ if (cmd) { const settings = require(process.cwd() + '/default')(argv); if (cmdMap[cmd]) { - try { + // try { require(`../cli/${cmdMap[cmd]}`)(settings); - } catch (error) { - console.log('Module [%s] loaded error.', cmdMap[cmd]); - console.dir(error); - } + // } catch (error) { + // console.log('Module [%s] loaded error.', cmdMap[cmd]); + // console.error(error); + // } } else { console.log('Command [%s] not found.', cmd); } diff --git a/cli/build.js b/cli/build.js index 001177c..c19692e 100644 --- a/cli/build.js +++ b/cli/build.js @@ -42,7 +42,7 @@ function getSources(config, input) { return { scripts, styles, templates, images }; } -function uglify(config, input) { +function uglify(config, input, callback) { let scripts = input || config.scripts; let stream = vfs.src(scripts, { base: config._SOURCE_ROOT}); @@ -52,8 +52,9 @@ function uglify(config, input) { } stream.pipe(vfs.dest(config._DEST_ROOT)); + stream.on('end', callback); } -function sass(config, input) { +function sass(config, input, callback) { let styles = input || config.styles; let stream = vfs.src(styles, { base: config._SOURCE_ROOT}); @@ -68,10 +69,11 @@ function sass(config, input) { } stream.pipe(vfs.dest(config._DEST_ROOT)); + stream.on('end', callback); } -function nunjucks(config, input) { - let styles = input || config.templates; - let stream = vfs.src(styles, +function nunjucks(config, input, callback) { + let templates = input || config.templates; + let stream = vfs.src(templates, { base: config._SOURCE_ROOT}); // if (config._isDev) { @@ -80,53 +82,65 @@ function nunjucks(config, input) { // } stream.pipe(vfs.dest(config._DEST_ROOT)); + stream.on('end', callback); } -function copy(config, input) { +function copy(config, input, callback) { let images = input || config.images; let stream = vfs.src(images, { base: config._SOURCE_ROOT}); stream.pipe(vfs.dest(config._DEST_ROOT)); + stream.on('end', callback); } -function build(config, input) { +function build(config, input, callback) { // npm run build // npm run build app/path/to/dir // npm run build app/path/**/*.js if (!input || isGlob(input) || utils.isDir(input)) { let s = getSources(config, input); + let complate = 0; if (s.scripts.length) { - uglify(config, s.scripts); + uglify(config, s.scripts, function() { + console.log('uglify'); + }); } if (s.styles.length) { - sass(config, s.styles); + sass(config, s.styles, function() { + console.log('sass'); + }); } if (s.templates.length) { - nunjucks(config, s.templates); + nunjucks(config, s.templates, function() { + console.log('nunjucks'); + }); } if (s.images.length) { - copy(config, s.images); + copy(config, s.images, function() { + console.log('copy'); + }); } } else if (utils.isFile(input)) { // npm run build app/path/to/file.js if (utils.isJS(input)) { - uglify(config, input); + uglify(config, input, callback); } if (utils.isSass(input)) { - sass(config, input); + sass(config, input, callback); } if (utils.isTemplate(input)) { - nunjucks(config, input); + nunjucks(config, input, callback); } if (utils.isImage(input)) { - copy(config, input); + copy(config, input, callback); } } } -module.exports = function (config) { - const input = config._arg._[1]; +module.exports = function (config, input, callback) { + input = input || config._arg._[1]; + callback = callback || function() {}; // npm run build:s => build --sprite if (config._arg.sprite) { @@ -134,6 +148,6 @@ module.exports = function (config) { build(config, input); }); } else { - build(config, input); + build(config, input, callback); } }; \ No newline at end of file diff --git a/cli/deploy.js b/cli/deploy.js index 9983806..689123b 100644 --- a/cli/deploy.js +++ b/cli/deploy.js @@ -1,3 +1,23 @@ +'use strict'; +const vfs = require('vinyl-fs'); +const ftp = require('vinyl-ftp'); +const _ = require('lodash'); + module.exports = function(config) { - console.log('deploy processor'); + let ftpConfig = _.defaults({ + log: function (type, file) { + if (/UP/.test(type)) { + return console.log.call(type, file); + } + } + }, config.deploy); + + let conn = ftp.create(ftpConfig); + + vfs.src(ftpConfig.src, { + base: config._DEST_ROOT, + buffer: false + }) + .pipe(conn.newer(ftpConfig.dest)) + .pipe(conn.dest(ftpConfig.dest)); }; \ No newline at end of file diff --git a/cli/start.js b/cli/start.js index ee52155..9792575 100644 --- a/cli/start.js +++ b/cli/start.js @@ -1,6 +1,8 @@ 'use strict'; +const chokidar = require('chokidar'); const shs = require('static-http-server'); const build = require('./build'); +const utils = require('../lib/utils'); function server(config) { shs(config.server.dir, { @@ -9,7 +11,28 @@ function server(config) { }); } +function watch(config){ + function log(e, rPath) { + console.log('[%s] => %s', e.toUpperCase(), utils.relativeDir(rPath)); + } + chokidar.watch(config._SOURCE_ROOT, { + ignored: config.watchIgnore, + ignoreInitial: true + }).on('all', (event, path) => { + log(event, path); + build(config, path); + }); + + chokidar.watch(config.templateRefs, { + ignoreInitial: true + }).on('all', (event, path) => { + log(event, path); + build(config, config.templates[0]); + }); +} + module.exports = function(config) { build(config); server(config); + watch(config); }; \ No newline at end of file diff --git a/default.js b/default.js index 9f52cf5..3857aee 100644 --- a/default.js +++ b/default.js @@ -7,6 +7,7 @@ const defaults = { scripts: ['app/**/*.js'], styles: ['app/**/*.scss'], images: ['app/**/i/*.+(|jpg|png|gif)'], + templates: ['app/views/*.html'], sprites: { cssName: '__sprite.scss', imgName: 'i/__sprite.png', @@ -23,8 +24,10 @@ const defaults = { config: 'config.js', test: '.test.html' }, + templateRefs: ['app/components/*/*.html', 'app/views/*/*.html'], assets: ['static/**/*'], + watchIgnore: /\/maco\/|\/layout\/|config\.js|node_modules/, dest: 'build', @@ -32,6 +35,15 @@ const defaults = { dir: '.www', port: 80, index: false + }, + + deploy: { + host: '127.0.0.1', + user: 'ftpuser', + password: 'ftppass', + parallel: 10, + src: 'build/**', + dest: './' } }; diff --git a/package.json b/package.json index ab6c843..44f7467 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "spritesmith": "^3.1.0", "static-http-server": "0.0.4", "uglify-js": "^2.6.1", - "vinyl-fs": "^2.3.1" + "vinyl-fs": "^2.3.1", + "vinyl-ftp": "^0.4.5" } }