Skip to content

Commit

Permalink
[import] Fix importing of unreferenced assets
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Mar 6, 2018
1 parent 60e4802 commit 720c909
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/@sanity/import/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@sanity/mutator": "^0.125.8",
"@sanity/uuid": "^0.125.8",
"debug": "^3.1.0",
"file-url": "^2.0.2",
"fs-extra": "^5.0.0",
"globby": "^8.0.0",
"gunzip-maybe": "^1.4.1",
Expand All @@ -42,7 +43,6 @@
},
"devDependencies": {
"@sanity/client": "^0.125.8",
"file-url": "^2.0.2",
"get-it": "^4.0.1",
"jest": "^22.0.5",
"prettier": "^1.10.2",
Expand Down
3 changes: 2 additions & 1 deletion packages/@sanity/import/src/assetRefs.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const getFileUrl = require('file-url')
const {get, set, unset} = require('lodash')
const {extractWithPath} = require('@sanity/mutator')
const serializePath = require('./serializePath')
Expand All @@ -22,7 +23,7 @@ function absolutifyPaths(doc, absPath) {

const modifier = value =>
value
.replace(/file:\/\/\.\//i, `file://${absPath}/`)
.replace(/file:\/\/\.\//i, `${getFileUrl(absPath, {resolve: false})}/`)
.replace(/(https?):\/\/\.\//, `$1://${absPath}/`)

findAssetRefs(doc).forEach(path => {
Expand Down
5 changes: 3 additions & 2 deletions packages/@sanity/import/src/importFromFolder.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fse = require('fs-extra')
const globby = require('globby')
const getFileUrl = require('file-url')
const debug = require('debug')('sanity:import:folder')

module.exports = async function importFromFolder(fromDir, options, importers) {
Expand All @@ -20,8 +21,8 @@ module.exports = async function importFromFolder(fromDir, options, importers) {
const images = await globby('images/*', {cwd: fromDir, absolute: true})
const files = await globby('files/*', {cwd: fromDir, absolute: true})
const unreferencedAssets = []
.concat(images.map(path => `image#${path}`))
.concat(files.map(path => `file#${path}`))
.concat(images.map(path => `image#${getFileUrl(path, {resolve: false})}`))
.concat(files.map(path => `file#${getFileUrl(path, {resolve: false})}`))

debug('Queueing %d assets', unreferencedAssets.length)

Expand Down

0 comments on commit 720c909

Please sign in to comment.