Skip to content
This repository was archived by the owner on Oct 28, 2023. It is now read-only.
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
18 changes: 10 additions & 8 deletions src/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,15 @@ export default class CreateCommand implements CliCommand {
return console.log(logSymbols.error, 'Directory not empty');
}

await fs.mkdir(base + 'plugin/icons', { recursive: true });
await fs.ensureDir(base + 'plugin/pi');
const pluginDir = join(base, `${choices.uuid}.sdPlugin`);

await fs.mkdir(`${pluginDir}/icons`, { recursive: true });
await fs.ensureDir(`${pluginDir}/pi`);
await fs.ensureDir(base + 'src/actions');

await fs.copy(
join(__dirname, '../../boilerplate/plugin/pi'),
join(base, 'plugin/pi'),
pluginDir,
{
recursive: true
}
Expand All @@ -121,12 +123,12 @@ export default class CreateCommand implements CliCommand {
join(__dirname, '../../boilerplate/plugin/pi/index.html')
);
await fs.writeFile(
base + '/plugin/pi/index.html',
`${pluginDir}/pi/index.html`,
Mustache.render(templatePi.toString(), choices)
);

await fs.writeFile(
base + '/plugin/manifest.json',
`${pluginDir}/manifest.json`,
JSON.stringify(
createManifest({
name: choices.name,
Expand All @@ -143,7 +145,7 @@ export default class CreateCommand implements CliCommand {

await fs.copy(
join(__dirname, '../../boilerplate/plugin/icons'),
join(base, 'plugin/icons'),
`${pluginDir}/icons`,
{
recursive: true
}
Expand Down Expand Up @@ -194,15 +196,15 @@ export default class CreateCommand implements CliCommand {
spinner.succeed('Boilerplate generated');

spinner.start('Installing node modules...');
await execAsync(`${pm} i`, { cwd: base });
await execAsync(`${pm} install`, { cwd: base });

spinner.succeed('Node modules installed');
spinner.start('Building the project...');
await execAsync(`${pm} run build`, { cwd: base });
spinner.stop();

await new LinkCommand().execute({
cwd: join(base, 'plugin')
cwd: join(process.cwd(), pluginDir),
});

console.log('\n', logSymbols.success, 'Project created', '\n');
Expand Down
6 changes: 0 additions & 6 deletions src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ export default class DevCommand implements CliCommand {
let cwd = process.cwd();
let manifest = await parseManifest(cwd);

if (!manifest) {
// allows command's execution in the main project directory
cwd = join(cwd, 'plugin');
manifest = await parseManifest(cwd);
}

if (manifest) {
await this.downloadDebugPlugin();

Expand Down
15 changes: 5 additions & 10 deletions src/commands/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { CliCommand } from '../interfaces.js';
import { CommandLineOptions, OptionDefinition } from 'command-line-args';
import { checkApplicationInPath, getUUID, parseManifest, reloadStreamDeckApplication } from '../util.js';
import { join } from 'node:path';
import symlinkDir from 'symlink-dir';
import { lstatSync, rmdirSync } from 'node:fs';
import { lstatSync, symlinkSync, unlinkSync } from 'node:fs';
import { PluginPath } from '../constant.js';
import logSymbols from 'log-symbols';

Expand All @@ -25,12 +24,6 @@ export default class LinkCommand implements CliCommand {

let manifest = await parseManifest(cwd);

if (!manifest) {
// allows command's execution in the main project directory
cwd = join(cwd, 'plugin');
manifest = await parseManifest(cwd);
}

if (manifest) {
const uuid = getUUID(manifest);
const pluginDirectory = join(PluginPath, uuid + '.sdPlugin');
Expand All @@ -49,7 +42,7 @@ export default class LinkCommand implements CliCommand {
}

if (stats.isSymbolicLink()) {
rmdirSync(pluginDirectory);
unlinkSync(pluginDirectory);
console.log(logSymbols.success, 'Plugin unlinked');
await reloadStreamDeckApplication(uuid);
} else {
Expand All @@ -62,10 +55,12 @@ export default class LinkCommand implements CliCommand {
return console.log(logSymbols.error, 'Plugin already linked');
}

await symlinkDir(cwd, pluginDirectory);
symlinkSync(cwd, pluginDirectory, 'dir');
console.log(logSymbols.success, 'Plugin linked');
await reloadStreamDeckApplication(uuid);
}
} else {
console.log(logSymbols.error, 'No manifest file found in current directory.');
}

}
Expand Down
2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const parseManifest = async (
): Promise<PluginManifest | undefined> => {
try {
return await fs.readJSON(
join(cwd, nested ? 'plugin' : '', 'manifest.json')
join(cwd, 'manifest.json')
);
} catch (e) {
if (!nested) {
Expand Down