packages/cli: added basic logic for diff to parse out existing plugin state

This commit is contained in:
Patrik Oldsberg
2020-05-01 17:54:39 +02:00
parent 7f03d85d91
commit 4423aa9315
+38 -2
View File
@@ -14,6 +14,42 @@
* limitations under the License.
*/
export default async () => {
console.log(`DEBUG: Diff!`);
import fs from 'fs-extra';
import { paths } from 'lib/paths';
import { version } from 'lib/version';
type PluginInfo = {
id: string;
name: string;
};
// Reads info from the existing plugin
async function readPluginInfo(): Promise<PluginInfo> {
let name: string;
try {
const pkg = require(paths.resolveTarget('package.json'));
name = pkg.name;
} catch (error) {
throw new Error(`Failed to read target package, ${error}`);
}
const pluginTsContents = await fs.readFile(
paths.resolveTarget('src/plugin.ts'),
'utf8',
);
// TODO: replace with some proper parsing logic or plugin metadata file
const pluginIdMatch = pluginTsContents.match(/id: ['"`](.+?)['"`]/);
if (!pluginIdMatch) {
throw new Error(`Failed to parse plugin.ts, no plugin ID found`);
}
const id = pluginIdMatch[1];
return { id, name };
}
export default async () => {
const pluginInfo = await readPluginInfo();
const templateVars = { version, ...pluginInfo };
console.log('DEBUG: templateVars =', templateVars);
};