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
11 changes: 10 additions & 1 deletion packages/scene-graph-mediator/client/lib/modules/parseArgs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion packages/scene-graph-mediator/client/src/modules/parseArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ import AssetExporterPlugin from '../interface/AssetExporterPlugin';
export default function parseArgs(): Args {
const packageJson = require('../../package.json');

const isRelativePath = (value: string) => {
return value.startsWith(`.${path.sep}`) || value.startsWith(`..${path.sep}`);
};

const spaceSeparatedPaths = (value: string): string[] => {
const parts = [];
const frags = value.split(' ');
for (let i = 0; i < frags.length; i++) {
const frag = frags[i];
if (fs.existsSync(frag)) {
if ((!path.isAbsolute(frag) && !isRelativePath(frag)) || fs.existsSync(frag)) {
parts.push(frag);
} else {
const nextFrag = frags[i + 1];
Expand Down Expand Up @@ -181,5 +185,12 @@ export default function parseArgs(): Args {

args.assetRoot = args.assetRoot.replace(/\/$/, '');

for (let i = 0; i < args.plugins.length; i++) {
const plugin = args.plugins[i];
if (isRelativePath(plugin)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

path.isAbsolute is more handy.

> path.isAbsolute('/aaaa/bbbb/cccc')
true
> path.isAbsolute('/aaaa/../cccc')
true
> path.isAbsolute('./aaaa/cccc')
false

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, Is it make mistakes?

> path.isAbsolute('ModuleName')
false

It isn't relative path.
!absolute !== relative.

Copy link
Copy Markdown
Contributor

@dolow dolow Jun 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there is another path variant.

  • absolute
  • relative
  • resolved

In this case, this fix may be OK.
I'd like to forget about $NODE_PATH because it can be defined by user or user's environment, will you be supporting for this variable ?

Copy link
Copy Markdown
Contributor Author

@takeshi-sakurai takeshi-sakurai Jun 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It basically worked correctly, as far as I tried.
The code below is worked correctly.

const Plugin = require(plugins[i] as string).default;

But, The following points need to be corrected.
Plugins have been removed by:

const spaceSeparatedPaths = (value: string): string[] => {
const parts = [];
const frags = value.split(' ');
for (let i = 0; i < frags.length; i++) {
const frag = frags[i];
if (fs.existsSync(frag)) {
parts.push(frag);
} else {
const nextFrag = frags[i + 1];
if (!nextFrag) {
break;
}
frags[i + 1] = `${frag} ${nextFrag}`;
}
}
return parts;
};

Copy link
Copy Markdown
Contributor Author

@takeshi-sakurai takeshi-sakurai Jun 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added support for loading plugins by specifying "ModuleName".
dd1b435 94bfbba

args.plugins[i] = path.resolve(process.cwd(), configFilePath, plugin);
}
}

return args;
}