Skip to content

Commit

Permalink
meta: Drafted programmatic updating to the vscode extension manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-coster committed Jul 12, 2023
1 parent 02e1eef commit 8d55209
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/vscode/scripts/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { $ } from 'zx';
// CREATE THE BUNDLE

const builder = esbuild.build({
entryPoints: ['./src/extension.ts'],
entryPoints: ['./src/extension.ts', './src/manifest.update.mts'],
bundle: true,
outfile: './dist/extension.js',
outdir: './dist/',
target: 'esnext',
keepNames: true,
sourcemap: true,
Expand Down
79 changes: 79 additions & 0 deletions packages/vscode/src/manifest.commands.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import type { ManifestCommand } from './manifest.types.mjs';
import { when } from './manifest.when.mjs';

export const commands = {
'stitch.assets.reveal': {
command: 'stitch.assets.reveal',
title: 'Stitch: Show Asset',
enablement: `${when.hasProjects} && resourceExtname =~ /\\.(yy|gml)$/`,
},
'stitch.assets.filters.enable': {
command: 'stitch.assets.filters.enable',
icon: '$(filter)',
title: 'Enable Filter',
enablement: `${when.assetTreeFocused} && ${when.hasProjects}`,
},
'stitch.assets.filters.disable': {
command: 'stitch.assets.filters.disable',
icon: '$(filter-filled)',
title: 'Disable Filter',
enablement: `${when.assetTreeFocused} && ${when.hasProjects}`,
},
'stitch.assets.filters.edit': {
command: 'stitch.assets.filters.edit',
title: 'Edit Filter',
},
'stitch.assets.filters.new': {
command: 'stitch.assets.filters.new',
icon: '$(add)',
title: 'New Filter...',
enablement: `${when.assetTreeFocused} && ${when.hasProjects}`,
},
'stitch.assets.filters.delete': {
command: 'stitch.assets.filters.delete',
icon: '$(close)',
title: 'Delete Filter',
enablement: `${when.assetTreeFocused} && ${when.hasProjects}`,
},
'stitch.assets.newFolder': {
command: 'stitch.assets.newFolder',
title: 'New Group...',
icon: '$(new-folder)',
enablement: `${when.assetTreeFocused} && ${when.hasProjects}`,
},
'stitch.assets.newScript': {
command: 'stitch.assets.newScript',
title: 'New Script...',
enablement: `${when.assetTreeFocused} && ${when.hasProjects}`,
},
'stitch.assets.newObject': {
command: 'stitch.assets.newObject',
title: 'New Object...',
enablement: `${when.assetTreeFocused} && ${when.hasProjects}`,
},
'stitch.openIde': {
command: 'stitch.openIde',
title: 'Stitch: Open in GameMaker',
shortTitle: 'Open in GameMaker',
enablement: `(resourceExtname =~ /\\.(yy|yyp|gml)$/) || (${when.assetTreeFocused} && ${when.hasProjects})`,
icon: '$(edit)',
},
'stitch.run': {
command: 'stitch.run',
title: 'Stitch: Run Project',
shortTitle: 'Run',
icon: '$(play)',
},
'stitch.clean': {
command: 'stitch.clean',
title: 'Stitch: Clean Project Cache',
shortTitle: 'Clean Cache',
icon: '$(history)',
},
'stitch.refresh': {
command: 'stitch.refresh',
title: 'Stitch: Refresh Project',
shortTitle: 'Refresh Project',
icon: '$(refresh)',
},
} satisfies Record<string, ManifestCommand>;
2 changes: 2 additions & 0 deletions packages/vscode/src/manifest.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// For programmatically updating the manifest.json file,
// making it easier to manage as the feature-set grows.
32 changes: 32 additions & 0 deletions packages/vscode/src/manifest.types.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { ViewContainerId } from './manifest.views.mjs';

export interface ManifestCommand {
command: string;
title: string;
shortTitle?: string;
icon?: `$(${string})`;
enablement?: string;
}

export interface ManifestView {
id: string;
name: string;
icon: './images/stitch-logo-mono.svg';
type: 'tree';
}

export interface ManifestViewContainer {
id: string;
title: string;
icon: './images/stitch-logo-mono.svg';
}

export interface Manifest {
contributes: {
commands: ManifestCommand[];
views: Record<ViewContainerId, ManifestView[]>;
viewsContainers: {
activitybar: ManifestViewContainer[];
};
};
}
27 changes: 27 additions & 0 deletions packages/vscode/src/manifest.update.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { pathy } from '@bscotch/pathy';
import { keysOf } from '@bscotch/utility';
import { commands } from './manifest.commands.mjs';
import type { Manifest } from './manifest.types.mjs';
import { viewsArray, viewsContainersArray } from './manifest.views.mjs';

async function main() {
const manifestPath = pathy('package.json');
await manifestPath.exists({ assert: true });

const manifest = await manifestPath.read<Manifest>();

// Update commands
manifest.contributes.commands = [];
for (const command of keysOf(commands)) {
manifest.contributes.commands.push(commands[command]);
}

// Update views
manifest.contributes.views['bscotch-stitch'] = viewsArray;
manifest.contributes.viewsContainers.activitybar = viewsContainersArray;

// Write out the updated manifest
await manifestPath.write(manifest);
}

main();
25 changes: 25 additions & 0 deletions packages/vscode/src/manifest.views.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { keysOf } from '@bscotch/utility';
import { ManifestView, ManifestViewContainer } from './manifest.types.mjs';

export type ViewId = keyof typeof views;
export const views = {
'bscotch-stitch-resources': {
id: 'bscotch-stitch-resources',
name: 'Resources',
icon: './images/stitch-logo-mono.svg',
type: 'tree',
},
} satisfies Record<string, ManifestView>;
export const viewsArray = keysOf(views).map((key) => views[key]);

export type ViewContainerId = keyof typeof viewsContainers;
export const viewsContainers = {
'bscotch-stitch': {
id: 'bscotch-stitch',
title: 'Stitch',
icon: './images/stitch-logo-mono.svg',
},
} satisfies Record<string, ManifestViewContainer>;
export const viewsContainersArray = keysOf(viewsContainers).map(
(key) => viewsContainers[key],
);
15 changes: 15 additions & 0 deletions packages/vscode/src/manifest.when.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export const when = {
assetTreeFocused: 'view == bscotch-stitch-resources',
hasProjects: 'stitch.projectCount > 0',
hasOneProject: 'stitch.projectCount == 1',
anyGameMakerFileFocused: 'resourceExtname =~ /\\.(yy|gml|yyp)$',
yypFocused: 'resourceExtname == ".yyp"',
yyFocused: 'resourceExtname == ".yyp"',
gmlFocused: 'resourceExtname == ".gml"',
viewItemIsFilter: 'viewItem =~ /^tree-filter-(enabled|disabled)/',
viewItemIsFilterGroup: 'viewItem == "tree-filter-group"',
viewItemIsFilterEnabled: 'viewItem == "tree-filter-enabled"',
viewItemIsFilterDisabled: 'viewItem == "tree-filter-disabled"',
viewItemIsProject: 'viewItem == "project"',
viewItemIsFolder: 'viewItem == "folder"',
};

0 comments on commit 8d55209

Please sign in to comment.