diff --git a/.gitignore b/.gitignore index a2f6293..ff79be6 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ build build_cache compiled node_modules -bower_components +.idea diff --git a/src/cli/silica-build.js b/src/cli/silica-build.js index 06c450d..1a7ebf6 100644 --- a/src/cli/silica-build.js +++ b/src/cli/silica-build.js @@ -12,6 +12,7 @@ const stylus = require('stylus') program .option('-d --done [script]', 'The path to a script to run after build') .option('-s --styles [path]', 'Directory of additional style imports relative to the src directory') + .option('-j --js-only', 'do not process any views, styles, or images') .parse(process.argv) var afterScript = program.done @@ -26,8 +27,12 @@ fs.removeSync('build') fs.mkdirSync('build') fs.mkdirSync(path.join('build', 'js')) -fs.mkdirSync(path.join('build', 'css')) -fs.mkdirSync(path.join('build', 'views')) + +if (!program.jsOnly) { + fs.mkdirSync(path.join('build', 'css')) + fs.mkdirSync(path.join('build', 'views')) +} + fs.copySync('src', path.join(cachePath, 'src')) function walk (dir) { @@ -93,20 +98,22 @@ function preprocessView (readPath, writePath) { fs.writeFileSync(writePath, content) } -console.log('Preprocessing views...') +if (!program.jsOnly) { + console.log('Preprocessing views...') -// Check the index file -preprocessView(path.join(cachePath, 'src', 'index.html'), path.join('build', 'index.html')) + // Check the index file + preprocessView(path.join(cachePath, 'src', 'index.html'), path.join('build', 'index.html')) -// Check all other views -var views = walk(path.join(cachePath, 'src', 'views')) -for (var i = 0, len = views.length; i < len; i++) { - var writeTo = views[i].split(path.sep) - writeTo.shift() - writeTo.shift() - preprocessView(views[i], path.join('build', writeTo.join(path.sep))) + // Check all other views + var views = walk(path.join(cachePath, 'src', 'views')) + for (var i = 0, len = views.length; i < len; i++) { + var writeTo = views[i].split(path.sep) + writeTo.shift() + writeTo.shift() + preprocessView(views[i], path.join('build', writeTo.join(path.sep))) + } + console.log('Preprocess Finished') } -console.log('Preprocess Finished') var asyncLock = 0 @@ -196,8 +203,18 @@ closureCompiler.run(function (exitCode, stdOut, stdErr) { }) // Generate sprite styles -var spriteCSSPath = path.join(cachePath, 'src', 'styles', 'sprite.css') -var totalCSS = '' +if (!program.jsOnly) { + var spriteCSSPath = path.join(cachePath, 'src', 'styles', 'sprite.css') + var totalCSS = '' + + try { + fs.statSync(path.join('src', 'images')).isDirectory() + fs.copySync(path.join('src', 'images'), path.join('build', 'images')) + } catch (err) { + } + + var spriteSrc = path.join('src', 'images', 'sprites') +} function stylusCallback (err, css) { if (err) { @@ -208,14 +225,6 @@ function stylusCallback (err, css) { } } -try { - fs.statSync(path.join('src', 'images')).isDirectory() - fs.copySync(path.join('src', 'images'), path.join('build', 'images')) -} catch (err) { -} - -var spriteSrc = path.join('src', 'images', 'sprites') - function stylusRender () { var styles = walk(path.join(cachePath, 'src', 'styles')).filter(function (name) { return name[0] !== '.' && name !== 'base.styl' && name !== 'fonts.styl' && name.endsWith('.styl') @@ -258,40 +267,42 @@ function writeStyles () { afterScriptCaller() } -try { - fs.statSync(spriteSrc) - if (fs.readdirSync(spriteSrc).length > 0) { - nsg({ - src: [ - path.join(spriteSrc, '*.png') - ], - spritePath: path.join('build', 'images', 'sprite.png'), - stylesheetPath: spriteCSSPath, - stylesheet: 'css', - stylesheetOptions: { - prefix: 'icon-', - pixelRatio: 2, - spritePath: '../images/sprite.png' - }, - compositor: require('node-sprite-generator-jimp') - }, function (err) { - if (err) { - if (fs.readdirSync(spriteSrc).length > 0) { - console.log('Error Generating Sprites', err) +if (!program.jsOnly) { + try { + fs.statSync(spriteSrc) + if (fs.readdirSync(spriteSrc).length > 0) { + nsg({ + src: [ + path.join(spriteSrc, '*.png') + ], + spritePath: path.join('build', 'images', 'sprite.png'), + stylesheetPath: spriteCSSPath, + stylesheet: 'css', + stylesheetOptions: { + prefix: 'icon-', + pixelRatio: 2, + spritePath: '../images/sprite.png' + }, + compositor: require('node-sprite-generator-jimp') + }, function (err) { + if (err) { + if (fs.readdirSync(spriteSrc).length > 0) { + console.log('Error Generating Sprites', err) + } + } else { + console.log('Sprite Generated') } - } else { - console.log('Sprite Generated') - } + stylusRender() + totalCSS += fs.readFileSync(spriteCSSPath, 'utf8') + writeStyles() + }) + } else { stylusRender() - totalCSS += fs.readFileSync(spriteCSSPath, 'utf8') writeStyles() - }) - } else { + } + } catch (err) { stylusRender() writeStyles() } -} catch (err) { - stylusRender() - writeStyles() } diff --git a/src/cli/silica-create.js b/src/cli/silica-create.js index e65c7ee..23f1af2 100644 --- a/src/cli/silica-create.js +++ b/src/cli/silica-create.js @@ -101,7 +101,6 @@ fs.writeFileSync(path.join(projectName, 'src', 'styles', 'app.styl'), styleTempl fs.writeFileSync(path.join(projectName, 'src', 'externs.js'), '//See closure compiler docs for usage of this file') // Setup yarn - console.log('Set up yarn (Choose any values)') var yarn = spawnSync('yarn',