Skip to content
Permalink
Browse files

fix(internal): avoid dir naming collisions by suffixing a hash to the…

… internally generated pkg dir names

The hash is created from the internally generated pkg directory path.
  • Loading branch information
jyounce committed Jul 27, 2016
1 parent 52c8cbb commit f31d0bf76b8e4dc3912a201246d89105ba860c4c
@@ -23,7 +23,9 @@ config.build.path = BUILD_PATH;
config.build.pkg = require(path.join(config.build.path, 'package.json'));
config.app.build = {};
config.app.build.opts = path.join(config.app.path, config.build.pkg.name);
config.build.cli = {};
config.build.helpers = {};
config.build.helpers.path = path.join(LIB_PATH, 'helpers');
config.build.cli = {};
config.build.cli.path = path.join(LIB_PATH, 'cli');
config.build.cli.opts = require(path.join(config.build.cli.path, 'get-cli-opts'))(config);
config.build.cli.templates = {}
@@ -31,11 +31,12 @@ module.exports = (config) ->
root: rootPath
node_modules: path.join rootPath, 'node_modules'
extra:
path: extraPath
config: path.join extraPath, 'config'
tasks: path.join extraPath, 'tasks'
temp: path.join extraPath, 'temp'
tools: path.join extraPath, 'tools'
path: extraPath
config: path.join extraPath, 'config'
helpers: path.join extraPath, 'helpers'
tasks: path.join extraPath, 'tasks'
temp: path.join extraPath, 'temp'
tools: path.join extraPath, 'tools'
generated:
path: generatedPath
testApp: path.join generatedPath, testAppName
@@ -83,6 +84,11 @@ module.exports = (config) ->
path: testPathAppSrcServer
test: path.join testPathAppSrcServer, 'test'

# add hash to generated test app
# ==============================
hashHelp = require "#{paths.abs.extra.helpers}/hash"
paths.abs.generated.testApp += hashHelp.getPathHash paths.abs.generated.testApp

# add rel
# =======
setRelPaths = (_paths, rels) -> # recursive
@@ -0,0 +1,14 @@
getHash = require 'sha1'

module.exports =
create: (str, opts={}) ->
return '' unless str
hash = getHash str
return hash if isNaN opts.length
hash.substring 0, opts.length

getPathHash: (_path, opts={}) ->
return '' unless _path
opts.length = opts.length or 3
hash = @create _path, opts
"-#{hash}"
@@ -102,6 +102,7 @@
"postcss": "5.1.0",
"postcss-import": "7.1.3",
"q": "1.4.1",
"sha1": "1.1.1",
"through2": "2.0.1"
},
"keywords": [
@@ -11,7 +11,6 @@ module.exports = (config) ->
# ========
del = require 'del'
fs = require 'fs'
fse = require 'fs-extra'
path = require 'path'

# helpers (gen = generated)
@@ -28,8 +27,12 @@ module.exports = (config) ->
catch e

getGenDir = (_path) ->
appPkg = require path.join config.app.path, 'package.json'
path.join _path, appPkg.name
hashHelp = require "#{config.build.helpers.path}/hash"
appPkg = require path.join config.app.path, 'package.json'
genPkgPath = path.join _path, appPkg.name
hash = hashHelp.getPathHash genPkgPath
genPkgPath += hash
genPkgPath

# vars
# ====
@@ -1,13 +1,19 @@
module.exports = (config) ->
path = require 'path'
log = require "#{config.req.helpers}/log"
test = require("#{config.req.helpers}/test")()
path = require 'path'
log = require "#{config.req.helpers}/log"
hashHelp = require "#{config.req.helpers}/hash"
test = require("#{config.req.helpers}/test")()

# helpers
# =======
join = (p1, p2) ->
path.join p1, p2

addHashToDir = (pkg) -> # update the reference, hash created from generated app path
hash = hashHelp.getPathHash pkg.path
for prop in ['dir', 'relPath', 'path']
pkg[prop] += hash

# init generated
# ==============
generated = {}
@@ -17,6 +23,7 @@ module.exports = (config) ->
generated.pkg.dir = config.app.name
generated.pkg.relPath = join generated.dir, generated.pkg.dir
generated.pkg.path = join generated.path, generated.pkg.dir
addHashToDir generated.pkg # avoid naming collisions, ensure unique dir name
generated.pkg.bower = join generated.pkg.path, 'bower.json'
generated.pkg.config = join generated.pkg.path, 'config.json'
generated.pkg.files = {}
@@ -0,0 +1,14 @@
getHash = require 'sha1'

module.exports =
create: (str, opts={}) ->
return '' unless str
hash = getHash str
return hash if isNaN opts.length
hash.substring 0, opts.length

getPathHash: (_path, opts={}) ->
return '' unless _path
opts.length = opts.length or 3
hash = @create _path, opts
"-#{hash}"

0 comments on commit f31d0bf

Please sign in to comment.
You can’t perform that action at this time.