Skip to content

Commit

Permalink
Implement support for PLAYCANVAS_TARGET_SUBDIR config variable (#35)
Browse files Browse the repository at this point in the history
* addSubdirToTarget

* checkTargetExists

* require cwd var also

* dont check cwd var

Co-authored-by: zachppaul <[email protected]>
  • Loading branch information
zachpeterpaul and zachppaul authored Apr 26, 2022
1 parent 1f5dbdd commit 1f3c179
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,16 @@ and environment variables.
can also set `PLAYCANVAS_USE_CWD_AS_TARGET` to `1` in `.pcconfig` to use
your current working directory as your target.

For some workflows, it may be necessary to
keep the `pcconfig.json` file at the top level
in the target directory, but treat one of its subdirectories as
the root of the local file hierarchy. In such cases
`PLAYCANVAS_TARGET_SUBDIR` needs to be provided, e.g.

```
"PLAYCANVAS_TARGET_SUBDIR": "src"
```

Backslash characters should be written as `\\` (escaped).

# Files and Folders to Exclude
Expand Down
13 changes: 13 additions & 0 deletions src/utils/common-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,19 @@ const CUtils = {

waitMs: function (ms) {
return new Promise(resolve => setTimeout(resolve, ms));
},

checkTargetExists: async function(fullPath) {
const stat = await PathUtils.fsWrap('stat', fullPath);

const good = stat && stat.isDirectory;

if (!good) {
const s = `Error: could not find target directory: ${fullPath}. ` +
'Check capitalization.';

CUtils.throwFtError(s);
}
}
};

Expand Down
27 changes: 20 additions & 7 deletions src/utils/config-vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const requiredFields = [

const optionalFields = [
'PLAYCANVAS_USE_CWD_AS_TARGET',
'PLAYCANVAS_TARGET_SUBDIR',
'PLAYCANVAS_INCLUDE_REG',
'PLAYCANVAS_FORCE_REG',
'PLAYCANVAS_DRY_RUN',
Expand Down Expand Up @@ -67,6 +68,8 @@ class ConfigVars {

this.fromConfigFile(this.result.PLAYCANVAS_TARGET_DIR, TARGET_CONFIG_FILE);

await this.addSubdirToTarget();

this.fromDefaults();

requiredFields.forEach(this.checkRequired, this);
Expand All @@ -93,14 +96,9 @@ class ConfigVars {
CUtils.throwFtError('Error: do not use the playcanvas-sync directory as target');
}

const stat = await PathUtils.fsWrap('stat', s);

if (stat && stat.isDirectory) {
this.result.PLAYCANVAS_TARGET_DIR = s;
await CUtils.checkTargetExists(s);

} else {
CUtils.throwFtError(`Error: could not find target directory: ${s}. Check capitalization.`);
}
this.result.PLAYCANVAS_TARGET_DIR = s;
}

fromEnvOrMap(h) {
Expand All @@ -121,6 +119,21 @@ class ConfigVars {
}
}

async addSubdirToTarget() {
let s = this.result.PLAYCANVAS_TARGET_SUBDIR;

if (s) {
s = PathUtils.rmLastSlash(s);

this.result.PLAYCANVAS_TARGET_DIR = path.join(
this.result.PLAYCANVAS_TARGET_DIR,
s
);

await CUtils.checkTargetExists(this.result.PLAYCANVAS_TARGET_DIR);
}
}

makeReg(field) {
const v = this.result[field];

Expand Down

0 comments on commit 1f3c179

Please sign in to comment.