Skip to content

Commit

Permalink
Merge pull request #12 from mikejgray/FIX_VariousBugfixes
Browse files Browse the repository at this point in the history
fix: various bugfixes
  • Loading branch information
mikejgray authored Aug 25, 2023
2 parents a388a20 + 9cb2320 commit 66c9022
Show file tree
Hide file tree
Showing 7 changed files with 1,131 additions and 13 deletions.
4 changes: 4 additions & 0 deletions .projen/deps.json

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

1 change: 1 addition & 0 deletions .projenrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const project = new cdk.JsiiProject({
license: 'Apache-2.0',

deps: ['projen'],
bundledDeps: ['yaml'],
devDeps: ['jsii-rosetta@~5.0.7'],
description: 'A projen project for creating OVOS skills, or retrofitting Mycroft skills to OVOS',
});
Expand Down
6 changes: 5 additions & 1 deletion package.json

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

45 changes: 34 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, writeFile
import { join } from 'path';
import { ProjenrcJson, SampleDir, SampleFile, TextFile } from 'projen';
import { GitHubProject, GitHubProjectOptions } from 'projen/lib/github';
import { parse } from 'yaml';
import { readmeMd } from './files/README';
import { setupPy } from './files/setup.py';
import { LicenseTestsWorkflow, ProposeReleaseWorkflow, PublishAlphaWorkflow, PublishReleaseWorkflow, SkillTestsWorkflow, UpdateSkillJsonWorkflow } from './GithubWorkflows';
Expand Down Expand Up @@ -197,16 +198,31 @@ ${line}`;
new SampleFile(this, 'skill.json', {
contents: '{}',
});
let requirements = 'ovos-utils\novos-bus-client\novos-workshop';
if (retrofit) {
if (existsSync('requirements.txt')) {
const existingRequirements = readFileSync('requirements.txt').toString();
requirements = `${existingRequirements}\n${requirements}`;
} else {
new TextFile(this, 'requirements.txt', {
lines: requirements.split('\n'),
});
let requirements = 'ovos-utils\novos-bus-client\novos-workshop\n# Your requirements here\n';
let manifestReqs = '';
if (existsSync('manifest.yml')) {
// Load and parse YAML file
console.debug('Found manifest.yml, trying to extract Python dependencies');
const manifest = readFileSync('manifest.yml').toString();
const manifestObject = parse(manifest);
if (manifestObject.dependencies.python) {
manifestReqs = manifestObject.dependencies.python.join('\n') + '\n';
}
}
if (existsSync('requirements.txt')) {
const existingRequirements = readFileSync('requirements.txt').toString();
requirements = `${existingRequirements}\n${manifestReqs ?? ''}${requirements}`;
} else {
new TextFile(this, 'requirements.txt', {
lines: [...requirements.split('\n'), ...manifestReqs.split('\n')],
});
}
if (!existsSync('version.py') && retrofit) {
new TextFile(this, 'version.py', {
lines: 'VERSION_MAJOR = 0\nVERSION_MINOR = 0\nVERSION_BUILD = 1\nVERSION_ALPHA = 0'.split('\n'),
});
};
if (retrofit) {
if (existsSync('__init__.py') && !existsSync('setup.py')) {
OVOSSkillProject.modernizeSkillCode('__init__.py');
} else if (!existsSync('__init__.py') && !existsSync('setup.py')) {
Expand Down Expand Up @@ -405,6 +421,14 @@ ${line}`;
*/
restructureLocaleFolders(sourceFolder: string) {
['vocab', 'dialog', 'regex', 'intents'].forEach((dir) => {
const dirPath = join(sourceFolder, dir);

// Check if the directory exists before proceeding
if (!existsSync(dirPath)) {
console.warn(`${dir} folder not found in original skill; skipping.`);
return; // Continue to the next iteration of the loop
}

const locale = join(sourceFolder, 'locale');
try {
mkdirSync(locale, { recursive: true });
Expand All @@ -424,9 +448,8 @@ ${line}`;
renameSync(join(sourceFolder, dir, lang), join(locale, lang, dir));
}
});

} catch (err) {
console.debug(err);
console.error(err);
}
});
}
Expand Down
35 changes: 35 additions & 0 deletions test/OVOSSkillProject.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { rmSync, writeFileSync } from 'fs';
import { Testing } from 'projen';
import { OVOSSkillProject } from '../src';

Expand All @@ -10,4 +11,38 @@ test('snapshot', () => {

const synth = Testing.synth(project);
expect(synth).toMatchSnapshot();
});

test('snapshot retrofit', () => {
const project = new OVOSSkillProject({
name: 'test',
skillClass: 'TestSkill',
pypiName: 'test-skill',
retrofit: true,
});

const synth = Testing.synth(project);
expect(synth).toMatchSnapshot();

rmSync('TODO.md');
});

test('snapshot retrofit with manifest.yml', () => {
writeFileSync('manifest.yml', `dependencies:
python:
- akinator
- rapidfuzz
`);
const project = new OVOSSkillProject({
name: 'test',
skillClass: 'TestSkill',
pypiName: 'test-skill',
retrofit: true,
});

const synth = Testing.synth(project);
expect(synth).toMatchSnapshot();

rmSync('manifest.yml');
rmSync('TODO.md');
});
Loading

0 comments on commit 66c9022

Please sign in to comment.