Flag when plugin is release mode or development

If a plugin is in development I’d like to run some debug code run but if a plugin is released I’d like to turn that code off.

Is there a flag to check that?

Use Case
Nate is creating his first plugin. He uses debug tools to help him debug. But he wants to turn those tools off when he release build.

Not a flag, as far as I’m aware of. It might be feasible, though (I can’t test that right now) to check this via fileSystemProvider.getPluginFolder(). For example, it might be as easy as checking whether this includes 'develop' (again: not tested, but it came to my mind while thinking about it)…

1 Like

Interesting. That sounds like it would work.

During development the plugin folder shows “develop” as the parent directory:

const filesystem = require("uxp").storage;
const folder = await filesystem.localFileSystem.getPluginFolder();
console.log(folder.nativePath);

Results in:

/Users/user/Library/Application Support/Adobe/Adobe XD/develop/my-plugin/

In production there is no develop folder (at least not in the default install path):

/Users/user/Library/Application Support/Adobe/Adobe XD/plugin_settings/abc123456/

This function checks for the develop folder at the parent directory:

async function isDesignMode() {
	const filesystem = require("uxp").storage;
	const pluginFolder = await filesystem.localFileSystem.getPluginFolder();
	const nativePath = pluginFolder.nativePath;
	const isMac = require("os").platform()=="darwin";
	const delimiter = isMac ? "/" : "\\";
	var folders = nativePath.split(delimiter);
	var folderName = "develop";
	var filtered = folders.filter((path)=> {return path});
	var numberOfFolders = filtered.length;
	var index = filtered.indexOf(folderName);
	var offsetOfDevelopFolder = -2;

	if (index==numberOfFolders+offsetOfDevelopFolder) {
		return true;
	}

	return false;
}

var designMode = await isDesignMode();
console.log (designMode); // true

I haven’t tested this on Windows or in production.

Hmmm. Normally I’d do this through an environment variable during my build process. This can then be injected at build time into my project so that when I build for release, the value is set one way, and when I build for debug, it’s another.

Another option is to look for the presence of a file that you only provide for production or debug, and switch based on that. Might be better than looking for the folder name itself (I’m not 100% sure if it is localized or not…, and it could be tricked anyway).

2 Likes

I’m reviving this topic since plugin developers are no longer using the develop folder

I like this idea. When UXP DT copies my plugin directory to wherever it copies it to is there any file that I can check exists?

If not, can UDT create a file in the directory and in it contain the date of the copy?

This is usually done as part of your build step. For example, we have yarn build and yarn watch inside Adobe, and one will set a flag as development and the other will set one for production. Depending on this, the build step generates the expected data.

For you, you could set something simple up (if you’re not using a webpack or the like) that drops a file into dist when you’re building a debug build vs when you’re building a release build.

For example, in package.json:

"scripts": {
    "build:debug": "touch dist/.dev && other-build-steps",
    "build:release": "rm dist/.dev && other-build-steps"
}

In your plugin code you can check to see if plugin://.dev exists or not and turn on the appropriate functionality.

I have my plugin installed through the plugin manager store and then when I work on it I Load it in with UXP DT locally. I can put a file in the plugin directory and check for its existence and that fixes part of my issue. Unfortunately, I can’t check the date on that.

Hmm… where is this from and this will be different than in my release build on the store? IIRC I remember seeing something like this in window.location (I’ll check).