UNPKG

alwaysai

Version:

The alwaysAI command-line interface (CLI)

53 lines (51 loc) 1.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.findOrWriteAppPyFileComponent = void 0; const fs_1 = require("fs"); const paths_1 = require("../../paths"); const general_1 = require("../general"); const util_1 = require("../../util"); const APPLICATION_SOURCE_CODE = `import cv2 import edgeiq def main(): # Your alwaysAI app goes here! print("This is a stub of an alwaysAI application") if __name__ == "__main__": main() `; const WRITE_MESSAGE = `Write ${paths_1.APP_PY_FILE_NAME}`; const FOUND_MESSAGE = `Found ${paths_1.APP_PY_FILE_NAME}`; async function findOrWriteAppPyFileComponent(props) { const { yes } = props; if ((0, fs_1.existsSync)(paths_1.APP_PY_FILE_NAME)) { (0, util_1.Spinner)(FOUND_MESSAGE).succeed(); } else { // !exists const confirmed = yes || (await (0, general_1.confirmWriteFilePromptComponent)({ fileName: paths_1.APP_PY_FILE_NAME, description: 'Application file' })); if (confirmed) { try { (0, fs_1.writeFileSync)(paths_1.APP_PY_FILE_NAME, APPLICATION_SOURCE_CODE, { flag: 'wx' }); (0, util_1.Spinner)(WRITE_MESSAGE).succeed(); } catch (exception) { if (exception.code === 'EEXIST') { // Unlikely scenario that the file did not exist but now does (0, util_1.Spinner)(FOUND_MESSAGE).succeed(); } else { (0, util_1.Spinner)(WRITE_MESSAGE).fail(); throw exception; } } } } } exports.findOrWriteAppPyFileComponent = findOrWriteAppPyFileComponent; //# sourceMappingURL=find-or-write-app-py-file-component.js.map