Skip to content

Commit

Permalink
Fix: make paths host-agnostic (fixes #41) (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
taylortom authored Jun 17, 2024
2 parents 9bf8730 + 51dbe8b commit 082171e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/AdaptFrameworkBuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import AdaptCli from 'adapt-cli'
import { App, Hook } from 'adapt-authoring-core'
import { createWriteStream } from 'fs'
import fs from 'fs-extra'
import path from 'path'
import path from 'upath'
import semver from 'semver'
import zipper from 'zipper'

Expand Down Expand Up @@ -348,7 +348,7 @@ class AdaptFrameworkBuild {
// replace asset _ids with correct paths
const idMapEntries = Object.entries(this.assetData.idMap)
const itemString = idMapEntries.reduce((s, [_id, assetPath]) => {
const relPath = assetPath.replace(this.courseDir, 'course').replaceAll(path.sep, '/')
const relPath = assetPath.replace(this.courseDir, 'course')
return s.replace(new RegExp(_id, 'g'), relPath)
}, JSON.stringify(i))
Object.assign(i, JSON.parse(itemString))
Expand Down
9 changes: 5 additions & 4 deletions lib/AdaptFrameworkImport.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { App } from 'adapt-authoring-core'
import fs from 'fs-extra'
import { glob } from 'glob'
import octopus from 'adapt-octopus'
import path from 'path'
import path from 'upath'
import semver from 'semver'

import ComponentTransform from './migrations/component.js'
Expand Down Expand Up @@ -76,7 +76,7 @@ class AdaptFrameworkImport {
* Path that the import will be unzipped to
* @type {String}
*/
this.unzipPath = unzipPath.replace(/\\/g, '/')
this.unzipPath = unzipPath
/**
* List of asset folders to check
* @type {Array<String>}
Expand Down Expand Up @@ -315,7 +315,8 @@ class AdaptFrameworkImport {

await Promise.all(usedPluginPaths.map(async p => {
const { name, version, targetAttribute } = await fs.readJson(`${p}/bower.json`)
this.usedContentPlugins[p.split('/').pop()] = { name, path: p, version, targetAttribute }
const pluginName = path.basename(p)
this.usedContentPlugins[pluginName] = { name, path: p, version, targetAttribute }
}))

const files = await glob(`${this.coursePath}/**/*.json`, { absolute: true })
Expand Down Expand Up @@ -410,7 +411,7 @@ class AdaptFrameworkImport {
tags: data.tags
})
// store the asset _id so we can map it to the old path later
const resolved = path.relative(`${this.coursePath}/..`, filepath).replaceAll(path.sep, '/')
const resolved = path.relative(`${this.coursePath}/..`, filepath)
this.assetMap[resolved] = asset._id.toString()
} catch (e) {
this.statusReport.warn.push({ code: 'ASSET_IMPORT_FAILED', data: { filepath } })
Expand Down
2 changes: 1 addition & 1 deletion lib/AdaptFrameworkUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { App } from 'adapt-authoring-core'
import FrameworkBuild from './AdaptFrameworkBuild.js'
import FrameworkImport from './AdaptFrameworkImport.js'
import fs from 'fs'
import path from 'path'
import path from 'upath'
import semver from 'semver'

/** @ignore */ const buildCache = {}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"glob": "^10.3.10",
"lodash": "^4.17.21",
"semver": "^7.6.0",
"upath": "^2.0.1",
"zipper": "github:adapt-security/zipper"
},
"devDependencies": {
Expand Down

0 comments on commit 082171e

Please sign in to comment.