motionlink-cli
Version:
Making it easy to use Notion as a Content Management system for personal websites, portfolios, blogs, business homepages, and other kinds of static websites.
107 lines • 6.28 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const cli_utils_1 = require("./cli_utils");
const logger_1 = require("./logger");
const associations_service_1 = __importDefault(require("./services/associations_service"));
const build_service_1 = require("./services/build_service");
const console_service_1 = __importStar(require("./services/console_service"));
const git_service_1 = __importDefault(require("./services/git_service"));
const media_service_1 = __importDefault(require("./services/media_service"));
const post_processing_service_1 = __importDefault(require("./services/post_processing_service"));
const prompt_sync_1 = __importDefault(require("prompt-sync"));
const file_system_service_1 = __importDefault(require("./services/file_system_service"));
const cli_files_1 = require("./constants/cli_files");
async function main() {
var _a;
const logger = (0, logger_1.getLogger)();
const mlVarsFilePath = `${process.cwd()}/.mlvars`;
const deployWorkflowFilePath = `${process.cwd()}/.github/workflows/deploy.yml`;
const deployWorkflowParentPath = `${process.cwd()}/.github/workflows`;
const gitignoreFilePath = `${process.cwd()}/.gitignore`;
if (process.argv.length < 3)
throw new Error('Too few arguments passed');
if (process.argv[2] === 'connect') {
const prompt = (0, prompt_sync_1.default)({ sigint: true });
const detectedRemoteUrl = await git_service_1.default.instance.findGitRemoteUrl(process.cwd());
console.log(`This command lets you connect your Notion workspace to your Github repository. To find the databases to connect, ` +
`Motionlink will look for a Notion page whose title contains the text '${detectedRemoteUrl}'. If this is not the repo you want ` +
`to connect, enter the git remote URL for the repo you want to connect (without .git at the end).\n`);
let remoteUrl = prompt(`Enter the url of the repo to connect. Press enter to skip and use '${detectedRemoteUrl}': `);
remoteUrl = remoteUrl.length === 0 ? detectedRemoteUrl : remoteUrl;
const useNetlify = prompt('Would you like to configure this project to deploy to Netlify? [y/n]: ').toLowerCase() === 'y';
const host = useNetlify ? console_service_1.Host.netlify : console_service_1.Host.none;
let buildCommand = 'npm build';
let publicFolder = './public';
if (useNetlify) {
let input = prompt(`What is the command used to build your project? [${buildCommand}]: `);
buildCommand = input.length === 0 ? buildCommand : input;
input = prompt(`What is your site public folder? [${publicFolder}]: `);
publicFolder = input.length === 0 ? publicFolder : input;
}
console.log('Follow the link below to authorize the connect request:');
const connectResult = await console_service_1.default.instance.connect(remoteUrl, host, process.env.ML_CONSOLE);
console.log(`Connect request complete. ${useNetlify
? 'Site available at below URL. Note that initially the Netlify site will be empty. It will be populated once you push your code.'
: ''}`);
if (useNetlify) {
logger.logWithColor((_a = connectResult.secureUrl) !== null && _a !== void 0 ? _a : '');
}
console.log('Saving Motionlink vars...');
file_system_service_1.default.instance.writeStringToFile(connectResult.vars, mlVarsFilePath);
let gitignore = '';
try {
gitignore = file_system_service_1.default.instance.readFileAsString(gitignoreFilePath);
}
catch (e) {
console.log('... No .gitignore file. Will create one.');
}
gitignore = `${gitignore}\n\n# Motionlink Vars\n.mlvars\n`;
file_system_service_1.default.instance.writeStringToFile(gitignore, gitignoreFilePath);
if (useNetlify) {
console.log('Saving github workflows...');
if (!file_system_service_1.default.instance.doesFolderExist(deployWorkflowParentPath)) {
file_system_service_1.default.instance.createFolder(deployWorkflowParentPath);
}
file_system_service_1.default.instance.writeStringToFile((0, cli_files_1.getNetlifyDeployWorkflow)(buildCommand, publicFolder), deployWorkflowFilePath);
}
console.log('All Done!');
process.exit(0);
}
else {
let motionlinkVars = [...process.argv].splice(2).join(' ');
if (process.argv[2] === 'build') {
motionlinkVars = file_system_service_1.default.instance.readFileAsString(mlVarsFilePath).trim();
}
const associations = (0, cli_utils_1.compileAssociations)(motionlinkVars);
const dbAssociations = await associations_service_1.default.instance.toNotionDatabaseAssociations(associations);
const configFile = `${process.cwd()}/motionlink.config.js`;
const templateRules = require(configFile);
await (0, build_service_1.newBuildService)().build(templateRules, dbAssociations);
await media_service_1.default.instance.commit();
post_processing_service_1.default.instance.flush();
}
}
exports.default = main;
//# sourceMappingURL=main_function.js.map