176 lines
6.9 KiB
JavaScript
176 lines
6.9 KiB
JavaScript
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.jiboPlugins = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
let path = require('path');
|
|
let fs = require('fs');
|
|
function findRoot(_start) {
|
|
let start = _start;
|
|
start = start || module.parent.filename;
|
|
if (typeof start === 'string') {
|
|
if (start[start.length - 1] !== path.sep) {
|
|
start += path.sep;
|
|
}
|
|
start = start.split(path.sep);
|
|
}
|
|
if (!start.length) {
|
|
throw new Error('package.json not found in path' + _start);
|
|
}
|
|
start.pop();
|
|
let dir = start.join(path.sep);
|
|
try {
|
|
fs.statSync(path.join(dir, 'package.json'));
|
|
return dir;
|
|
}
|
|
catch (e) { }
|
|
return findRoot(start);
|
|
}
|
|
exports.default = findRoot;
|
|
|
|
},{"fs":undefined,"path":undefined}],2:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const path = require("path");
|
|
const Module = require("module");
|
|
const FindRoot_1 = require("./FindRoot");
|
|
class PathUtils {
|
|
static findRoot(start) {
|
|
start = start || process.cwd();
|
|
if (!(start in this.findRootCache)) {
|
|
this.findRootCache[start] = PathUtils._findRoot(start);
|
|
}
|
|
return this.findRootCache[start];
|
|
}
|
|
static _findRoot(start) {
|
|
let assetPack = PathUtils.getAssetPack(start);
|
|
if (assetPack) {
|
|
return PathUtils.resolveAssetPack(assetPack);
|
|
}
|
|
else {
|
|
return FindRoot_1.default(start);
|
|
}
|
|
}
|
|
static getProjectName(dir) {
|
|
return require(path.join(dir, 'package.json')).name;
|
|
}
|
|
static isURL(uri) {
|
|
return uri.startsWith('https://') || uri.startsWith('http://') || uri.startsWith('file://');
|
|
}
|
|
static isImage(uri) {
|
|
return uri && /^\.(jpg|png|gif|jpeg)$/i.test(path.extname(uri));
|
|
}
|
|
static setDefaultPath(parentDir, fileName) {
|
|
let split = fileName.split(PathUtils.ASSET_TOKEN);
|
|
if (split.length === 2) {
|
|
return split[0] + PathUtils.ASSET_TOKEN + path.join(parentDir, split[1]);
|
|
}
|
|
else {
|
|
return path.join(parentDir, fileName);
|
|
}
|
|
}
|
|
static getAssetPack(fileName) {
|
|
const split = fileName.split(PathUtils.ASSET_TOKEN);
|
|
return (split.length === 1) ? "" : split[0];
|
|
}
|
|
static getAssetUri(fileName, assetPack = '', resourceRoot) {
|
|
let key = fileName + '###' + assetPack + '###' + resourceRoot;
|
|
if (!(key in this.getAssetUriCache)) {
|
|
this.getAssetUriCache[key] = PathUtils._getAssetUri(fileName, assetPack, resourceRoot);
|
|
}
|
|
return this.getAssetUriCache[key];
|
|
}
|
|
static _getAssetUri(fileName, assetPack = '', resourceRoot) {
|
|
let split = fileName.split(PathUtils.ASSET_TOKEN);
|
|
if (split.length === 2) {
|
|
assetPack = split[0];
|
|
fileName = split[1];
|
|
}
|
|
const isSpecificAssetPack = (assetPack && (assetPack !== 'project'));
|
|
if (path.isAbsolute(fileName)) {
|
|
return fileName;
|
|
}
|
|
else if (isSpecificAssetPack) {
|
|
resourceRoot = PathUtils.resolveAssetPack(assetPack);
|
|
}
|
|
else if (!resourceRoot) {
|
|
if (assetPack) {
|
|
resourceRoot = PathUtils.resolveAssetPack(assetPack);
|
|
}
|
|
else {
|
|
resourceRoot = PathUtils.findRoot();
|
|
}
|
|
}
|
|
return path.join(resourceRoot, fileName);
|
|
}
|
|
static getAudioUri(fileName, currentAssetPack = '', resourceRoot) {
|
|
let audioPath = PathUtils.setDefaultPath('audio', fileName);
|
|
return PathUtils.getAssetUri(audioPath, currentAssetPack, resourceRoot);
|
|
}
|
|
static getTimelineUri(fileName, currentAssetPack = '', resourceRoot) {
|
|
let timelinePath = PathUtils.setDefaultPath('timelines', fileName);
|
|
return PathUtils.getAssetUri(timelinePath, currentAssetPack, resourceRoot);
|
|
}
|
|
static getAnimationUri(fileName, currentAssetPack = '', resourceRoot) {
|
|
let animPath = PathUtils.setDefaultPath('animations', fileName);
|
|
return PathUtils.getAssetUri(animPath, currentAssetPack, resourceRoot);
|
|
}
|
|
static resolve(moduleId, fromPath) {
|
|
let fromDir = path.resolve(fromPath || PathUtils.getPackagePath());
|
|
let fromFile = path.join(fromDir, 'noop.js');
|
|
try {
|
|
let filepath = Module._resolveFilename(moduleId, {
|
|
id: fromFile,
|
|
filename: fromFile,
|
|
paths: Module._nodeModulePaths(fromDir)
|
|
});
|
|
return filepath;
|
|
}
|
|
catch (err) {
|
|
console.error("Surprise exception in PathUtils.resolve()!", err);
|
|
return null;
|
|
}
|
|
}
|
|
static resolveAssetPack(assetPack) {
|
|
if (assetPack && assetPack.endsWith(PathUtils.ASSET_TOKEN)) {
|
|
assetPack = assetPack.split(PathUtils.ASSET_TOKEN)[0];
|
|
}
|
|
if (assetPack === 'project') {
|
|
return PathUtils.getPackagePath();
|
|
}
|
|
if (assetPack === 'core' || assetPack === 'jibo') {
|
|
assetPack = 'jibo';
|
|
let packagePath = PathUtils.resolve(assetPack + "/package.json");
|
|
if (!packagePath) {
|
|
return PathUtils.getPackagePath();
|
|
}
|
|
return path.dirname(packagePath);
|
|
}
|
|
const packagePath = PathUtils.resolve(assetPack + "/package.json");
|
|
return path.dirname(packagePath);
|
|
}
|
|
static getPackagePath() {
|
|
let uri = process.cwd();
|
|
if (global.atom) {
|
|
uri = atom.project.getPaths()[0];
|
|
}
|
|
let root = FindRoot_1.default(uri);
|
|
return root;
|
|
}
|
|
}
|
|
PathUtils.ASSET_TOKEN = '://';
|
|
PathUtils.findRootCache = {};
|
|
PathUtils.getAssetUriCache = {};
|
|
exports.default = PathUtils;
|
|
|
|
},{"./FindRoot":1,"module":undefined,"path":undefined}],3:[function(require,module,exports){
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
var FindRoot_1 = require("./FindRoot");
|
|
exports.findRoot = FindRoot_1.default;
|
|
var PathUtils_1 = require("./PathUtils");
|
|
exports.PathUtils = PathUtils_1.default;
|
|
|
|
},{"./FindRoot":1,"./PathUtils":2}]},{},[3])(3)
|
|
});
|
|
|
|
//# sourceMappingURL=jibo-plugins.js.map
|