Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ build
build_cache
compiled
node_modules
bower_components
.idea
115 changes: 63 additions & 52 deletions src/cli/silica-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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) {
Expand All @@ -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')
Expand Down Expand Up @@ -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()
}
1 change: 0 additions & 1 deletion src/cli/silica-create.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down