Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sst: Create a configPrefix global option for the dev command #3452

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/sst/src/cli/program.ts
Expand Up @@ -23,11 +23,15 @@ export const program = yargs(hideBin(process.argv))
type: "string",
describe: "ARN of the IAM role to use when invoking AWS",
})
.option("configPrefix", {
type: "string",
describe: "The custom prefix for the config file",
})
.option("future", {
type: "boolean",
describe: "DO NOT USE. For enabling untested, experimental features",
})
.group(["stage", "profile", "region", "role", "verbose", "help"], "Global:")
.group(["stage", "profile", "region", "role", "configPrefix", "verbose", "help"], "Global:")
.middleware(async (argv) => {
if (argv.verbose) {
process.env.SST_VERBOSE = "1";
Expand Down
15 changes: 9 additions & 6 deletions packages/sst/src/project.ts
Expand Up @@ -100,21 +100,23 @@ interface GlobalOptions {
stage?: string;
root?: string;
region?: string;
configPrefix?: string;
}

export async function initProject(globals: GlobalOptions) {
// Logger.debug("initing project");
const root = globals.root || (await findRoot());
const root = globals.root || (await findRoot(globals));
const out = path.join(root, ".sst");
await fs.mkdir(out, {
recursive: true,
});
const configPrefix = `${globals.configPrefix}.sst` || "sst";
// Logger.debug("made out dir");

let file: string | undefined;
const [metafile, sstConfig] = await (async function () {
for (const ext of CONFIG_EXTENSIONS) {
file = path.join(root, "sst" + ext);
file = path.join(root, configPrefix + ext);
if (!fsSync.existsSync(file)) continue;
// Logger.debug("found sst config");
const [metafile, config] = await load(file, true);
Expand All @@ -125,7 +127,7 @@ export async function initProject(globals: GlobalOptions) {
throw new VisibleError(
"Could not found a configuration file",
"Make sure one of the following exists",
...CONFIG_EXTENSIONS.map((x) => ` - sst${x}`)
...CONFIG_EXTENSIONS.map((x) => ` - ${configPrefix}${x}`)
);
})();

Expand Down Expand Up @@ -257,16 +259,17 @@ async function promptPersonalStage(
return await promptPersonalStage(out, true);
}

async function findRoot() {
async function findRoot(globals: GlobalOptions) {
const configPrefix = `${globals.configPrefix}.sst` || "sst";
async function find(dir: string): Promise<string> {
if (dir === "/")
throw new VisibleError(
"Could not found a configuration file",
"Make sure one of the following exists",
...CONFIG_EXTENSIONS.map((ext) => ` - sst${ext}`)
...CONFIG_EXTENSIONS.map((ext) => ` - ${configPrefix}${ext}`)
);
for (const ext of CONFIG_EXTENSIONS) {
const configPath = path.join(dir, `sst${ext}`);
const configPath = path.join(dir, `${configPrefix}${ext}`);
if (fsSync.existsSync(configPath)) {
return dir;
}
Expand Down